Adding GTM, FB pixel and affiliate tracking

Guys -
How specifically do i add:

google tag manager

commission junction tracking code

facebook tracking pixel

I’ve done this before, but your functions.php is not normal and special code seems to have to be added.
One forum said just add the code and the function will figure it out. IT WILL NOT. It will blow up the site and serve a 500 error.

To be clear on GTM, you have two add TWO pieces of code. One in head and one in body. ie

Paste this code as high in the of the page as possible:

Additionally, paste this code immediately after the opening tag:

Every single site needs to add tracking code, so i don’t understand why this is so hard. The plug in is only for GA, not GTM which is the standard now.

Appreciate help thanks
Alex

Hi There,

Thank you for writing in, you can add this function to your child theme’s functions.php file. With this your code will be output inside the <head> of the site.


add_action('wp_head','my_tracking');
function my_tracking () { ?>

<!-- Your code here, this code will be output inside the <head> of the page -->

<?php }

Replace the line that says “Your code here” with your actual code.

And this one will output the code inside the <body> tag.

add_action( 'x_before_site_begin', 'x_print_fb_sdk', 1 );
function x_print_fb_sdk(){ ?>

<!-- Your code here, this code will be output inside the <body> of the page -->

<?php }

Cheers!

Hi I figured out how to make google and I think FB to work in the mean time.
However I was looking for code for what i think are javascript based tracking:

I tried the code, which doesn’t blow up my site with a 500 error, but i’m pretty sure the pushcrew doesn’t work, since I don’t see popup in site.
Commission junction shows in tools.pingdom.com taking up a lot of speed, but i guess that means it is calling.

Can you check what’s wrong please?

Summary
// Add pushcrew
// =============================================================================


add_action( 'x_after_site_begin', 'x_print_script' );
function x_print_script(){?>
  <script type="text/javascript">
  /* Your custom script will go here /*

   (function(p,u,s,h){
        p._pcq=p._pcq||[];
        p._pcq.push(['_currentTime',Date.now()]);
        s=u.createElement('script');
        s.type='text/javascript';
        s.async=true;
        s.src='https://cdn.pushcrew.com/js/1d6c77106a652fb704b58580afb5a36f.js';
        h=u.getElementsByTagName('script')[0];
        h.parentNode.insertBefore(s,h);
    })(window,document);

  </script>
  <?php
}


// Add Commission junction
// =============================================================================

function add_my_javasript (){ ?>

<script src="//www.anrdoezrs.net/am/8372070/include/allCj/impressions/page/am.js"> (http://www.anrdoezrs.net/am/8372070/include/allCj/impressions/page/am.js)>

<?php } 

add_action('wp_footer', 'add_my_javasript'); ?>

With regards to PHP and the usage of X and WordPress hooks, there is no problem. I’m not sure about the scripts within it though and it is outside the scope of our support to investigate third party scripts. We do have an in-house custom development team that offer paid services, who may be able to assist. They can be contacted at pinnacle@theme.co if this is of interest to you. If you have any further questions about the theme, we are more than happy to provide you with assistance on these inquiries.

Thank you for your understanding.

Does this HAVE to be in a child theme?

Hi @neoinoakleys

Yes, since this is a custom function, it should be placed on child theme’s functions.php file. Please read this post as to why child theme is important when you have custom modification on the theme/site.

Thanks,

Thanks.

Well look. I’ve migrated from TagDiv Newspaper theme to this.
With TagDiv you copy and paste into the functions php and things just work.
Here you have to write code to make things work.
Commission junction is the largest affiliate site in the world for example.

The functions i provided in the code came from the old Themeco forum, so an answer has sort of been provided before as other’s have asked. They just don’t work.
The issue is not in the code companies are providing, the issue is in what the code needs to be wrapped in for Themeco to work and not turn websites in 500s.
So what is the code to input JS based tracking code that multiple companies use?

And yes, I write this in child function.php

Thanks

Hello There,

Thanks for updating in! To resolve your issue adding codes in the header or footer, I would highly recommend that you use a 3rd party plugin, Insert Header and Footers (https://wordpress.org/plugins/insert-headers-and-footers/). 100% No coding required. All you need to have is the code from GTM, Facebook Pixel, etc and place it in the header or footer settings using that plugin.

Hope this helps.

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