Asynchronous tag

 

Foreword

You may load our JavaScript library asynchronously. However, this requires an adaptation in your tagging.

 

Tagging

  • Declare the ATInternet callback in the following manner
window.ATInternet = window.ATInternet || {};
window.ATInternet.onTrackerLoad = function(){
    window.tag = new window.ATInternet.Tracker.Tag();
    // your tag
};

In this way, you declare the function onTrackerLoad in the global object ATInternet. This function is then automatically called when the file smarttag.js finishes execution.

  • Load our JavaScript library asynchronously
(function(){      
    var at=document.createElement('script');
    at.type='text/javascript';   
    at.async=true;    
    at.src='http://www.site.com/smarttag.js';
    (document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]||document.getElementsByTagName('script')[0].parentNode).insertBefore(at,null);   
})();
 

Tagging example

<script type="text/javascript">
window.ATInternet = window.ATInternet || {};
window.ATInternet.onTrackerLoad = function(){
    window.tag = new window.ATInternet.Tracker.Tag();
    // your tag
};
(function(){      
    var at=document.createElement('script');
    at.type='text/javascript';   
    at.async=true;    
    at.src='http://www.site.com/smarttag.js';
    (document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]||document.getElementsByTagName('script')[0].parentNode).insertBefore(at,null);   
})();
</script>

The URL of the smarttag.js file must be replaced by the file path on your server.
Declaration of the callback onTrackerLoad must always be done before loading the smarttag.js file.
Remember, the feature tag.clickListener measures an element that must exist at the moment that the feature is used

Last update: 04/03/2019