Search code examples
google-analyticsevent-tracking

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


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


Solution

  • 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).