We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,011 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Is it ok to include google analytics to all pages from single php file?

Hello,

I just revamped a website and rather experimented including absolutely all <head > contents within a single .php file, including google analytics.

But I am a little confused now reading the analytics for my website and I wonder if google analytics, being fed to all the pages from a common php file, is still able to recognize the different pages of the website.

Is it? or should I paste the block of analytics code inside every webpage instead of feeding it from a php file?

Sorry for some people this question looks like it insists upon itself, but other times people ask me to be "more specific".

Thank you for your help!

2
Contributors
2
Replies
8 Hours
Discussion Span
1 Year Ago
Last Updated
3
Views
Question
Answered
manchurianCEO
Junior Poster in Training
66 posts since Apr 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

PHP is server-side code.
You can write your client-side javascript google analytics code in to PHP file and print to the browser(client-side):

analytics.php

<?php echo '<script>google analytics code here</script>'; ?>

page.php

<html>
<head>
</head>
<body>
<!-- YOUR HTML code here -->
<?php require_once 'analytics.php'; ?>
</body>
</html>

Note: the place of google analytics javascript must be before </body>, to emulate window.onLoad() functionality

eXpertPHP
Newbie Poster
20 posts since Aug 2011
Reputation Points: 10
Solved Threads: 7
Skill Endorsements: 0

Awesome, thank you!!!

manchurianCEO
Junior Poster in Training
66 posts since Apr 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
Question Answered as of 1 Year Ago by eXpertPHP

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0580 seconds using 2.69MB