Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
48
rated 0 times [  50] [ 2]  / answers: 1 / hits: 24144  / 10 Years ago, fri, december 12, 2014, 12:00:00

I have a website where I want to track who has clicked on specific links with GA.



Let's say I have this page: /index.php?id=32



On this page I run some query based on the ID variable (in this case: 32), and I get the URL of the 32 id item from the Database to redirect the visitor.



I'm using a PHP function: header('Location: http://www.example.com');. Before I'm redirecting the user, I want Google to capture the visitor's information and only then redirect to the desired webpage.



I have tried to paste the GA code and ECHO it just before the redirection, however it did not work. How is it possible to track these kind of pages with GA?


More From » php

 Answers
23

Generally speaking




If your page uses redirects, the redirecting page becomes the
landing page's referrer. For example, if you've changed your site so
that index.html now redirects to home.html, then index.html becomes
the referrer for home.html. If someone reached your site via a Google
search that sent them first to index.html, you won't have any data
regarding the Google search.



For this reason, you should place the Google Analytics tracking
code on the redirecting page as well as on the landing page. This way,
the redirecting page will capture the actual referrer information for
your reports.



Note, some browsers may actually redirect before the JavaScript
call from the code can be made.




(cf. https://support.google.com/analytics/answer/1009614?hl=en)



Your specific case



Since PHP is rendered and executed before any Javascript, Google Analytics tracker has no chance to send data to its server.






Solutions



Considering that you cannot track a PHP redirection page, there are a number of possible alternatives:



















  • Campaign tracking (I wouldn't personally use this method in this specific case.)


    • /products.php?utm_source=index&utm_medium=redirection-page&utm_campaign=32





The last two items in the list are implemented on the individual links on the initial page before you get on the PHP redirection page.


[#68498] Wednesday, December 10, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
grant

Total Points: 169
Total Questions: 96
Total Answers: 98

Location: Cape Verde
Member since Sat, Apr 24, 2021
3 Years ago
;