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!