View Full Version : Google Analytics and .php
mikeumus
May 3rd, 2008, 07:48 AM
Hey guys,
How do I insert the Google Analytics html code into all the pages of my site, if most of them are .php files and do not follow the html format?
Thank you all for your time and consideration and I hope all of your projects are gracefully progressing as well.
Peace and Love,
Mike.
kdd
May 3rd, 2008, 04:16 PM
I don't understand what you mean by your .php files don't follow html format. In any .php file, you can have html stuff, you know? (I don't know how Google Analytics code looks like, otherwise I could help you better).
If it's like a script type of thing, then:
<head>
<script type="text/javascript" src="linkToGoogleAnalytics.js"></script>
</head>
would work. But I'm still not sure what you mean by your .php files don't follow html format.
Syous
May 3rd, 2008, 06:17 PM
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "";
urchinTracker();
</script>
Perhaps?
Stageline
May 4th, 2008, 08:51 PM
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "";
urchinTracker();
</script>
Perhaps?
<?php
$out = '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">';
$out .= '</script>';
$out .= '<script type="text/javascript">';
$out .= '_uacct = "";';
$out .= 'urchinTracker();';
$out .= '</script>';
echo $out;
?>
Not tested.
mikeumus
May 6th, 2008, 10:59 PM
Thanks all of you guys!
I'll test it out and tell you how it went. I am now confiden about it though.
Thanks again.
:D
Esherido
May 7th, 2008, 08:52 AM
<?php
$out = '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">';
$out .= '</script>';
$out .= '<script type="text/javascript">';
$out .= '_uacct = "";';
$out .= 'urchinTracker();';
$out .= '</script>';
echo $out;
?>
Not tested.
Why would you have PHP echo it? Just put it outside the PHP brackets and PHP won't even have to touch it, but you can still run a include/require on that file and it will be loaded. Also, with your method, you don't have any newlines included, so it will be echoed in one continuous line. Which makes for some really ugly HTML code. And echoing the string uses up unnecessary processing power.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.