when and how does Google Anayltics send tracking requests - google-analytics

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.

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:

Users not being tracked in Google Analytics 4 using Google Tag Manager Server

I am trying to send event data to Google Analytics 4 through a Google Tag Manager Server container. This setup will later be used to track an app for which we will not be using the Google SDK. However whatever I try, I can't seem to record users within GA4, even though the events are recorded.
Currently, I send an HTTP POST request from Postman to our Google Tag Manager Server container, which is captured by a custom Client and is processed by the official GA4 tag. Within the GA4 tag, I map the original event data to the event data needed by GA4. The request that is sent is shown below:
Also, GTM shows a 204 response code.
When the GA4 tag sends the request to GA4, I do see the event coming in, but no user is recorded:
Which parameters am I missing that are required?
(Yes, I know that there are dedicated App streams within GA4, but you have to connect your account to Firebase, which is exactly what we do not want for our setup. Therefore, I set up a web stream.)

Is analytics.js being pulled in twice?

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.

Google Tag Manager - firing events from rest api

Some of my events are getting fired from frontend for both google analytics and facebook pixel and they are getting captured properly through GTM.
but now i have a functionality which is getting done from cron and is served from backend. I need to capture a event in both google analytics and facebook pixel when this is getting captured.
We need to fire the https (rest based) calls for capturing this.
Kindly help on this how this can be achieved.
Update: While this was correct at the time of writing, Google has since introduced server-side tagging via GTM, which conceivably can be used for server-to-server communication.
--
GTM has no serverside API to trigger tracking calls (the GTM API is for managing tags that will be wrapped into a Javascript function. There is no tracking backend to do calls against).
You need to send your calls directly to GA via the measurement protocol or respectively to Facebook via offline conversions.
Yes you can.
create an event listener on button click to connect to the API to collect the data
then with an event push the data you want to a Datalayer
and then use it as you wish.

History.js and Google Analytics virtual pageviews page titles

I'm using Google Analytics to track virtual pageviews when pushState() is executed via by History.js. Things are reporting fine, but there seems to be an error in the ordering of things.
document.title is changing after the URL changes and the pageview fires, so the information sent is not consistent. It appears with an accurate URL, but contains the title of the last page.
If I delay the pageview to be sent by 100 milliseconds, I get the correct info, but would like to avoid doing this in the future.
Any ideas?
You need to be updating the page title in addition to the URL as you're navigating throughout the site.
The Single Page Application Tracking developer guide goes through exactly how to properly track pages loaded via AJAX using Google Analytics.

Resources