Expand my Community achievements bar.

Tracking Click and Page View Events across multi-page + SPA

Avatar

Level 1

Hi all.

 

I am attempting to track click and page view events in an AB test I'm running.  However, I'm having some issues as the site we are working on is both a multi-page and a SPA website.

In the test, we are primarily tracking a button click from the home page, which navigates the user to a separate page in the site.

 

This new page operates essentially as a SPA, it has a funnel the user goes through similar to a "quote" application process, but it is all one page with sequential endpoints as "steps" in the process.

TLDR

  1. Selection events aren't re-attaching to the page on a multi-page + SPA solution
  2. Better way to force attach selection events than getOffers/applyOffers?
    1. getOffers/applyOffers is executed every time the url changes on an event listener
  3. Click tracking on nav menu in the home page is not consistent at all in live audience mode
    1. Is it possible that this is due to navigation happening too quick for target to log the event?

More Information
We have a primary goal (tracking button clicks on a CTA on the home page) as well as several sub-metrics (tracking each submit button clicked throughout the quote user funnel)

I'm running into the following issues when tracking:

  1. On the home page, the selection event is attached to the button normally (on page load event), submit button for the first step is also attached after navigation
    1. However, once the user navigates through the funnel, Target does not re-apply the metric selection events to the rest of the steps in the funnel ( as the url changes but the page does not re-load due to it being a SPA)
    2. Therefore, we get (albeit inconsistent) results from the first two metrics in the quote process, but none of the rest of the tracking occurs for the other steps
  2. To fix the above, I added a getOffers/applyOffers code snippet every time the url changes in the funnel
    1. This essentially treats every url change as a new page load event, re-attaching the click event listeners as expected throughout the funnel
    2. However, this is seen as a bandaid, and creates many callouts to Target that we don't need to track
      1. Any advice on tackling the above?  I could narrow down the getOffers/ApplyOffers callout
  3. Another issue, the button click on the homepage seems very inconsistent.
    1. In QA mode, the button click is tracked properly
    2. In live audience mode, the button click is tracked way less than the rest of the steps in the funnel
      1. eg maybe 4-5 button clicks were tracked, but over 100 people made it through the funnel
      2. indicating either the click event wasn't tracked for these users or they navigated to the rest of the funnel from other means
    3. Is it possible that the click navigation is happening too quickly for target to capture the click event?  Thus forcing the event to cancel?
      1. Also, is it possible for a user to trigger metrics from manually navigating to the pages (for page view metrics)?  Our intention is to only track users that have clicked the nav button initially, not track from anywhere else

Thank you, I hope someone can shed some light on this!  I'm happy to provide any code snippets/configuration details if needed.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

10 Replies

Avatar

Community Advisor

Hi @MatthewMu5 I believe you're using at.js for your implementation and this been either setup through Adobe Launch or directly at.js injection to your application right. 

So what I understood from above problem is that, The click tracking is not working as expected due to SPA dynamic content updates. 

 

So here I would suggest, instead of reloading the page or calling getOffers/ applyOffers each time, you can call adobe.target.triggerView(),  to inform the AT when the view changes .. in your case ( step in the funnel) 

adobe.target.triggerView("step1")

you can define/trigger the views for each SPA steps in funnel, like step1, step2, ... so on.

Here is the link for Adobe Target implementation in SPA -  you can go through it to understand the way it works. 

https://experienceleague.adobe.com/en/docs/target-learn/tutorials/implementation/implement-atjs-20-i...

https://experienceleague.adobe.com/en/docs/target-dev/developer/client-side/at-js-implementation/dep...  

 

For another question where you said, the button click on the homepage seems very inconsistent 

Possibly, the navigation occurring too quickly for Target to capture the event, then either you can put some delay after the click event to make sure that click event is captured  using 

adobe.target.trackEvent

https://experienceleague.adobe.com/en/docs/target-dev/developer/client-side/at-js-implementation/fun... 

 

You go through this and if any more questions please feel free to post it here.

Hope this helps.

Thanks

 

Avatar

Level 1

Hi @Gokul_Agiwal , thanks for the help!!

 

So thats the thing, we were originally using triggerView on url hash changes with no luck.  We're using Adobe Launch/Data Collection and running a rule to load target onto the page.  We're attaching an event listener onhashchange to execute triggerView
For more context here is the script we run (the getOffers portion is currently commented out but we were testing with that too):

function sanitizeViewName(viewName) {
  if (viewName.startsWith('#')) {
    viewName = viewName.substr(1);
  }
  if (viewName.startsWith('/')) {
    viewName = viewName.substr(1);
  }
  return viewName;
}
function triggerView(viewName) {
  viewName = sanitizeViewName(viewName) || 'home';
  // Validate if the Target Libraries are available on your website
  if (typeof adobe != 'undefined' && adobe.target && typeof adobe.target.triggerView === 'function') {
    adobe.target.triggerView(viewName);
    
    // This is the getOffers/applyOffers bandaid
    /*adobe.target.getOffers({
        request: {
            execute: {
                pageLoad: {}
            }
        }
    }).
    then(response => adobe.target.applyOffers({ response: response }))
    .then(() => console.log("Success"))
    .catch(error => console.log("Error", error));*/
    console.log('AT: View triggered on page load: '+viewName)
  }
}
//fire triggerView when the SPA loads and when the hash changes in the SPA
if(window.location.pathname.indexOf('sidney/testing/select-limits/#/')){
    triggerView(location.hash);
}
window.onhashchange = function() {
    if(window.location.pathname.indexOf('sidney/testing/select-limits/#/')){
        triggerView(location.hash);
    }
}

To be clear, the triggerView code above is firing properly, but selection events are not being re-attached to track user's clicks further in the funnel.

 

The metrics are using page-load events to attach the click event listeners, so my guess is triggerView is not working on these events because of that.  Is there a way I can trigger these events to attach when the View loads (ie when triggerView occurs)?  I'm not seeing anywhere in the experience UI to assign a metric goal to attach on a specific view (at least in Goals & Settings)

MatthewMu5_3-1736436959458.png

 

However, I CAN see the view when setting up Experience A/B in the "Experiences" tab.

MatthewMu5_2-1736436906984.png

 

Is there something I'm missing here?

Avatar

Community Advisor

Hi @MatthewMu5 

Can you try to use with a custom events which listen to explicitly when the SPA view changes.

After triggerView, dynamically reattach custom event listeners to track click events. like below, 

window.onhashchange = function () {
  if (window.location.pathname.indexOf('sidney/testing/select-limits/#/') > -1) {
    triggerView(location.hash);

    // Attach custom click listeners as needed
    document.querySelectorAll('.quote-submit-button').forEach(button => {
      button.addEventListener('click', function () {
        adobe.target.trackEvent({
          mbox: 'funnel-step-click', //custom mbox name
          params: { step: location.hash }
        });
      });
    });
  }
};

 

also make sure your adobe launch rule fired on every view change include the custom event to track click event. 

 

Once this custom mbox triggered successfully, you can utilise this in your goals and setting metrics. 

Hope this helps. 

Avatar

Level 1

Thanks for the help!

Yeah, one goal for me is to reduce the amount of adobe.target calls. Binding applyOffers on every page load causes many unnecessary callouts. 

 

Binding the trackEvent to a click listener will reduce that amount, so I will try this method out and update with my findings.

Avatar

Community Advisor

Hi @MatthewMu5 

Yes try with trackEvent and let us know how it's going for you? Post your findings, thanks 

Avatar

Level 1

Hi @Gokul_Agiwal 

How can I view these trackEvents?  I can't seem to find anything in the adobe target UI to be able to view reports on them.

 

Thanks!

Avatar

Community Advisor

Hi @MatthewMu5  

trackEvent functionality does not provide an interface to view or report on these custom events directly within the Adobe Target UI.

Actually, it serves as a way to capture custom actions that can then be tied to specific metrics or used for integrations with Adobe Analytics (via A4T) or Target reporting tools.  

 

In this case, once you implement the trackEvent, you can tie the mbox name 'funnel-step-click' (from above example) in Goals and Setting screen with custom metric. 

Thanks

Avatar

Level 9

@MatthewMu5 can you confirm which Target extension you are using in Adobe Launch, should be V2- has support for SPA

Avatar

Level 1

Yep!  We are loading Target v2.

 

Does this SPA support include tracking button clicks on triggerView?  I read the docs and I was unable to confirm if triggerView is supposed to also trigger re-attaching click/page view metrics to the DOM.
My ideal world would be:
onhashchange -> call triggerView() -> triggerView looks for metrics defined in adobe target builder and attach listeners to the page.

Let me know if my understanding of that is incorrect.  The alternative would be to define those metrics in code as a rule, but I'm looking for a way to avoid hardcoding every metric if I don't have to.

Avatar

Level 9

@MatthewMu5 yes  Trigger View action can be called whenever a new page is loaded or when a component on a page is re-rendered. 

Use Target 2 extension in Tag > action > configure then condition per your flow