Direct call rules in SPA (Single Page Application) async deployment

galynai3258253

16-09-2020

Hello 🙂 

 

We use _satellite.track to track pageviews in the Single Page Application while the Adobe script loads asyncronously. As expected, sometimes we get error message: _satellite is not defined. It means that the _satellite.track had been fired before the script finished loading.

 

What is the best way to solve this issue technically? Is there any method recommended by Adobe? 

 

Thank you in advance.

Galyna

 

 

 

Accepted Solutions (1)

Accepted Solutions (1)

evolytics_brian

16-09-2020

I think the only real option here is to code around the context of your site. Before calling _satellite.track(), make sure it exists. This could be done in various ways...

  • Define your data layer on the page and move the _satellite.track() call into Launch.
  • Create an interval that continuously checks for the _satellite object, only calling _satellite.track() when you're certain it exists on the page.
  • Create a page load rule that notifies the page that _satellite has loaded and is ready to go. When that rule fires, use it to trigger your _satellite.track() call(s) by emitting a custom JS event that can be subscribed to with a simple document.addEventListener() in your page content. (Or, set a JS variable on the window that, when present/populated, tells the page that you're ready for the _satellite.track() calls to fire.)

You have a lot of options, but at the end of the day, it's just a timing challenge, and you'll have to decide what fits best in your environment.

Answers (0)