A Single Page Application (SPA) is a web application that loads a HTML document only once and dynamically updates its content, typically through AJAX requests without page reloading.

For tracking SPAs, virtual pageviews are often used – events generated in GTM synthetically, without actual page reloads, such as when a user interacts with or updates the content.

In Universal Analytics, tracking single-page applications with virtual pageviews could pose challenges. Sending virtual pageviews from URLs usually excluded UTM parameters, and the referrer remained the same, leading to the creation of a new session and inaccurate attribution of subsequent conversions.

In GA4, the situation has somewhat simplified – sessions no longer break, but conversion attribution still relies on the last non-direct source (in the case of using Last Click attribution). Essentially, Google organic traffic may continue to claim some conversions from paid traffic in GA4.

To avoid misunderstandings, I recommend adhering to the following practices when calculating attribution for SPA sites:

1. Use session-based attribution on raw data in BigQuery and extract source data from the first hit. This practice is particularly relevant for SPA.

2. Preserve the original URL during the initial page load in the dataLayer array and then substitute it in virtual pageview events. Exercise caution with this method, as it may not cover all corner cases of your project.

3. If the URL contains a '#' and it's crucial for you, rewrite the page_location using the JavaScript variable window.location.href.

4. Some practices suggest rewriting or resetting page_referrer. Approach this cautiously, as there is no foolproof mechanism for dealing with synthetic document.referrer.

If you work with GA4 to BigQuery exports, be sure to check out my SQL cheat sheet.