Is analytics.js being pulled in twice? - google-analytics

I enter a legacy codebase that has their analytics setup already. I am a bit new to Google Analytics but in our codebase, analytics events are pushed into a data_layerarray on the window and Google Tag Manager (GTM) consume it at some point. I notice that on my network tag (and when running the GA debugger tool) it appears analytics.js is called and initialized twice. One from gtm.js where we initialized somewhere in our codebase but the other initiator is from https://www.google-analytics.com/analytics.js. I look all over the codebase and it doesn't appear this link is called anywhere and when I view the page as a rendered page, I do see two script tag calling for this script.
Is this normal or am I definitely missing a init function somewhere?

This is normal when your website is HTTP not HTTPS. You can see the first call has a 307 status code which is for temp-redirect from HTTP to HTTPS. It is not being loaded twice.
GTM.js loads analytics.js and that is normal.

Related

how can I validate if good analytics is counting review with ajax request

I have installed the google analytics in our e-commerce site using google tag manager. From the product detail page you can click on the colors to see the same product in the different colors. I implemented this using ajax so the page load is not required. I was curious if the google analytics will count as multiple reviews a user clicks on the different colors or do I need to explicitly call something in order for the GA to count as multiple reviews.
First of all, that depends how and what kind of GA you've implemented.
To implement analytics, you have to specify a trigger for the analytics tag. That trigger normally determines if a tag is fired or not.
If you used a page load trigger, then the tag will only be triggered on the real page load. And it won't be triggered on your ajax manipulations.
With only one exception: if you used the GA4 config tag, you had this checkbox there:
The checkbox doesn't only send the pageview on config load, it keeps sending pageviews on every history change. Therefore, if your ajax causes history change and you use the GA4 config tag, then you're getting pageviews.
But this is theory. You can just go and check. Open your network tab, filter the request by collect and see what's sent when. Or alternatively, install the adswerve datalayer debugger and it will log whatever is sent whenever it's sent into the console in a very neat, clean way. This is how it works on this page:

Hotjar & Google Tag Manager (GTM) with virtual page views

I have set up our Google Tag Manager (GTM) account so it sends virtual page views to Google Analytics (GA). This boiles down to pushing a custom event on the dataLayer (= GTM) array which will then trigger sending a pageview to GA. This works fine.
The same GTM account also has Hotjar connected to it, and I'm searching to send the virtual page view also to Hotjar. However, I can't seem to find any documentation about this. Hotjar does support it, but they only talk about doing it via their own "hj" function, and I'd rather do it via GTM.
Based on their official documentation they saying that Hotjar will track page views automatically if you changing URLs in your single page application.
If you SPA changing only fragments, then you need to use this setting "Track changes automatically, including fragments"
If you want to send analogue of "virtual page view" to Hotjar, then you should execute in your GTM:
hj('stateChange', 'some/relative/path');
You should be able to use hj and function should be already defined when GTM is triggering tag.
If you want detailed answer specific to your website, it will be better to share the link to website and the way how you currently configured GTM to track virtual page views

Force SSL on Google Analytics analytics.js load via Google Tag Manager

We load Google Analytics (Universal) via Google Tag Manager and I can't find any way to force it to load the analytics.js script itself over SSL; we set forceSSL via the fields to set options, but by the time it applies that it has already loaded the initial script over plain HTTP.
It looks like GTM checks whether it's on an HTTPS URL and then loads GA over HTTP if so, but I'd prefer to force it over HTTPS instead. Is there any way to do this?
Unfortunately, looking at the documentation available at the very bottom paragraph of Google Tag Manager - Dev Guide - Security, it reads:
While most of the tag templates in Google Tag Manager are also
protocol relative, it's important to make sure that, when setting up
custom tags to fire on secure pages, those tags are also either
protocol relative or secure.
I flipped through a GTM profile to see if there were any configuration options exposed, but I didn't see any either. To your statement about using forceSSL, that wouldn't do anything (as you found) because it's setting a configuration in the already-loaded GA script to use for sending the future requests (e.g. pageview and events).
So, I loaded up a page with GTM installed on it with GA and took a look through the logic until I found where Google Analytics is loaded up from. If you'll take a look, we've got a function that's essentially determining whether to load GA up from either HTTP or HTTPS depending on the value of location.protocol as in the below screenshot:
That means that unless you load up the GA tag via a Custom HTML tag, you're not going to be able to change it to explicitly only load from HTTPS. You mention you're considering just hosting GA directly on the page - you're going to be pasting the exact same snippet there as you would in this Custom HTML tag (ensure that it's surrounded by tags or it won't do anything), and if you're already using GTM for something else, there's little reason to leave your vendor logic in multiple places.
So, in a long answer, no, you can't specify that you want to only load Google Analytics via SSL without resorting to using a Custom HTML tag (and then you unfortunately lose a lot of the mapping simplicity of using the GA tag itself).

Google Tag Manager + Analytics doesn't seem to be working

I recently set up Tag Manager and Google Analytics.
In Google Analytics
I set up an account
In Tag Manager
I pasted the Tag Manager script just under the body tag of all my pages
I set up a container
I added the "Universal Analytics" tag
I copied my Google Analytics tracking ID "UA-...." to the tag
I added the "All pages" rule to the tag
I published the tag
When I hit one of my web pages, I see
- a call to googletagmanager.com/gtm.js?id=GTM-... (with my tag ID)
- a call to google-analytics.com/analytics.js
- a call to google-analytics.com/collect?...tid=UI-...&tgm=GTM-... (with both my tag and analytics ID)
Now when I go to the Google Analytics dashboard, I see no sessions, not even in the Real-Time session dashboard.
Under Admin > Property > Tracking Info > Tracking Code, it says "Status: Tracking Not Installed" I assume this is ok since I didn't copy the Analytics script to my page, but the Tag Manager script instead.
Is there some delay, or am I setting it up wrong?
I recommend every time you sent up GTM with a analytics tracking tag that you check that it sends data. This can be done by looking at the developer tools with chrome or firefox. Really any web browser.
In your web browser open up developer tools and open network. Find the filter button a and search for "UA-".
If you see something that says pageview, scroll down the headers and you will see your UA Account number and if you used GTM to implement the tag you should see your GTM tag ID.
Reload the page and check again. If you see it means it is sending data to the correct property. If it is not then there is something wrong with your implementation.
If you set everything up correctly and still dont see data check your filters. I always recommend keeping one view unfiltered.

when and how does Google Anayltics send tracking requests

I am NOT having problems tracking my page views or events.
I simple do not see any http requests in the NET tab of Chrome Tool or Firebug.
Do they use a different protocal? Is everything just send onunload?
When and where does Google Anayltics send tracking requests?
Their Javascript reads the cookies, then requests a GIF during the request, where they pass the parameters back to their system for tracking. When you look in Firebug, look at either ALL or Images. You should see a GIF that's been transfered from Google Analytics in your history. When they request the GIF they're also passing a long string of GET vars to the URL. They should also be providing you with a tracking cookie. Which is also set with the Javascript.
Here's more about how Google Analytics works.
How the Tracking Code Works
In general, the Google Analytics Tracking Code (GATC) retrieves web
page data as follows:
1. A browser requests a web page that contains the tracking code.
2. A JavaScript Array named _gaq is created and tracking commands
are pushed onto the array.
3. A <script> element is created and enabled for asynchronous
loading (loading in the background).
4. The ga.js tracking code is fetched, with the appropriate
protocol automatically detected. Once the code is fetched and loaded, the
commands on the _gaq array are executed and the array is transformed
into a tracking object. Subsequent tracking calls are made directly to
Google Analytics.
5. Loads the script element to the DOM.
6. After the tracking code collects data,
the GIF request is sent to the Analytics
database for logging and post-processing.

Resources