Google Analytics & PHP

cstamper

New Member
Messages
126
Reaction score
0
Points
0
I'm trying to get the legacy Google Analytics tracking code into my PHP webpage. Fwiw, I'm using pluck-cms.

The code is supposed to look like this (HTML):


<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-thisismycode";
urchinTracker();
</script>

So my PHP looks like this:

echo "<script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\">";
echo "</script>";
echo "<script type=\"text/javascript">";
echo "_uacct = \"UA-thisismycode";";
echo "urchinTracker();"
echo "</script>";

Which works, until it reaches this line:

echo "_uacct = \"UA-thisismycode";";

It gives this error when I load the page in a browser:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in ---------- on line (that line)

I think it has something to do with the";

Any ideas?
 

oracle

New Member
Messages
430
Reaction score
0
Points
0
Better have ur google analytics code stored in a seperate file, named googlecode.php and then in the mail file where u want to insert it just do:

<?php include_once("googlecode.php") ?>

and you are done :)

PS: Just put the javascript code of google as it is in the .php file, without <?php and ?> tags
 

cstamper

New Member
Messages
126
Reaction score
0
Points
0
So in the goog.php file, it should have ONLY the HTMLode that google analytics gives me? And the php echo's written just like I wrote them?

Thanks a lot!
 
Last edited:

lucybellfan

New Member
Messages
9
Reaction score
0
Points
0
why don't you try not parsing that part of the code. I mean just close the php and then open it again.



(your php code)
?>

<script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\">
</script>
<script type=\"text/javascript">
_uacct = \"UA-thisismycode";
urchinTracker();
</script>

<?php
(and continue your php code till it finishes...)


Hope it works.
 

StephenCronin

New Member
Messages
6
Reaction score
0
Points
0
You're missing a backslash to escape the quotemark.

Try changing:

Code:
echo "_uacct = \"UA-thisismycode";";

to:

Code:
echo "_uacct = \"UA-thisismycode\";";

Note the extra backslash. That should fix it for you.
 
Top