AppMeasurement loading race conditions



I'm running into an issue where some of my code in a third party script is running before the AppMeasurement library is loaded.  I'm trying to figure out what the best solution to solve this issue.  Here is the setup:

- Adobe Analytics tool configured to load at page bottom

- Global rule that is set to load on DOM ready. This rule has a non-sequential third party script that watches for custom JS events and fires custom link tracking

- A page rule that loads on DOM ready that tracks the normal page load events

The problem I'm having is that the global rule seems to be firing the custom event before AppMeasurement has been loaded which causes a JS error to happen.  The JS error then interferes with other JS thats running.  I need the Adobe Analytics tracking to fire at the bottom of the page because we set some global JS data as the page loads.  I've tried switching to a sequential third-part script but then we run into a situation where the custom event watcher isn't set when it's being triggered.

I think the best case scenario would be to be able to load the AppMeasrurement library at the top of the page while keeping the Adobe Analytics page load event triggering at the bottom of the page. Is that something that is possible?

Accepted Solutions (0)

Answers (1)

Answers (1)




You can set the AA tool config to load at top of page. It just loads there; it doesn't actually trigger the s.t() call at that time. The s.t() call isn't made until DOM Ready. So you can configure the AA tool lib to load at top of page, and create page load rules to populate AA vars at Top of Page, Bottom of Page, and/or DOM Ready, and they will be included in the s.t() call.

Note that while you can set AA vars in a rule set to trigger on Onload (Window Load), they will not be included in the s.t() call, because the s.t() call has already been made a this point. I kinda feel like this is a bug.  Either DTM is not working as advertised, or else it should be grayed out as an option for Onload, or something. Point is, you are physically able to create a Page Load Rule set to trigger Onload, and you can set AA vars in it, but they won't be in your AA request, because AA already triggered!

Sidenote: You mentioned that the Global rule set to load DOM Ready is triggering before the AA tool configured to load at page bottom.  This shouldn't be possible. Items set to trigger at "Bottom of Page" or "Page Bottom" means they will syncronously load when the DTM Footer code (_satellite.pageBottom) is called, which should be a syncronous blocking script directly on your page, so it should very definitely trigger before DOM ready event.  So, assuming your AA tool vs. Global rule are indeed configured at appropriate trigger points, then it sounds like

a) You have _satellite.pageBottom() wrapped in a DOM Ready or other callback that isn't executed syncronously/immediately directly on-page (or you put it in some other script tag not loaded syncronous or blocking, etc..) instead of placed directly on the page in a blocking script tag

b) Your DTM Footer (_satellite.pageBottom) script tag is missing from your page. If this is the case, then DTM will internally make a _satellite.pageBottom call on DOM Ready if it has not been previously called.

If either of those scenarios apply to you, then fix it.  But if they do not, then... that sounds like some deeper issue you should probably investigate, because at face value, this should not be happening.