AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
1.7K members online now
1.7K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Google analytics code on header.php page

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello All,

  

   I want to add Google analytics code to my website. As my website has lot of pages, I could add the code in header.php page and have called the function on each pages. Is it right method or should I add the code separately on each pages? Please advice me.

 

Thanks,

Surya

1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Surya s
August 2016

Re: Google analytics code on header.php page

Participant ✭ ✭ ✭
# 2
Participant ✭ ✭ ✭
Hi Surya,
You don't need to add tracking code on each page separately. Please follow below instruction.

Copy the Javascript tracking code snippet and add it to a file named analyticstracking.php or with any other name. Then include the analyticstracking.php file on each PHP template page. For each template page, immediately after the opening <body> tag, add the following code:
<?php include_once("analyticstracking.php") ?>

Hope this helps.

Thanks

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Surya s
August 2016

Re: Google analytics code on header.php page

Participant ✭ ✭ ✭
# 2
Participant ✭ ✭ ✭
Hi Surya,
You don't need to add tracking code on each page separately. Please follow below instruction.

Copy the Javascript tracking code snippet and add it to a file named analyticstracking.php or with any other name. Then include the analyticstracking.php file on each PHP template page. For each template page, immediately after the opening <body> tag, add the following code:
<?php include_once("analyticstracking.php") ?>

Hope this helps.

Thanks

Re: Google analytics code on header.php page

A T
Participant ✭ ✭ ✭
# 3
A T
Participant ✭ ✭ ✭
Adding it in header.php makes more sense.

Just make sure it is reflected on all pages of the website.