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

Thanks for sharing.

I’m glad you’re looking for a solution to track your website’s single page application. Unfortunately, tracking scripts like Mautic struggle with sites that have a consistent header and dynamic URLs. However, website security should always be a top priority and making sure the tracking script is properly implemented is crucial. Have you considered using a security solution to protect your website? Security of your site can provide this company https://www.namecheap.com/security/protect-website/. It can be a challenge, but in the end it’s definitely worth it.

Tracking scripts on websites with single-page applications can be difficult because of the dynamic nature of these websites. However, there are some approaches and tools that can help you control and track the placement of tracking scripts. Tag Management Systems (TMS): TMS platforms, such as Google Tag Manager or Tealium, can be used to manage and deploy tracking scripts to your site, including single-page applications. These tools provide a centralized interface through which you can update, add or remove tracking scripts without directly changing the site code. They often offer preview and debugging functions that can help ensure that scripts are properly placed. But sometimes you can’t control everything, and we can see that at https://deeplab.com/security/widespread-malware-attacks-in-eastern-europe-flagged-by-google-tag.