Adding tracking tag code on specific pages

I seem to be having some issues with tracking code / tags on my site. I’m trying to put the below tag only on specific pages:

<script type="text/javascript"><!--

vs_account_id      = "fwABAVxl1bV0xQCd";

//--></script>

<script type="text/javascript" src="https://rw1.marchex.io/euinc/number-changer.js">

</script>

<!-- end ad widget -->

the page ids I need it on are: 216,906,179,169,899,905,147,169,2

I tried this code below but it doesn’t work as it seems to be conflicting with other tracking code / tags in my functions.php file:

function third_party_tracking_code_header() { 
  if ( is_page(216,906,179,169,899,905,147,169,2) ) : ?>

<!-- start number replacer -->

<script type="text/javascript"><!--

vs_account_id      = "fwABAVxl1bV0xQCd";

//--></script>

<script type="text/javascript" src="https://rw1.marchex.io/euinc/number-changer.js">

</script>

<!-- end ad widget -->
<?php }
add_action( 'wp_head', 'third_party_tracking_code_header' );

Hi @armintz,

Thank you for writing in, because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released.

Then update your code and place it on the child theme’s functions.php file:

 function third_party_tracking_code_header() { 
 if ( is_page ( array(216,906,179,169,899,905,147,169,2) ) ) : ?>

    <!-- start number replacer -->
    <script type="text/javascript"><!--
    vs_account_id      = "fwABAVxl1bV0xQCd";
    //--></script>
    <script type="text/javascript" src="https://rw1.marchex.io/euinc/number-changer.js">
    </script>
    <!-- end ad widget -->

 <?php endif; }
add_action( 'wp_head', 'third_party_tracking_code_header' );

More details about is_page() function.

Hope it helps,
Cheers!

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