0

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
3
Views
6 Years
Discussion Span
Last Post by manchurianCEO
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

Edited by eXpertPHP: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.