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!

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

Awesome, thank you!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.