Analytics
4.7K members online now
4.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

Inserting code into a PHP site

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I am working with a php site. The instructions for installing Google Analytics are to make a php file for the code snippet then install the link to the file on all the pages I want to track at the opening body tag. My body tag is in the header, and the header is the same through the whole site. Do I really just need to install the <?php include_once("analyticstracking.php") ?> once in the header and that is it?

 

Thanks!

Re: Inserting code into a PHP site

Participant ✭ ✭ ✭
# 2
Participant ✭ ✭ ✭
Hi Erin,
I don't understand that <body> tag is in the header. For PHP site you need to place tracking code on analyticstracking.php and you need to place <?php include_once("analyticstracking.php") ?> within <head> </head> tag.

Hope this helps.
Thanks

Re: Inserting code into a PHP site

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
I should have been more clear. The body tag is in the header.php file. And that header.php file is the header for the entire website. There are different files for different pages of the website but those different pages all use the same header, and therefore use the same opening body tag. So I really only inserted once in my whole website. Is that the right way to do it for a php site?

Re: Inserting code into a PHP site

Follower ✭ ☆ ☆
# 4
Follower ✭ ☆ ☆
Hi Erin:
Yes - if you place the Google Tracking code just above the closing </head> tag in your header.php file your tracking will work as expected.
As you said, no need to create a new file since your header.php file is placed on every page of your website.
Best,
Jay