开发者

Sending data to the Google Analytics platform - in a pure PHP page?

开发者 https://www.devze.com 2023-04-11 13:56 出处:网络
I\'m building an application, and I\'d like to incorporate some stat tracking for each of the pages created. However, these pages are simply redirect pages using header() to different places, dependin

I'm building an application, and I'd like to incorporate some stat tracking for each of the pages created. However, these pages are simply redirect pages using header() to different places, depending on what conditions have been met.

Rather then build my own stat tracking platform and incorporate it within PHP, I'd rather send t开发者_如何转开发raffic data to the Google Analytics platform. However, as the page exits via a header() alteration, I cannot print the normal Javascript code.

Is there anyway I can still have the page and query string traffic data sent to Google Analytics without using the standard script?


User's browser must make a request to Google's 1-pixel "tracking gif". There is google's solution for mobile web sites, where Javascript is not available. You can see it in the tracking code section of your google analytics settings pages. It is written for PHP. However, this pure-PHP solution just inserts <img> tag into the output. It won't work for you, since you're just making a redirect with HTTP headers.

So, there could be two solutions:

  1. Make the redirect via META tag. Thus, you'll be able to track the redirect with either Javascript or PHP-based analytics code.

  2. Try to fetch that 1x1 GIF from google server-side. However, this will screw lots of things in your Analytics. E.g. originating IP will be wrong, so all demographics will be wrong, you won't be able to pass cookies, etc. It will be most rudimentary tracking at best.


There's an official Google's PHP class "Server-Side Google Analytics PHP Client"

https://code.google.com/p/php-ga/

0

精彩评论

暂无评论...
验证码 换一张
取 消