2

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 traffic 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?

asked Oct 5, 2011 at 18:32

2 Answers 2

2

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.

answered Oct 5, 2011 at 18:41
Sign up to request clarification or add additional context in comments.

Comments

0

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

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

answered Aug 17, 2013 at 10:51

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.