Include Adobe DTM asynchronously in AngularJS

541 Views Asked by At

We have a platform developed with AngularJS. The platform is the same for all our customers. We must include Adobe DTM only for a client.

I sometimes have external scripts that aren't loaded. Do you have a better way to do it?

enter image description here

var adobedtm = '//assets.adobedtm.com/5249...abe2e5/satelliteLib-2d8560...eb5937-staging.js';

if( window._env.environment === 'production' ){
  adobedtm = "//assets.adobedtm.com/5249...abe2e5/satelliteLib-2d8560...eb5937.js"
}

$.getScript('//cdnjs.cloudflare.com/ajax/libs/postscribe/2.0.8/postscribe.min.js', function (data, textStatus, jqxhr){
  postscribe(document.body, '<script src="' + adobedtm + '" type="text/javascript"><script type="text/javascript">_satellite.setDebug(true);</script><script type="text/javascript">_satellite.pageBottom();</script>');
});

1

There are 1 best solutions below

0
On

I believe there is no better way other than embedding DTM library in the header section of your HTML file. the external scripts are added using document.write() which only work while the page is loading.

Reference: http://javascript.info/modifying-document#a-word-about-document-write