Single Page Application Website Tracking Issue

Has anyone come up with a good solution for tracking when the tracking script is put on a single page application website.

From my understanding what happens in websites like this is the header is consistent across the entire site and any page that is loaded gets a new url, but the header stays the same, as such Mautic is unable to track different page hits in the site. The only way to see a new page hit is if someone refreshes the entire site (on a new page for example) and then a new anonymous lead is created in contacts.

I am very interested to see how this can be overcome without having to manually go and insert the tracking script in the body of each page (considering some sites could have thousands of pages)

Well, I have not tried this, but looking at how tracking is done in GTM for those kind of apps and how mautic tracking script works.

I would approach it as follows:

  • in your SPA attach listener to browser location change
  • trigger mt(‘send’, ‘pageview’); inside the callback
  • move the logic to component and use component on every page of your app (note: you should benefit using the component in main - root component, but without experiments, there is no telling).

You might have to modify mauitc tracking script slightly (you already have an event in mautic for this) to go with your frontend framerwork (react, angular, etc.).

About the title - with SPA it does not really matter if it does not change as you can adjust the mautic tracking script to get value from some other variable than page title.

If you want, you can also change the title of the page via SPA - I would probably first try this as then I would be able to avoid at least some modifications of tracking script.

1 Like