| « Resize Admin Textarea plugin | Yahoo Rich Text Editor (plugin) » |
Google Analytics code plugin
Did your Google Analytics code survive your latest upgrade? Is it still there when you changed your skin? No worries anymore. This plugin will inject the Google Analytics code into every page in your blog, even in the Admin section.
When you subscribe to Google Analytics you get a snippet of code that goes at the bottom of the page. At teh moment there is a deprecates snippet and a new one. Of course the plugin uses the new one. This is how it looks:
<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">
var pageTracker = _gat._getTracker("UA-1234567-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
You will need to copy/paste the pageTracker code. Formerly known as _uacct, but the code didn't change. In this code it's UA-1234567-1. You add that to the setting of the plugin:

Link to B2evolution forum post
View the source at Sourceforge.net evocms-plugins
Download at Sourceforge.net evocms-plugins repostiories
Have fun
Trackback address for this post
12 comments

Hey, thanks for creating the plugin. But it doesn't seem to be putting the code in my pages, is there any way of troubleshooting this? I put in the UA_ code, is there a delay or something?

Hm I cannot post code in a comment. Will see to that. Anyway have a look at the sourcecode of your page and there you'll find the Google analytics code block. See the source of this page as a reference.
Good luck

I see the code in my source, but Analytics doen'st recognize it. There seems to be one little difference, a line pageTracker._initData(); that Google doesn't give me for the paste in code. I deleted it but that didn't change Google's idea that the code wasn't there, so I put it back. Any ideas?

Hi Troy,
I remember now Google has two key codes for Analytics, one old and a new version.The key itself is the same though. This plugin uses the new code. Have a look in the Analytics help files if you need to change something in order to be able to work with this new code.
I can assure this code works flawless on this blog.
Good luck

I installed your plugin using latest revision (v 874) located @ sourceforge http://evocms-plugins.svn.sourceforge.net/viewvc/evocms-plugins/google_analytics_plugin/trunk/_google_analytics.plugin.php?view=markup&pathrev=874
I found the output code is not correct. So I debuged the code.
I found problematic line. here is the diff
115c115
< var pageTracker = _gat._getTracker("'. $id .'");
---
> var pageTracker = _gat._getTracker("<?php echo $google_analytics; ?>")
hope this help.

dejavu-cat:
Which line is correct in your above correction?

var pageTracker = _gat._getTracker("'. $id .'");
is the correct one.
I did not notice the comments was break up like that, sorry about that.

Thanks
You can also change the function call to
function get_google_analytics_code($google_analytics)The effect should be the same ;)

Foppe, is this plugin supposed to work with the 1.10.x branch?
I am guessing that it should, as I examined the code and saw that it works by hooking to SkinEndHtmlBody, which is documented in 1.10.
I installed it, but I cannot see anything new in the HTML output after the plugin was installed (even though I can see that it is in the backend, marked as installed, and configured).
I changed the code as suggested by dejavu-cat, but I still don't see any changes.
Can you recommend a troubleshooting strategy? Or will it be easier to simply embed Google's code into the skin's main.php?
Get the original plugin from this page: http://evocms-plugins.svn.sourceforge.net/viewvc/evocms-plugins/google_analytics_plugin/trunk/_google_analytics.plugin.php?view=log&pathrev=874You are looking for revision 674. The bug is from a later date.
If you want to debug simply try one of the hints in this thread. $google_analytics and $id are mixed up in the later versions. That happens when the function get_google_analytics_code() is called.
Good luck

I just realized one thing, having re-read my previous message. I got a bit confused, I wrote SkinEndHtmlBody, then I checked my skin to see if it triggers this event. I discovered that the skin triggers another one: SkinBeginHtmlHead.
The documentation lists this one, but not the one in your code: doc.b2evo.net/v-1-10/plugins/Plugin.html#methodSkinBeginHtmlHead
I edited the code of the plugin:
//function SkinEndHtmlBody()
function SkinBeginHtmlHead()
This still does no yield the desired result.

That should work. I think it's he best if not only hook in 1.10. The code should pop up in the <head> section of every page.
Good luck