How to add tracking code to body from header

In order for your tracking to work  you have to insert tracking codes to the HTML body. However, in some cases you cannot edit your site's body and the only way to add custom codes is to do it via header. Here's a little tip on how to do it with our tracking codes.

So once again, the purpose of the following HTML header script is to dynamically add a code to HTML body.

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {

    // the custom code goes here

});
</script>

If you want to add a click tracking code using this method you have to use asynchronous click tracking code so the result would look like this:

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {

   (function(d,t) {
    var script = d.createElement(t); script.id= 'pap_x2s6df8d'; script.defer = true;
    script.src = 'YOUR_PAP_INSTALLATION_DOMAIN/scripts/trackjs.js';
    script.onload = script.onreadystatechange = function() {
      var rs = this.readyState; if (rs && (rs != 'complete') && (rs != 'loaded')) return;
      try { PostAffTracker.track(); } catch (e) {}
    }
    var theBody = document.getElementsByTagName("body")[0];
    theBody.appendChild(script);
  })(document, 'script');

});
</script>

 

×