Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Add Tracking Code to Specific Page WordPress

  • SOLVED

I need to add two tracking codes to my wordpress site, but only on a specific page (the Checkout page, run through WooCommerce http://novelconcept.org/checkout/).
It's important that the tracking code data doesn't show up anywhere else.

The tracking codes:

<!-- Google Code for Checkout Page Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 1002376574;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "d22OCPLw2AcQ_pr83QM";
var google_conversion_value = 20;
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/1002376574/?value=20&amp;label=d22OCPLw2AcQ_pr83QM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>




-------------------------
and
-------------------------


<script type="text/javascript">
var _mfq = _mfq || [];
(function() {
var mf = document.createElement("script"); mf.type = "text/javascript"; mf.async = true;
mf.src = "//cdn.mouseflow.com/projects/4dea4abb-763c-40c8-bc3c-5be30163e8d7.js";
document.getElementsByTagName("head")[0].appendChild(mf);
})();
</script>

Answers (3)

2013-08-25

Liam Bailey answers:

You simply do this in your functions.php

add_action('wp_footer','add_tracking',20);


function add_tracking() {
if (is_page(#page_id#)) {
//replace #page_id# with id of page
?>
<!-- Google Code for Checkout Page Conversion Page -->

<script type="text/javascript">

/* <![CDATA[ */

var google_conversion_id = 1002376574;

var google_conversion_language = "en";

var google_conversion_format = "3";

var google_conversion_color = "ffffff";

var google_conversion_label = "d22OCPLw2AcQ_pr83QM";

var google_conversion_value = 20;

var google_remarketing_only = false;

/* ]]> */

</script>

<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">

</script>

<noscript>

<div style="display:inline;">

<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/1002376574/?value=20&amp;label=d22OCPLw2AcQ_pr83QM&amp;guid=ON&amp;script=0"/>

</div>

</noscript>
<script type="text/javascript">

var _mfq = _mfq || [];

(function() {

var mf = document.createElement("script"); mf.type = "text/javascript"; mf.async = true;

mf.src = "//cdn.mouseflow.com/projects/4dea4abb-763c-40c8-bc3c-5be30163e8d7.js";

document.getElementsByTagName("head")[0].appendChild(mf);

})();

</script><?php
}
}


philipzeplin comments:

if (is_page(#page_id#))

for the #page_id#, do I add in the page ID from wordpress instead?
So, for instance, it would look like:

if (is_page(47))


philipzeplin comments:

Also, where in the functions.php should I add this?


Liam Bailey comments:

You can add it anywhere insite the php tags <?php ?> and yes, you use the Wordpress ID for the page, you are correct.

2013-08-25

Abdelhadi Touil answers:

Hi.
You can use is_page() function to check if a page is being displayed like so:

<?php if is_page('checkout') { ?>
<!-- Google Code for Checkout Page Conversion Page -->

<script type="text/javascript">

/* <![CDATA[ */

var google_conversion_id = 1002376574;

var google_conversion_language = "en";

var google_conversion_format = "3";

var google_conversion_color = "ffffff";

var google_conversion_label = "d22OCPLw2AcQ_pr83QM";

var google_conversion_value = 20;

var google_remarketing_only = false;

/* ]]> */

</script>

<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">

</script>

<noscript>

<div style="display:inline;">

<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/1002376574/?value=20&amp;label=d22OCPLw2AcQ_pr83QM&amp;guid=ON&amp;script=0"/>

</div>

</noscript>

<script type="text/javascript">

var _mfq = _mfq || [];

(function() {

var mf = document.createElement("script"); mf.type = "text/javascript"; mf.async = true;

mf.src = "//cdn.mouseflow.com/projects/4dea4abb-763c-40c8-bc3c-5be30163e8d7.js";

document.getElementsByTagName("head")[0].appendChild(mf);

})();

</script>
<?php } ?>


Use it in your footer or header section.

Source:

[[LINK href="http://codex.wordpress.org/Function_Reference/is_page"]]http://codex.wordpress.org/Function_Reference/is_page[[/LINK]]

[[LINK href="http://codex.wordpress.org/Conditional_Tags"]]http://codex.wordpress.org/Conditional_Tags[[/LINK]]

Good luck.

2013-08-25

Sabby Sam answers:

Add this code in header.php
You will find in the theme directory.

http://codex.wordpress.org/Function_Reference/is_page
change your checkout page id , you will find in all page and moving mouse hover on quick edit.
<?php if(is_page(16)) { ?>
<!-- Google Code for Checkout Page Conversion Page -->

<script type="text/javascript">

/* <![CDATA[ */

var google_conversion_id = 1002376574;

var google_conversion_language = "en";

var google_conversion_format = "3";

var google_conversion_color = "ffffff";

var google_conversion_label = "d22OCPLw2AcQ_pr83QM";

var google_conversion_value = 20;

var google_remarketing_only = false;

/* ]]> */

</script>

<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">

</script>

<noscript>

<div style="display:inline;">

<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/1002376574/?value=20&amp;label=d22OCPLw2AcQ_pr83QM&amp;guid=ON&amp;script=0"/>

</div>

</noscript>
<script type="text/javascript">

var _mfq = _mfq || [];

(function() {

var mf = document.createElement("script"); mf.type = "text/javascript"; mf.async = true;

mf.src = "//cdn.mouseflow.com/projects/4dea4abb-763c-40c8-bc3c-5be30163e8d7.js";

document.getElementsByTagName("head")[0].appendChild(mf);

})();

</script>
<?php ?>


Alternate solution

http://docs.woothemes.com/document/conditional-tags/

is_woocommerce()
Returns true if on a page which uses WooCommerce templates (cart and checkout are standard pages with shortcodes and thus are not included).

This will work too.