Best practices for Single-Page Apps | Community
Skip to main content
February 12, 2018

Best practices for Single-Page Apps

  • February 12, 2018
  • 5 replies
  • 76575 views

What are the best practices for Single-Page Apps tracking using Launch? Basically, I'm looking for a robust techique for collecting / dispatching virtual pageviews (JS framework agnostic).

Here https://marketing.adobe.com/resources/help/en_US/experience-cloud/launch/c_extension-dtm.html I found that Launch Core extension contains events like “Custom Event” and “Data Element Changed”.  I suppose I should use one of these features, but not sure which one to select as I don’t know their pros and cons. 

On the web I found some examples for DTM only, I don’t know if they are applicable to Launch.

When working with GTM, I used custom events for these purposes. However custom events in GTM are just key-value pairs pushed into the GTM data layer. But in the DTM-related articles which I saw on the web custom events refer to something absolutely different: Javascript-native interface called CustomEvent: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent

Any suggestions / documentation on this?

Thanks a lot!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

5 replies

February 19, 2018

For all our SPAs we use direct call rules which the developer would fire after the datalayer was ready. Custom events ion DTM I believe are page events such as button clicks, hash changes, etc. that trigger a rule to fire.

February 19, 2018

We've build a framework for tracking, in which we use for DTM / Launch Custom Events. With Direct Call Rules, you can only reference a "static" Digital Data object, which might cause race conditions if you're not managing your Digital Data Object correctly.

The advantage of Custom Events is that you can pass context data with the event; so we're passing the Digital Data Object as event data, and reference this directly from within DTM / Launch.

This works flawless within traditional page based sites, as with SPA's. In an SPA, Dev would just "trigger" a "Page impression" event. In a traditional page based site, the "Page impression" is a trigger call on document.ready.

Stewart_Schilling
Community Advisor
Community Advisor
March 1, 2018

+1 on using custom events in preference to direct call rules in SPA environments.

+1 on letting the SPA tell Launch when a page has changed as it accounts for hard loads, and soft navigation equally well.

+1 on passing the DDO as the payload on the event (the presence of "event" as a free variable was sort of an easter egg in DTM). 

jkunz
March 1, 2018

I used to prefer using custom events Event Based Rules to using Direct Call Rules because DCRs couldn't handle additional conditions, but now in Launch, they can, so I think it's more a matter of preference.
But I agree, you definitely want to use one or the other to let Launch know when the new page view has occurred (after the new page view's data layer is in place).
Single Page Apps | Digital Data Tactics  has a bunch of documentation on Single Page Apps (both Launch or DTM).
And Setting up an Event-based Rule that be fired directly like a Direct Call Rule | Digital Data Tactics  has some use case and examples for Custom Events, and DTM Examples  has (buried in the source code) a working example.

March 2, 2018

I also use Custom Events

     1) due to the lack of conditional ruling in Direct Calls,

     2) DDL context: DC's can only read "the" static object... so if you would fire 2 DC's which might change your DDL in between distinctively, you're never sure if both DC's are reading the DDL at the correct moment for their context (race condition).

Since I'm working hard on changing from "page based analytics" into "event based analytics", which is more suitable for modern app frameworks (e.g. react, vue, etc...), proper DDL context on each event is crucial. If interested, please view my work on

xploregroup / xploregroup-webanalytics-demo — Bitbucket

This is the framework I mentioned earlier. The repo points to a set of other repo's with front-end code. The DTM translator holds the Custom Event implementation for DTM/Launch.

have fun...

Stefan

Stewart_Schilling
Community Advisor
Community Advisor
March 2, 2018

Hi Stefan!

I'm interested in seeing that repo, but the link you gave is giving me an error.

-Stew

Also, if you'd like to connect on LinkedIn, here's my profile: https://www.linkedin.com/in/stewartschilling/

jantzen_b
Adobe Employee
Adobe Employee
March 1, 2018

Moderator Note: Since this question has turned more into a discussion, I'm going to change this into a discussion. The discussion will allow users to read each of these answers without the need to select a single one as correct.

Stewart_Schilling
Community Advisor
Community Advisor
November 8, 2018

OK. Seven months later...    Better later than never?

We just deployed a new extension to the Launch Production Catalog called "Data Layer Manager (free edition)".  It is built as a best practice approach to asynchronous embeds of Launch with data layer events that may come before or after Launch has loaded.  It blends a bit of the GTM dataLayer with a bit of the W3C CEDDL (but avoids most of the nonsense).

We also just deployed the new "AA Product String Builder" which works REALLY nicely with the Data Layer Manager. Be sure to check it out if you are doing Adobe Analytics stuff.

November 8, 2018

Cool looks interesting, though a bit too late for me Also the Product String Builder. I'll have a look at it the next time I need to build product strings.

I decided to use direct call rules for the whole website, when I found out you can provide a payload as Aaronius mentioned in March. With this I have enough control over the events and the data they should process. I also changed the normal page load from pageBottom to a direct call but with a check if there is an SPA container on the page and gets only fired if there isn't. The SPA then fires an init direct call when it is ready which uses the same rule as the page load but we can be sure the app did all the necessary modifications to the datalayer.