How can I use Google Analytics without its gtag.js library - google-analytics

I am having some pages where I need to track page views and get data for reports. So I need to use some tracking events without using gtag.js.
I have tried solutions like GIF Request Parameters
But this solution was there in ga.js and its a legacy

The format used in your linked documentation is deprecated since Google introduced Universal Analytics in 2012.
However the current solution to send requests to Googke Analytics without a library, the Measurement Protocol, works broadly the same way. You have an endpoint (google-analytics.com/collect) and add the necessary parameters as described in the reference, depending on what kind of interaction you want to track. The endpoint returns a 200 http status and a gif (no matter if the request has actually been logged in analytics, this just confirms that you actually hit the server).

Related

Is there any API call or any kind of feedback to know whether data is actually sent through google analytics collect endpoint?

I have settled my google tag manager as from the guide.
I have got in place a page that redirect just after the tag gtm-load is collected into the dataLayer. It's actually a "transition" page that should redirect instantaneously.
In this way I make sure google-analytics.com/r/collect is called, as I can see from the network ta of my browser, seems the only way to do so for an "instant redirect page".
However I need to test it from the back-end side.
Is there any way to have a feedback from Google Analytics about the data is actually sent? For example something like google-analytics.com/get/data/lastEntry, so that I can use a restAPI to check it out?
As far as I know, google analytics provide only metrics through a web page, and no actual data sent to.
Moreover there are some Rest API here but they are only for configuration purpose.
you might pass a JavaScript function as a hitCallback parameter of analytics send command and it will be called right after hit data were sent:
https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#hitCallback
Here's an example of how to use it with GTM alongside another useful feature of eventcallback
https://www.simoahava.com/gtm-tips/hitcallback-eventcallback/
Hope this helps.
There is a realtime API in Google Analytics, so what I have done for testing is to call my test URL with utm campaign parameters attached. Then I made a call to the realtime API and filtered by my custom campaign.
The realtime API is fairly limited (no session based values, obviously, you cannot test custom dimensions etc), but at least this tells you if your hit has registered in GA.

Avoiding Google Tag Manager blocking by AdBlockers

I have used Amplitude analytics in the past in my react Web app to send event data. However I just started with Google Tag Manager and noticed it does not run because being blocked by adBlockers. Amplitude was always functional because I loaded their Javascript SDK through NPM install 'github:amplitude/Amplitude-Javascript' and initialized it at app load with client API key. I like the approach of Google Tag manager where I dont have redeploy app to make changes to my analytics logic. How can I take a similar approach to avoiding being blocked by adblockers.
It may very well be that Google products are popular so Adblock specifically just block google analytics products not other analytics products.
You don't. If people don't want to be tracked, that is their decision. You should not be forcing people to provide you with any data they do not want to provide. Especially by using some shady "bypassing" measures. Instead-
You could use a cookie to permanently disable your tracking of those who do not wish to be tracked, to help you preserve reliable analytics. See: http://www.multiminds.eu/2016/05/19/how-to-disable-tracking-via-google-tag-manager/
Or, better yet, simply measure the percentage of visitors who have disabled tracking so your analytical data can remain accurate. See: https://marthijnhoiting.com/detect-if-someone-is-blocking-google-analytics-or-google-tag-manager/
Yes, it's possible.
You can use reverse proxy for Google Tag Manager.
First, download the Google Analytics JavaScript library itself and host it on your server.
Then alter the code in the downloaded library to change the target host from www.google-analytics.com to your own domain name using find-replace.
Replace the link from the default Google Analytics script in your codebase to modified one.
Create a proxy endpoint to Google Analytics servers on your back end. One important step here is to additionally detect the client’s IP address and write it explicitly in requests to Google Analytics servers to preserve correct location detection.
Test the results. You’re done!
more detail info on freecodecamp.org/news/save-your-analytics-from-content-blockers and https://analytics-bypassing-adblockers.netlify.com
There's dataunlocker.com as well as some other open source alternatives (1, 2) which can help to fix reporting accuracy of Google Tag Manager, Amplitude, Google Analytics etc.
Talking about ethics and privacy, tools like DataUnlocker are just tools which allow you to bypass ad blockers as if you have implemented server-side analytics. I think by correctly implementing that "we use cookies" consent one can solve any privacy concerns.
I've managed to get around some blockers with the following in a node app:
var request = require('request');
app.get('/proxy*', function(req,res) {
const newurl = req.url.split('/proxy/')[1];
const data = request(newurl);
//data.on('response', function(response){console.log(JSON.stringify(response))});
data.pipe(res);
});
Then in your snippets for GTM prepend: "/proxy/" in the url and now the call goes via your server.
The caveat with the above is that without additional code you can't preview the container, but the container does load correctly. Lack of preview is a different issue to deal with.

Can Google Analytics distinguish multiples requests using methods such POST, PUT, DELETE on a single URL?

I'm working on a web application that uses node.js + express. Our team has decided that all related pages must use a single URL and be distinguished only by its method.
So, for example: we have a group edition page. GET /groups gets the html, which includes the edition form, and POST /groups saves the changes.
The issue is that I only desire to track the POST /groups request. However, on the Google Analytics configurations, I only found URL-related tracking, nothing about specific HTTP methods.
Can this be done?
If you have implemented GA via the standard client-side tracking code then no, GA will not be aware of the http method (JavaScript has no access to http headers). It should however be trivial to render a Javascript if condition into the code depending on the request method.

How is Google Analytics Measurement Protocol different?

I was checking GA Measurement Protocol to send data to GA from backend.Which is working fine.Url i am using is:
https://www.google-analytics.com/collect?tid=UA-XXXXXXX-1&v=1&cid=9350&dp=home&t=pageview
(Please replace UA-XXXXXXX-1 with your own tracking id.)
Now i have a website which is GA enabled using javascript way.I checked in Chrome inspect that it sends information to google through url:
https://stats.g.doubleclick.net/__utm.gif?utmwv=5.6.5dc&utms=4&utmn=1588741400&............
I can use this url too to send information to google from backend. What's special and new in Measurement Protocol because using this url too i can send data to google for analytics purposes?
I need to send data from backend to GA so please guide.
The measurement protocol is now the "backbone" for data collection for Universal Analytics for all versions (web, mobile etc). Unlike the gif-method it is well documented and it can be called from every device/programming language that can send http requests (it will still return a transparent gif, though).
The main reason for using the measurement protocol is that everything else is deprecated and Google has announced that support for older tracking methods will be dropped. It looks like your second example uses an older version of the Analytics tracking code, current versions send their calls to the https://www.google-analytics.com/collect endpoint. You should not invest a lot of effort in developing solutions based on deprecated technology, especially if it offers no advantages over the current versions.
Google measurement protocol is very useful when implementing distributed solution of a service like restful APIs.
The client is not known by the server, each client world wide can call the rest API so no javascript code is possible to be injected at the client.
Measurement protocol enabled us to track which kind of devices are calling our API, how many requests per endpoint, etc...

What is utmu parameter in google analytics __utm.gif request?

I am trying to make the google analytic __utm.gif request using php. I have broken all the variables and the only one which I don't know about is utmu parameter. It is not documented anywhere.
When I see a pageview tracking request it is appended to the end of request as &utmu=qB~
While doing ecommerce tracking it is appended as &utmu=qBAL~
Please help me with this.
It is a bitmap of all of the methods used to build the request.
Source: http://glucik.blogspot.com/2011/02/utmu-google-analytics-request-parameter.html
utmu doesn't actually contain anything of external meaning. Google uses it to store some internal values that help them improve ga.js. It's not required to make any functionality work, so, your PHP code doesn't need to account for it.
However, you should know there are already a few long-standing PHP-based Google Analytics projects, like Server Side Google Analytics (SSGA), as well as the semi-official Google Analytics for Mobile PHP and PHPGA.

Resources