FAQ

  1. Home
  2. Docs
  3. FAQ
  4. Core Web Vitals
  5. How do I adjust the etracker code so that the etracker script is loaded asynchronously?

How do I adjust the etracker code so that the etracker script is loaded asynchronously?

You can simply adapt the existing etracker code by replacing src=”//static.etracker.com/code/e.js” with src=”//code.etracker.com/code/e.js” and adding the async keyword. 

The code must contain the parameter marked in the example:

Caution when using asynchronous code retrieval and eCommerce events. Timing problems can occur here, which result in the eCommerce events not being transmitted successfully. Therefore, the eCommerce API should be called in the following function, which ensures that the etracker code has already been loaded before the Ecommerce events are sent:

<script>
function _etrackerOnReady() {
etCommerce.sendEvent('viewProduct', { /* product */ } );
}
</script>

Or the following function, if several events are to be sent from different places in the code:

<script>
window._etrackerOnReady = typeof window._etrackerOnReady === 'undefined' ? [] : window._etrackerOnReady;
window._etrackerOnReady.push(function() { etCommerce.sendEvent('viewProduct', { /* product1 */ } ) });
</script>
...
<script>
window._etrackerOnReady.push(function() { etCommerce.sendEvent('viewProduct', { /* product2 */ } ) });
</script>