Google Analytics configured with GTM showing two pageviews. But when I check GTM assistant it only shows one - google-analytics

I have configured Google Analytics using GTM in my single-page application build in next.js. In order to check the pageviews I push a custom event to the data layer called "pageview" each time a user change to a new page.
In GTM I have created a trigger that looks for the "pageview" custom event and fires up the google-analytics tag.
Everything seems to be working properly but when I enter the debugview of google analytics and I change from one page to another 2 paweviews are recorded instead of one.
I have check GTM assistant and the tag is not firing twice, so I do not know where the problem might be.
This is messing my stats as I have twice more pageviews than in reality.
Here in the photos i upload you can see the tag. In the history and message no tags are getting fired
While this is what happens in google analytics (both page_views contain the exact same parameters (same page_refererr, page_location...):
Here is the implementation insine next.js. Basically I call the function GTMPageView() each time a route is change. GTMPageView() is the function that pushes "pageview" into the datalayer
I really appreciate any kind of help as I have been hours trying to solve the problem and I cant get to the end of it.

Related

What is difference between Page Views and Event type in Google Tag Manager and where "some page views" are stored in Google Analytics?

I am kinda new in this topic and wondering what is the difference between Page Views and Event data type in Google Tag Manager. I would like to create an e-commerce funnel. I have configured tags for every steps in GTM and they work properly in preview mode. But I can't find them in Google Analytics. I've been creating tags with pageview -> some page views tags. Where this type of tags are stored in Google Analytics? Should I change it to event data type? And in which case could we need some pageviews tags otherwise?
GTM and GA are two different systems, that unfortunately use the same words for rather different things.
GTM is a deployment system for Javascript tags. In GTM Parlance, an "event" is something that makes GTM update its internal variables and allows for triggering tags. GTM events manifest themselves as a key with the name "event" in the datalayer (GTM overwrites the "push" method of the datalayer array to detect the "event" key when it is contained in an object that is pushed to the datalayer). A pageview in GTM is just one type of event that happens when the GTM code is first executed. By itself it does not send data anywhere and nothing is stored. Data is sent only by the tags that are configured to be triggered by an event.
GA is a system that records tracking data. Tracking data is sent as "hits", where a hit is a http request with a payload that is formatted according to a certain protocol (the measurement protocol, which can be used in any language that supports http requests, and is also used by the analytics.js library). Hits come in different types (pageview, event, timing, and possibly others). The difference is not so much technical (its all http requests), is that the different hit types are by convention tied to different "dimensions", i.e. descriptive properties of the hit. A "page view" hit has a document location and document title. An "event" in GA has additionally the dimensions "event category", "event action" and "event label". That distinction made sense when GA was created, because back then a "page view" was more or less well defined by browser behaviour, but today with ajax and SPAs and all that it becomes more an more meaningless, which is why GA4, the new version of Google Analytics, now only has one hit type - the event, to which you can add dimensions by way of parameters.
So a page view in GTM maybe configured to send a page view in Google Analytics, but does not have to be; the two things have the same name, but exists independently. If a GTM event is not recorded, then it probably has not GA tag connected to it via a trigger. GTM events by themselves do not store data anywhere.
As for the funnel, in Universal Analytics you would create this by implementing enhanced e-commerce. Enhanced E-Commerce can be implemented both via pageviews or via events (that mostly depends on how your page is structured - if you have a checkout with multiple pages you might want to use page views, if everything happens on one page you would rather use events). The important thing is that the appropriate dimensions and metrics are attached to the hit. In GTM the easiest way to this is to have your developers set up the datalayer structure according to the linked documentation, and then you simply check the "enhanced e-commerce" feature in you GA tag and point it to the e-commerce variable in your datalayer (instructions are in the documentation, if you expand the "See the Tag Configuration for this Example" sections by clicking on them).

Google Analytics not generating data

I'm new to Google Analytics. Yesterday, I created an account and I pointed it to our website. I've added the JavaScript codes that Google Analytics generated for us. I put the code on all of our .html files.
I've been hitting our website from outside and so does my officemates since last night and also today. However, when I visited https://www.google.com/analytics under Reporting, everything was showing 0. I don't see any single spike at all.
I would recommend navigating to the Reporting -> Realtime -> Overview tab within your Google Analytics (GA) account. This is an almost realtime view into users on your site. In a separate tab access your site and refresh the page, this page view event should then be visible in the GA Realtime view.
If you can see your page view then its likely that you've inserted the correct GA script into your page and that you've used the correct GA property id. If you cant see your own page view then you will know that your script is incorrectly inserted or your GA property id is incorrect.
Last bit of advice: GA often has a 24-48 delay before you are able to use its full suite of insight tools (such as GA Goals). If you're expecting to see Goals populate immediately you're gonna have a bad time.
Last-last bit of advice: make sure that you select the current date from the date range picker in the top right of the GA Reporting view. It defaults to yesterday.

Event Tracking UA + Upgrading to Google Tag Manager

I've got a website where every button has an onclick parameter based [on this article]https://developers.google.com/analytics/devguides/collection/analyticsjs/events. This works fine with universal analytics. But I wonder if it also works with Google Tag Manager without any adjustments. Am I fine or do I need to change code on site to get this? If I do need to change, where should I start, couldn't find any resources
If you use GTM for event tracking, you would need to remove event tracking code on your site because this will result in double-tracking and inflated analytics data. What you can do is to tag everything you want tagged in GTM, but DO NOT publish your container and tags just yet - just work in debug mode so that you can see if/when your tags are firing. Then once everything is working in GTM debug mode, you can then remove your event tracking code and publish your container. Alternatively, if you wanted to just leave the event tracking code in your site and use GTM concurrently, then you would have to make sure you don't tag those events that are already being tracked, but really this isn't ideal and defeats the purpose of GTM.

using web page variable for google analytics

I am very much new to google analytics. I have a page level variable will have either zero or greater than 0. If it is zero then different db query will be executed and if it is greater than zero different db query will be executed on the same page which does not have any java script. Is it possible to get these actions in google analytics.
Please help me.
you need to place the Google Analytics (Java script) code in the head of the HTML document. once you do that, you can track these actions by using event tracking. Execute the Event Tracking Function in the database call position.
Event Tracking : https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide

How to use Google Analytics Tag Manager to track off site links

I noticed that Google has released their Tag Manager application making it really easy to make changes to your tags and tracking options. How can I use this tool to track off site links?
Google Tag Manager (GTM) is not a tracking tool, so the short and unhelpful answer is that you can't. However you can deploy Google Analytics via GTM, which I guess is what you mean. I have to say, though, that tracking offsite links turned out a little less straightforward than I expected it to be.
Usually you track external links by virtual pageviews (or events). The usual way in GTM would be to push a variable to the data layer on the click event of the link and then fire a GA tag with a virtual pageview based on a rule based on that event. This failed completely for me when I tested it, presumably because the new page had loaded before the GA tag could fire. So I resorted to a not very elegant workaround:
First I created a standard Google Analytics Tag (tracking type pageview) to make sure the GA code was included in the site. Then I created a custom HMTL Tag with a bit of Javascript (this is assuming you use jQuery in your page):
<script>
$('a').click(function() {
var p = $(this).attr('href');
if (p.search(/.+YOUDOMAIN/) == -1){
_gaq.push(['_trackPageview', "external://" + p]); // mark links as external in the GA interface
}
});
</script>
For all links that do not contain YOURDOMAIN a click event with a pageview is attached to the link. To make sure the all the links are tagged with the click event you set a rule in the tag manager to make sure the script is executed only after the page has loaded you set event based rule in the tag manager where the event is equal to gtm.load (gtm's equivalent of jQuerys domReady).
This works (at least it did in my tests), but since it does not use GTMs intermediary dataLayer it looks rather like a hack to me. If anybody can suggest a proper solution I'd be grateful.

Resources