I'm running into issues with DTM and the timing of referencing a js object. I noticed that at times, DTM doesn't have access to the js object the web application (ASP.net MVC framework) creates. The js object is created before any of the js from DTM loads but I started having to use "settimeouts" in a few spots to ensure I had context to the object but this is now becoming increasingly more difficult to manage as I'm having to do this in a number of locations.
I was wondering if anyone had any advice on how to delay the loading of the DTM files until I know that I have access to that object? I have a bootstrap file that loads the appropriate DTM files. I was thinking about possibly putting the delay in the bootstrap loader file but I still don't like that solution as I'm also concerned about load time of the pages. Ideas?
-Thanks!
You're right. This can be tricky. Essentially its a race between the DTM page load and execution of your code.
If this is something you need to control on page load, one solution would be to "abort" the original AA request on page load and then, when your object exists, call a direct call rule that will send the data.
I might try something like this:
//Page Load Rule - Adobe Analytics Custom Code Section
s.abort = true // cancel the initial image request on page load
//Check for ASP Object
//Can be done within AA custom code or a custom JS tag
if (MY_OBJ_EXISTS) {
_satellite.track('MY_RULE_TO_SEND_DATA_TO_AA')
}
The same concept can be applied if you have ajax that needs to load before you send data to AA. You can abort the initial call, listen for a callback and send data via a direct call rule.
Hope this helps.