Thanks for this thread - I just did this on our forum. The Google code has changed a little bit:
PHP Code:
$output .= '<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-XXXXXXX-1");
pageTracker._trackPageview();
} catch(err) {}</script>
';
The key to getting it to work as a plugin is:
--Add this first:
--Paste your Google code
--Add this at the end:
--Go through the pasted Google code and anywhere there is a single quote (') escape it with a backslash (\'), LEAVING the first and last single quotes you added above. You can find 4 places in the code I put above, and there should always be an even number!