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?
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.
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.
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.
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.
[
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With