24 Aug 2006

Crazyegg.com tracking code

So I’m currently testing this new toy, Crazy Egg a web statistic tool that also comes in 3 forms of result – overlay, list and heatmap. The reason I try it because I want an easy way to see which part of my blog that visitors are clicking. After 1 day of testing, the result turns out to be excellent.

In order to get started, you need to register an account at crazyegg.com. For starters, try out the free plan but it’s limited to 5,000 visits per month.

Scrambling Crazy Egg tracking code

When you’re done setting up your account and the test page, you need to place a code somewhere before the closing BODY tag:

<script>
document.write('<script'+' src="http://crazyegg.com/pages'+'/scripts/your_id_number.js?'+(new Date()).getTime()+'" type="text/javascript"></scr'+'ipt>');
</script>

But instead of pasting and embedding the given code, I’ve made a slightly little modification so that the W3C Markup Validator will stop whining:

  • <script type="text/javascript">
    <!--//--><![CDATA[//><!--
    document.write('<script src="http://crazyegg.com/pages/scripts/your_id_number.js?'+(new Date()).getTime()+'" type="text/javascript"><\/script>');
    //--><!]]>
    </script>
    
  • <script type="text/javascript">
    // <![CDATA[
    document.write('<script src="http://crazyegg.com/pages/scripts/your_id_number.js?'+(new Date()).getTime()+'" type="text/javascript"><\/script>');
    // ]]>
    </script>
    
  • Not sure about this.

    <script type="text/javascript">
    <!--
    document.write('<script src="http://crazyegg.com/pages/scripts/your_id_number.js?'+(new Date()).getTime()+'" type="text/javascript"><\/script>');
    //-->
    </script>
    

Take note: Change your_id_number with your own. For example mine is 358. Please refer to your original tracking code given during page setup.

I’m still figuring out if there’s any consequences if I use mine instead of the default given snippet.

On WordPress

If you’re using WordPress and only tracking your blog front page, consider adding this extra code:

<?php if ( is_home() && !is_paged() ) { ?>
.... Crazy egg tracking code
<?php } ?>

Or if you don’t want to track your own visits or clicks (assuming that you’re logged in to your WordPress), use:

<?php global $user_ID; if ( !$user_ID ) { ?>
.... Crazy egg tracking code
<?php } ?>

7 Comments

  1. Safirul, Thanks for writing this tutorial no modifying Crazy Egg to be W3C compliant, we will be spitting out a W3C compliant code in the near future, and I am sure we will use some of your suggestions / improvements. Also we will be creating an easy to use wordpress plugin at some point, but, again your information on this is much appreciated and noted :-)

  2. [...] Crazyegg.com tracking code crazyegg kod validan (tags: valid w3c xhtml code) [...]

  3. Crazy Egg Week 1 Updates…

    We have been live for over a week now and we have some updates, most of these updates come from requests from initial users of Crazy Egg. These things were on our minds before we launched, but we wanted to hear feedback and decide which things should …

  4. i try to see the demo in firefox but it takes so long to load up. but anyway i use google analytics to see where most my visitors clicks on my site.

  5. How i put into a php file (ex. index.php)?

  6. Zeo

    Pablo, http://zeo.unic.net.my/notes/where-is-my-egg/

  7. [...] CrazyEgg.com – different display of stats including a heatmap view. Free to 5,000 views and 4 pages [...]