Using Google Analytics from backend

Bogdan Gusiev picture Bogdan Gusiev · Aug 3, 2012 · Viewed 17.5k times · Source

There is some custom google analytics events I've specified for my application. Trigering these events is sometimes not very easy.

For example: User is redirected to home page after purchase and I have to forward some data that this home page is displayed after purchase to push something to _gaq based on that.

Is there any way to trigger google analytics from backend e.g. in a controller without taking care if the action is ajax request or plain request and response has redirect or Ok status?

Answer

Filippo Vitale picture Filippo Vitale · Nov 15, 2012

To trigger Google Analytics from the backend you should use: Measurement Protocol.

That is part of the Analytics Collection:

Web Tracking (ga.js) Measure user interaction with websites or web applications.

Android Measure user interaction with Android applications.

iOS Measure user interaction with iOS applications.

Measurement Protocol Measure user interaction in any environment with this low-level protocol.

At the moment it is available as dev preview. To signing up simply request access to the beta.