Search code examples
javascriptgoogle-ads-apinoscript

Tracking Pixels...Why do you need script and noscript?


I often find when adding tracking pixels there is a javascript and non-javascript options:

<!-- Google Code for Online Purchase Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = xxxxxx;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "Aa4-CNKm8QcQvu2V0QM";
var google_conversion_value = 1.00;
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/xxxx/?value=1.00&amp;label=Aa4-CNKm8QcQvu2V0QM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

Why is the JS version needed...i.e. why don't you have simply:

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

Solution

  • As others have hinted at, the javascript version offers some more advanced capabilities. One of the most important ones is adding a random cache-busting number to the request to avoid caching. If you don't include the cache buster, you're at risk of getting data discrepancies (e.g. under-counting conversions or having smaller cookie pools for remarketing).

    The example pixel you have there has pretty static information that is easy to put into an image pixel, but it could contain a lot more advanced info too. Sure, you could encode all of this extra advanced info in an image tag (that site has instructions on how to do it), but it can be error prone.

    I've seen a lot of tags that simply don't work because someone tried to encode it all themselves and they got it wrong. For the majority of people, it is better to use the human-readable, easy to develop, and easy to debug javascript version and leave the encoding and formatting to Google's code rather than try to do it all on their own.

    You could argue that there are performance implications and you'd be right - in the grand scheme of things the difference in running the tracking javascript instead of just loading the image tag though is a drop in the ocean compared to what most websites these days are doing and on modern devices wont be noticeable, but if you are going for the absolute bleeding edge of performance and are 100% sure you're encoding everything right yourself, you can use the image tag as described on the site.

    Hope that helps!