Google Tag Manager and Single Page apps

Benjamin Netter picture Benjamin Netter · Oct 23, 2015 · Viewed 17.7k times · Source

I'm trying to integrate Google Tag Manager with my Ember app. I'm having a hard time understanding how to notify GTM that the page changed, and send a page view event.

I've read a lot of things online, mostly working around creating a new variable for a "virtual page" or something, but obviously this is far from ideal.

I'd like to be able to just use dataLayer.push to notify the page actually changed. Is there an easy way out I didn't find or is it really a pain to track with GTM on SPA?

Answer

András Szepesházi picture András Szepesházi · Feb 11, 2018

This was asked quite a while ago. With the current feature set of GTM, you can easily set up SPA page tracking without much trouble.

First, go to Triggers and create a new trigger. Select History Change as the trigger type. This will create a trigger that fires every time the location history changes.

Then create a new Tag of Universal Analytics type and set it up as per the screenshot below.

[Universal Analytics tag configuration1

As for the trigger, set the previously defined History Change trigger, and you're done. Every time a navigation occurs in your SPA, a page view event with the proper page path will be triggered.

EDIT: as trognaders pointed out in a comment, this does not track the initial page view. To remedy, simply add an additional trigger for your tag that fires on the Page View event (All Pages). See screenshot below.

enter image description here