Asynchronous tracking scripts

In case you need your scripts to be loaded asynchronously, try to follow this article on how to change it...
 

Default click tracking code

The default click tracking code which is available in your merchant panel looks like this:
<script type="text/javascript"><!--
document.write(unescape("%3Cscript id='pap_x2s6df8d' src='" +
(("https:" == document.location.protocol) ? "https://" : "https://") +
"URL_TO_PostAffiliatePro/scripts/trackjs.js' type='text/javascript'%3E%3C/script%3E"));//-->
</script>
<script type="text/javascript"><!--
PostAffTracker.setAccountId('default1');
try {
PostAffTracker.track();
} catch (err) { }
//-->
</script>
This code generates a correct code based on protocol used on the website (with http or https).
 
In case you know that only one protocol is used each time you can shorten the code so it uses just the final link.
<script type="text/javascript" id="pap_x2s6df8d" src=" https://URL_TO_PostAffiliatePro/scripts/trackjs.js">
</script>
<script type="text/javascript"><!--
PostAffTracker.setAccountId('default1');
try {
PostAffTracker.track();
} catch (err) { }
//-->
</script>
 
In both cases the code is loaded by client browser with all the other webpage content. This may result in slow load of the webpage in case the server with Post Affiliate Pro or Post Affiliate Network is slower or not responding. In case the tracking code is placed in beginning of the HTML body, the whole page would not display until the server with PAP or PAN responds... This can take few seconds to tens of seconds. I am sure this is something you would not like your customers to see.

To avoid this, (mainly in case your PAP or PAN server is slower) you should use asynchronous approach.
 

Asynchronous click tracking code

The difference between standard and asynchronous approach is in time when scripts are loaded. Standard approach loads script one by one while displaying the page in browser so in case of a problem the other content waits for the problematic script. In case of asynchronous approach scripts are loaded after the page is displayed. The following code is the click tracking code which will be displayed asynchronously:
<script type="text/javascript">
  (function(d,t) {
    var script = d.createElement(t); script.id= 'pap_x2s6df8d'; script.async = true;
    script.src = '//URL_TO_PostAffiliatePro/scripts/trackjs.js';
    script.onload = script.onreadystatechange = function() {
      var rs = this.readyState; if (rs && (rs != 'complete') && (rs != 'loaded')) return;
      PostAffTracker.setAccountId('default1');
      try { PostAffTracker.track(); } catch (e) {}
    }
    var theBody = document.getElementsByTagName("body")[0];
    theBody.appendChild(script);
  })(document, 'script');
</script>

The code has to be somewhere in HTML body. Note that the asynchronous approach may result in missing clicks. As the code will be loaded after the whole page is loaded, it can happen that a "quick customer" (clicking too fast without waiting for the site to fully load) won't be tracked at all.
 

Asynchronous sale tracking code

The following code is the sale tracking code which will be displayed asynchronously:
<script type="text/javascript">
  (function(d,t) {
    var script = d.createElement(t); script.id= 'pap_x2s6df8d'; script.async = true;
    script.src = '//URL_TO_PostAffiliatePro/scripts/trackjs.js';
    script.onload = script.onreadystatechange = function() {
        var rs = this.readyState; if (rs && (rs != 'complete') && (rs != 'loaded')) return;
 
        PostAffTracker.setAccountId('default1');
        var sale = PostAffTracker.createSale();
        sale.setTotalCost('120.50');
        sale.setOrderID('ORD_12345XYZ');
        sale.setProductID('test product');
        try { PostAffTracker.register(); } catch (e) {}

    }
    var theBody = document.getElementsByTagName("body")[0];
    theBody.appendChild(script);

  })(document, 'script');
</script>
 
NOTICE:
In all the codes here we are using a fake URL to PAP or PAN. If you want to use it you have to change the URL_TO_PostAffiliatePro to match the real URL of your installation of Post Affiliate Pro (Network). 
In case of Post Affiliate Network you also have to make sure the account ID in function call PostAffTracker.setAccountId('default1'); is set correctly as well (each merchant can find their account ID in merchant panel Tools > Integration).
In the sale tracking code do not forget to replace the sample values of tracking parameters (setTotalCost() , setOrderID() etc.) with some dynamic variables of your shopping cart.