Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I call google analytics from server side?

I have a web application on it google analytics, doing call on events for example when the user logs in:

 _gaq.push(['_trackEvent', 'webapp', 'account', 'login', , false]);

I have the same web app as a desktop app (one that is on my clients desktops).If user do login from the desktop app it sends request to my web app with params to tell a login was made. so let's say when a user logs in in the desktop app it's sending request to "http://mywebapp.com/?UserID=[userid]&op=login" ,the webapp save the data, and I want it to call google analytics with,

_gaq.push(['_trackEvent', 'desktopapp', 'account', 'login', , false]);

is it possible ? my webapp is MVC 4 C#.

like image 423
Haddar Macdasi Avatar asked May 26 '13 15:05

Haddar Macdasi


People also ask

Is Google Analytics server side or client side?

The Google Analytics Platform lets you measure user interactions with your business across various devices and environments. Google Analytics provides the resources to collect, store, process, and report on these user-interactions. You can collect analytics on the client side and on the server side.

Is GTM client side or server side?

Using GTM: You can use regular GTM on the client-side to send data. Using Gtag. js: You can also use Gtag. js to send data to a server-side container.

Is Google Tag Manager server side?

Server-side tagging is a new way to use Google Tag Manager to instrument your application across devices. Server containers use the same tag, trigger, and variable model that you're used to, while also providing new tools that allow you to measure user activity wherever it happens.

Can I send event data from backend to Google Analytics?

It allows businesses to send data and events from their servers back to the ads' servers. Google Analytics Measurement Protocol is one of the solutions that allow advertisers to overcome those restrictions and collect the data in the backend and send it directly from the server to Google Analytics Servers via the API.


1 Answers

Absolutely yes. Your server just needs to form a proper URL string for Google Analytics, such as e.g.:

http://www.google-analytics.com/__utm.gif?utmwv=4.4sj&utmn=2013699399&utmhn=localhost&utmr=-&utmp=%2Fwebapp&utmac=XX-999999-99&utmcc=__utma%3D999.999.999.999.999.1%3B&utmvid=0x10ccd599999999&utmip=

(you need to check and change some of the request parameters to something sensible - read more of the parameters here).

Then open the URL from your server code. In Java you could do it like:

URL url = new URL(urlAsString);
URLConnection connection = url.openConnection();
connection.setUseCaches(false);

connection.addRequestProperty("User-Agent", "MyBrowser/1.0 MyEngine/1.0");
connection.addRequestProperty("Accept-Language", "en-US");

connection.getContent();

This is a similar question: How to trigger Google Analytics from code? for C#.

UPDATE 18 Jul 2014

With the launch of Universal Analytics it's now easier to do server side analytics integration - see the following post here on SA for details: Is there any way to post events to Google Analytics via server-side API?

like image 137
tbsalling Avatar answered Oct 12 '22 17:10

tbsalling