How to track with Google Analytics on a redirection page with PHP

0 votes

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?

Jul 7, 2020 in Web Development by kartik
• 37,520 points
1,863 views

1 answer to this question.

0 votes

Hello @kartik,

Since the page that is sending visitors to the redirect is also under your control, I would suggest a totally different approach: use event tracking on the source page.

On the page that has the /index.php?id=32 link, measure all clicks on this link by attaching an onClick handler to the link and executing something like

ga('send', 'event', {
  eventCategory: 'Redirect Link',
  eventAction: 'click',
  eventLabel: event.target.href
});

Hope it helps!!

Thank You!!

answered Jul 7, 2020 by Niroj
• 82,840 points

Related Questions In Web Development

0 votes
1 answer
+1 vote
2 answers

How to embed Google map on my website?

1. Search whatever you want to embed. 2. ...READ MORE

answered Jan 17, 2020 in Web Development by anonymous
1,238 views
0 votes
1 answer

How to hide a div with jQuery?

We hide the divs by adding a CSS ...READ MORE

answered Jun 27, 2022 in Web Development by rajatha
• 7,680 points
438 views
0 votes
0 answers

How to scroll to top of page with JavaScript/jQuery?

Is there a way to control browser ...READ MORE

Jul 1, 2022 in Web Development by gaurav
• 23,260 points
2,276 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,068 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
3,016 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,944 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,871 views
+1 vote
1 answer

How to access the Angularjs scope of a particular html element from our console?

Hello, You should follow the below steps:-- 1.Compile and ...READ MORE

answered Jan 21, 2020 in Web Development by Niroj
• 82,840 points

edited Jan 21, 2020 by Niroj 3,021 views
0 votes
1 answer

How to Return JSON from PHP to JavaScript?

Hello @kartik, Php has an inbuilt JSON Serialising ...READ MORE

answered Jul 6, 2020 in Web Development by Niroj
• 82,840 points
1,669 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP