Expand my Community achievements bar.

SOLVED

Including Adobe DTM asynchronous in AngularJS

Avatar

Level 1

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?

here my code :

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>');
});

https://i.stack.imgur.com/NbNTI.png

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Have you considered using Launch instead of DTM?

DTM is full of document.write calls which is OK if you're using DTM in a supported way (i.e. Header embed synchronously loaded in the HEAD, and pageBottom() synchronously called just before the closing BODY tag).   There are certain expectations that DTM has regarding when it is being invoked within the lifecycle of a page being rendered.  Your implementation does not support DTM's expectations.

Launch, however, supports async embed and does not require the pageBottom call.

If you absolutely can't move to Launch, I'd suggest looking at the contents of each of these scripts and seeing why they cannot be loaded after DOM ready.  If they are "sequential JS" try changing to "non-sequential JS". 

View solution in original post

2 Replies

Avatar

Level 1

And I can’t include for all our clients. I forgot to put the screenshot.

NbNTI.png

Avatar

Correct answer by
Community Advisor

Have you considered using Launch instead of DTM?

DTM is full of document.write calls which is OK if you're using DTM in a supported way (i.e. Header embed synchronously loaded in the HEAD, and pageBottom() synchronously called just before the closing BODY tag).   There are certain expectations that DTM has regarding when it is being invoked within the lifecycle of a page being rendered.  Your implementation does not support DTM's expectations.

Launch, however, supports async embed and does not require the pageBottom call.

If you absolutely can't move to Launch, I'd suggest looking at the contents of each of these scripts and seeing why they cannot be loaded after DOM ready.  If they are "sequential JS" try changing to "non-sequential JS".