How to Add Crazy Egg Code to the Thesis Theme

I needed to add some Crazy Egg code to specific sections on the Sugarrae site today (which runs on the Thesis theme) to see the impact of the new design I launched last week. But after a few searches, I couldn’t find any “copy and paste” code to add it, so I had to write the functions myself.

I figured I’d share in case anyone else who ISN’T capable of writing their own functions ever needs to add it.

More in-depth information on why I added Crazy Egg to the site and what I do with the data it collects soon. :)

If you’re using Thesis and want to add the Crazy Egg code to one specific page or post on your site, you can use the following code(s) within the custom_functions.php file to make it happen:

If your site uses a static front page and you want to add Crazy Egg to that static front page…


function crazyegg_home() {
if (is_front_page()) { ?>
THE CUSTOM JAVASCRIPT TRACKING CODE CRAZYEGG GAVE YOU HERE
<?php
}
}
add_action('thesis_hook_after_html' , 'crazyegg_home');

If your site uses a static front page (or doesn’t use one) and you want to add Crazy Egg to the main posts page…


function crazyegg_blog() {
if (is_home()) { ?>
THE CUSTOM JAVASCRIPT TRACKING CODE CRAZYEGG GAVE YOU HERE
<?php
}
}
add_action('thesis_hook_after_html' , 'crazyegg_blog');

If you want to add Crazy Egg code to a specific page…


function crazyegg_page() {
if (is_page('PAGEIDHERE')) { ?>
THE CUSTOM JAVASCRIPT TRACKING CODE CRAZYEGG GAVE YOU HERE
<?php
}
}
add_action('thesis_hook_after_html' , 'crazyegg_page');

If you want to add Crazy Egg code to a specific post…


function crazyegg_post() {
if (is_single('POSTIDHERE')) { ?>
THE CUSTOM JAVASCRIPT TRACKING CODE CRAZYEGG GAVE YOU HERE
<?php
}
}
add_action('thesis_hook_after_html' , 'crazyegg_post');

If you want to add Crazy Egg code to a specific category page…


function crazyegg_category() {
if (is_category('CATEGORYIDHERE')) { ?>
THE CUSTOM JAVASCRIPT TRACKING CODE CRAZYEGG GAVE YOU HERE
<?php
}
}
add_action('thesis_hook_after_html' , 'crazyegg_category');

If you want to add Crazy Egg code to a specific tag page…


function crazyegg_tag() {
if (is_tag('TAGIDHERE')) { ?>
THE CUSTOM JAVASCRIPT TRACKING CODE CRAZYEGG GAVE YOU HERE
<?php
}
}
add_action('thesis_hook_after_html' , 'crazyegg_tag');

Please Note

When it comes to PAGEIDHERE, POSTIDHERE, CATEGORYIDHERE and TAGIDHERE that you can use the slug for each instead of the numerical ID if you’d prefer. So, as an example if my post was located at the following URL: sugarrae.com/admin/post-name-here/ then I could swap out the ‘POSTID’ with ‘post-name-here’ – however, I just prefer to use the numerical ID values of the posts, pages, categories and tags (if I used tags).

Cheers!

About Rae Hoffman

Rae Hoffman aka "Sugarrae" is an affiliate marketing veteran and the CEO of PushFire, a search marketing agency specializing in SEO audits and link building strategies. She is also the author of the often controversial Sugarrae blog. You can connect with Rae via Twitter, Google+ and Facebook.

Sugarrae runs on the Genesis Framework

Genesis Framework

If you’re someone who doesn’t understand a lot of PHP, Genesis will give a ton of functionality that you wouldn’t be able to obtain otherwise with a simple control panel instead of having to alter code. For the advanced, Genesis has incredible customization possibilities via Genesis hooks.

The theme is not only highly customizable, but it has allowed me to run Sugarrae more professionally, with a much more targeted focus on monetization than it ever has been able to achieve before.

You can find out more about Genesis below:

Comments

  1. Hi
    I’m not very good at php, but I think you’ve left out a <?php in your code
    I think it should be:
    THE CUSTOM JAVASCRIPT TRACKING CODE CRAZYEGG GAVE YOU HERE
    <?php

    Ta
    Seamus

    • Weird… the <?php was in my post, but you’re right, it wasn’t showing in the output even though it was all wrapped in code tags. Not sure why it left all the rest alone but killed off that one piece. However, I’ve changed the < to the ascii version and it suddenly starting showing. Thanks for noticing! I’d tested them all and knew they worked and missed that they’d been stripped. In short, fixed! :D

  2. Thanks heaps for this post – I didn’t know CrazyEgg existed.
    Have inserted your code and waiting impatiently to see my website’s snapshot.

  3. If I want to add Facebook’s ad conversion pixel (conversion code) to a specific page/post in THESIS in the section, is it going to be possible to do it as you explained above?

    (THESIS does have an “Embed Your Own Javascript” box in each page/post, but I don’t know if it sticks the code in between the head tags.)

    • I don’t see why not. Should work the same if you just substitute the Crazy Egg code for the FB code. You only need to do it via the above though if you only want it to appear some specific posts or pages and not all of them though. In Thesis 1.8.5, if you want to put a script in the head section, you can just go to Site Options > Additional Scripts and put the code in that box – but it will appear on ALL pages of the site if you do. I’m not sure where the “embed your own JavaScript” on the specific post and page screens outputs in Thesis though – but should be easier enough to test by adding the code, saving and then viewing the source of the post to see where it outputs. Hope this helps!

Speak Your Mind

*