Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Tag Manager and Single Page apps

Tags:

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?

like image 763
Benjamin Netter Avatar asked Oct 23 '15 09:10

Benjamin Netter


People also ask

How does Google Analytics work with a single page application?

In the case of traditional websites, Google Analytics works fine because the code snippet is loaded every time the page is loaded. But in the case of a single page application, content is loaded dynamically which means the page refresh happens only once and Google Analytics runs only once on the page.

Why you should not use Google Tag Manager?

We'll send you updates from the blog and monthly release notes. GTM is a code injector. Browsers generally view code injectors negatively because they can easily become a weak link through which hackers can plant malicious code in a website or app.

Does Google Tag Manager work for mobile apps?

The latest version of Google Tag Manager for mobile apps is smaller, faster, easier to implement, and more functional. It is integrated with Firebase – Google's platform for mobile developers across iOS and Android – and extends its capabilities for developers and marketers.


1 Answers

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

like image 119
András Szepesházi Avatar answered Dec 29 '22 00:12

András Szepesházi