5

I am trying to track a redirect page with google analytics:
I have a page called redirect.php; when I visit an url like redirect.php?c=12345678 , a php function does a query on a sql lookup table to decode the code 12345678 with a previously inserted url, then does a 301 redirect.

(I'm doing a 301 redirect to avoid duplicate content.)
I wish to track every single visit to redirect.php with analytics, but I can't.

For example:

redirect.php?c=87654321 redirects to story.php.

Obviously in Analytics I can't find the redirect.php page. the story.php referer is organic/google so I can't rely on the referer.

Is it possible to track every redirect in some ways?

the
  • 21,007
  • 11
  • 68
  • 101
gfabi
  • 96
  • 3
  • 9
  • Looks like the analytics API is smart enough to bypass routing pages like your redirect.php, interesting... Can you try to include a 'home-made' tracking script like analytics to make sure that it's working? – Dax Feb 29 '12 at 21:28
  • @Gianluca Fabrizi - Did you ever come up with a solution for this? If so can you share it? – meder omuraliev May 14 '12 at 22:26
  • @meder - no, not with analytics. You can do it with piwik and it's php api: http://piwik.org/docs/tracking-api/ – gfabi May 20 '12 at 09:42

2 Answers2

7

GA works in the browser. Whenever the user visits a page with the GA script - a request from the user to google is sent notifying about the visit. Since you are making a 301 header redirect - no GA script is loaded and therefore google doesn't know the user has been on that page.

Options you have

  • Switch the redirect from 301 header to a page with meta redirect and the GA code
  • Switch to another analytics system such as Piwik and add data to it manually on the redirect page
  • Implement your own counter inside the redirect script, separated from GA

Of course you could merge the options and have, say a page with meta redirect and the GA code, which redirects to redirect.php script, which in turn redirects with a 301 header, but this is not the best solution.

the
  • 21,007
  • 11
  • 68
  • 101
Alex
  • 11,479
  • 6
  • 28
  • 50
  • I have tried adding a meta redirect to redirect.php: `` GA still doesn't see this page (neither as a referer). I have added a code of another analytics system (javascript code) near the GA code; the new code sees the page redirect.php as a destination page and as a referer too. The problem seems to be with Google... – gfabi Feb 29 '12 at 22:09
  • 1
    That probably happens due to the 0 seconds timeout, while the GA scripts takes more time to load, initialize, take and analyze the data and only then send it to Google. Try increasing the timeout. – Alex Mar 01 '12 at 18:15
  • The counter idea is the cleanest option I've heard so far on this topic. – 3Dom Nov 01 '12 at 02:34
1

You need to add your Analytics code BEFORE the redirect.

Paul Dessert
  • 6,363
  • 8
  • 47
  • 74
  • already done; the analytics code is on top of redirect.php page. – gfabi Feb 29 '12 at 21:22
  • This usually won't work because the headers are already sent: `Warning: Cannot modify header information - headers already sent` – Jerad Jan 23 '14 at 15:02