GTM - History Change Trigger not tracking Initial PageLoad - google-analytics

I am using History Change trigger in my GTM TAG to track my page views since mine in Single Page Application(Angular 6). I could see all the page views and its related data are tracked except Initial page load i.e., HomePage.
If I do refresh my home page it is getting tracked.
Do I need to use different trigger to capture initial page load or Am I missing something here?
Any reference link would be helpful.

You can add the "all page" trigger to the GTM tag and it will trigger on both history change and page load.

Related

GTM UA Tag - Track Page Views using All Clicks OR All Pages as triggers

I'm still learning GTM, so please forgive me if this is a basic question. I've been researching but can't find anyone with a similar issue.
What I want is simple: to set up GTM to track page views in UA. (Easy enough.) But I looked at the setup of my predecessor, and he had the UA tag set up like this:
Tag Type: Google Analytics (UA)
Track Type: Page View
(GA ID)
Triggering:
All Clicks (All Elements)
OR
All Pages (Page View)
I'm trying to understand why they set it up with the All Clicks trigger. What I fear is that this is recording a page view every time a click is recorded, but I can't imagine my predecessor would have created a strange setup like that. I'd just as soon eliminate the All Clicks trigger, but I don't want to harm any of our future data without fully understanding. Bottom line question: is there any good reason for this tag to be set up this way, or is it wrongly inflating my numbers? Thanks in advance for any help.
It's kind of weird.
If the tag is for tracking pageView. The trigger should only be all page.
Still there might be 1% that your predecessor really knows what he or she is doing.
Maybe you can share the website and we can check if it is abnormal or not.
Update about the click trigger
The website is firing "Pageview" when click the link.
You can change the GA tag from pageview to event and set up like this
Category : click
Action : link_click
Label : {{the click Url}}
Then you can see which user is doing pageview and who clicks the link.

Fire a page view tag but only if it was from a specific referral URL. Google tag manager

I have a form that when submitted it goes to a different "success page" and I want to use that landing page to track conversions or count how many times people hit the "submit". I could use a page view tag but then that will fire every time someone goes to that page. So perhaps if someone hits the back button and reloads the page then that will count as a form submit.
So I would like to make a page view Tag in google tag manager that only fires if the page view is coming from a specific URL or referred from a specific URL. Is this possible?
Thanks in advance.
It is possible. Enable the built-in "referrer" variable, and on your target page create a trigger "pageview", with an added condition "referrer equals <your referrer>".
Some browsers might not send a referrer header, so this is not 100% reliable. If the page that sends the traffic is under your control, you might consider using a tracking parameter instead.

Customize history change trigger to skip hashchanges on same page in GTM

I have a website with Barba.js to use pushState API to load pages. So to track these virtual page loads in GTM I added a History Change trigger to fire analysis page view event. It works great.
But if I have on page anchors, e.g
About
This also fires the History Change event, and cause google analytics to record another page view which I don't want.
Is there a way to make a history change trigger that only fires on new pages e.g if /services changes to /about , and doesn't fire when URL changes from /about to /about/#about
Update :
I have now used 'History Source' variable equals to 'pushState' condition to filter history change events because the hash change events is showing 'popState' in the History Source in the Data Layer variables. I am not 100% confident that this is correct, but it seems to be working.

Google tag manager single page application window load and history change

I'm trying to create page view tags. I have to create two for two different triggers.
Page view triggered by history change;
Page view triggered on window load (because first page load doesn't have any history change)
My problem is the home page, which is firing both tags.
Because if put in URL www.mysite.com, the page redirects to my.site.com/home
which creates a window load and a history change. So two page view tags are fired.
I can't exclude historychange trigger to exclude page path: /home because once people got into the site they'll navigate back and forth.
I can't exclude windowload because people may use either URL to enter the site (mysite.com or mystie.com/home)
Anyone can help me with this?
I suggest to create 1 page view tag instead of 2 and use both triggers. Multiple triggers in GTM tag work with OR operator. And set tag to fire once per page.
Advanced settings -> Tag firing options -> Once per page
UPD I'm afraid that in this case other hits for virtual pages triggered by History change will not be fired (because of 1 per page rule). Try to check what value have variable Old History Change after redirection. If undefined or empty, you can use it in trigger of History Change tag as exclusion.

Google Tag Manager and Single Page apps

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?
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.
You definitely need to push events into the dataLayer which you can then trigger a GA page view tag in GTM. So to push an event into the DL:
dataLayer.push({'event':'virtualPageView'});
Then setup a trigger called 'vpv' which fires on a custom event called 'virtualPageView'. Add that trigger to a GA tag.
The best thing to do is also send through the details of the virtual page when you send the event. This way you can set up variables that pull these dataLayer property values into the page view call. So you might do this:
dataLayer.push({
'event':'virtualPageView',
'page':{
'title':'contact us',
'url':'/contact'
}
});
So you'd setup a variable called 'DL- page title' (for example) which is a dataLayer value of 'page.title' and another variable called 'DL - page url' which is a dataLayer value of 'page.url'.
You then setup a new Universal Analytics tag which has all your usual pageview settings but with 2 'Fields to Set' (under More Settings). Set 'title' to {{DL-page title}} and 'page' to {{DL - page url}}
Finally set the trigger to 'vpv' and you'll find everytime you push the event + data into the datalayer you'll get a pageView fired off with your virtual page's title and virtual url.

Resources