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 the page uses everytime just one of it, 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 the script while displaying the page in browser, so in case of 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:
<div id='papPlaceholder'></div>
 
<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 placeholder = document.getElementById('papPlaceholder');
    placeholder.parentNode.insertBefore(script, placeholder);
    placeholder.parentNode.removeChild(placeholder);
  })(document, 'script');
</script>

We can divide the above code to two sections. The placeholder and the tracker. Both codes have to be somewhere in HTML body. The placeholder is the place where the click tracking code will be deployed by the tracker and always have to be placed somewhere before the tracker.
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:
<div id='papSaleTrackingPlaceholder'></div>
 
<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.track(); } catch (e) {}

    }
    var placeholder = document.getElementById('papSaleTrackingPlaceholder');
    placeholder.parentNode.insertBefore(script, placeholder);
    placeholder.parentNode.removeChild(placeholder);
  })(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, make sure the account ID in the PostAffTracker.setAccountId('default1'); line  is correct as well (each merchant finds in his merchant panel at Tools > Integration the proper account id in the tracking codes).
In the sale tracking code do not forget to replace the sample values of tracking parameters (setTotalCost() , setOrderID() etc.) with some dynamic variable of your shopping cart.