Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to send tracking info to Google Analytics from PHP?

I have a PHP code that will return a image. the link is given to 3rd party. so, i need to keep track where the php request coming from. Because the PHP only return the image, I cannot use the Javascript code for Google analytics. I know that I can get the information from the access.log, but i think I can't dump the access.log to GA for analyzing, right? so, is there a way that I can do in PHP (e.g. sending a CURL ), send somethig to Google Analytics for tracking?

like image 405
murvinlai Avatar asked Jun 11 '10 19:06

murvinlai


People also ask

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

In practice, what GA will do is to issue a HTTP GET for a 1-pixel sized GIF image, in which the GET parameters will contain the information to store in GA servers. If you figure out the format of the GET request, you may be able to store the information you want to. You can use any net monitoring tool or browser plugin of similar functionality (like Firebug, etc) to understand the parameters that are passed to GA servers. These are nowhere to be found in GA documentation, although the architecture of this process is.

In practice, what you're trying to accomplish is the same as enabling GA for a javascript-disabled client. By limiting the information you can provide to GA to the one that the server obtains from browser requests you won't be able to get some detailed info such as the screen resolution, etc. On the bright side, the information that won't be accessible by this method is actually very little (and probably of little significance) and the web is full of resources on using GA for the javascript-impaired that you can use as example, eventually adapting to PHP and to your particular case.

like image 91
Miguel Ventura Avatar answered Oct 02 '22 06:10

Miguel Ventura