How to add tracking script for Crazy Egg

Hi guys,

I have a tracking code that I need to place ‘before the closing head tag in my header file’ according to Crazy Egg.
I understand that I need to place this in the Custom > Edit global javascript section of the customiser, but I am not sure exactly what the code should say. Can someone please help clarify this for me?

This is the code provided by Crazy Egg:

But shouldn’t there be some extra code to place it before the closing head tag?

Furthermore, I would like to know how to place a tracking code on one page only, before the closing head tag?

Thanks for your help in advance! :slight_smile:

Hi there,

Please install and activate the child theme on your site.

You can get the installable file here:

https://theme.co/apex/child-themes

Once you have installed and activated the child theme, please login through FTP and go to wp-content/themes/x-child then edit the functions.php then add this code to the file:

add_action('wp_head', 'add_crazy_egg_code');

function add_crazy_egg_code(){
?>
    PASTE HEADER CODE HERE
<?php
}

Kindly remove the text PASTE HEADER CODE HERE in the code and replace it with the Crazy Egg code.

Hope this helps.

Thank you, I have placed the code so hopefully it works :slight_smile:

I have another tracking code that I need to install into a thank-you page as well, is it the same process? I imagine the code would differ slightly though to target only that page, am I right?

Thanks for your help with this!

Hi,

You can add it to that code, just add a conditional statement.

add_action('wp_head', 'add_crazy_egg_code');

function add_crazy_egg_code(){
?>
    PASTE HEADER CODE HERE

<?php
   if(is_page(1))  { ?>

   PASTE Thank you page Tracking CODE Here    

<?php
   } 
}

Change 1 with the page id of your thank you page.

For your guide on how to get page id, kindly refer to the link below

Thanks

Great, thank you for your help! :smiley:

You’re welcome! :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.