Server-side GTM for single-page applications (SPAs)

Written by

Liudmyla Kharchenko

Updated Sep 2, 2026 comments

What is a single-page application (SPA)?

Tracking single-page applications

3 ways to track single-page applications (SPAs)

GA4’s enhanced measurement for pageviews

Data Streams
Web stream details
Show Advanced setting
Page changes based on browser history events
Enhanced measurement events
Preview button
Connection interface
History change event
GA4 measurement ID

GTM’s History Change trigger

Create a new trigger
All History Changes selected
GTM's preview mode

Data Layer Push with GTM

<script>  window.dataLayer = window.dataLayer || [];  window.dataLayer.push({    'event': 'virtualPageview',    'pageUrl': 'https://www.example.com/path/?example#example',    'pageTitle': 'Example title'  }); </script>
Data Layer Variable config
Data Layer Variable config
Trigger config
GA4 Event tag config

Common challenges with tracking single-page applications

window.location.href
Send page view config parameter

Best practices for tracking single-page applications

Conclusion

Want to start using server-side tags?

Stape has lots of tags for server GTM! Click on Try for free to register and check them all.

Try for free

Written by

Liudmyla Kharchenko

Content writer

Liuda is a Content Manager at Stape, writing about server-side tracking and tech that simplifies work. She helps businesses improve data accuracy, find the right customers, and build connections.

Was this article helpful?

Comments

Recommended for you

Turn better tracking into better marketing performance

Try for free