track a redirect page with google analytics

2019-02-22 16:22发布

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?

2条回答
【Aperson】
2楼-- · 2019-02-22 17:00

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.

查看更多
等我变得足够好
3楼-- · 2019-02-22 17:08

You need to add your Analytics code BEFORE the redirect.

查看更多
登录 后发表回答