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,832 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

+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,191 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
422 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,254 views
0 votes
1 answer

Translating a page with jquery "translator", google translate etc

Why not use Google's Website Translator? They have ...READ MORE

answered Aug 1, 2022 in Web Development by rajatha
• 7,680 points
1,376 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,012 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
2,994 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,918 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,690 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 2,971 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,656 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