Why not just do this:
http://wpmututorials.com/plugins/how-to-hook-into-the-footer/
You really don’t need to be BP-specific or this.
On the author’s plugin page, he says the plugin requires the BP bar, but it really doesn’t; it doesn’t hook into anything.
Here’s the proper way to have written the plugin:
function bp_ga_analytics() {
echo '<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-5834099-9");
pageTracker._trackPageview();
} catch(err) {}</script>';
}
add_action('bp_after_footer', 'bp_ga_analytics');
—
You can also use Andrea’s tutorial as well, the difference between Andrea’s and mine is I’m using the bp_after_footer action, and not the wp_footer action.
bp_after_footer shouldn’t hook into the admin dashboard as well, so this should be safe.
That’s right r-a-y. I tried your solution and it’s works but it’s necesary to escape all apostrophe inside the echo command. I mean:
function bp_ga_analytics() {
echo ‘<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-XXX”);
pageTracker._trackPageview();
} catch(err) {}</script>’;
}
add_action(‘bp_after_footer’, ‘bp_ga_analytics’);
Yes you’re right, netstay… I typed it on the fly and didn’t check for apostrophes!
Thanks!
I get the following code showing on all pages even the admin area:
function bp_ga_analytics() { echo ' '; } add_action('bp_after_footer', 'bp_ga_analytics');
Sandeep didn’t wrap the open and close php tags properly…
Replace whatever is in his PHP file with this:
<?php
/*
Plugin Name: BP Analytics
Description: Do you even need this plugin?
Author: Whatever
Version: 1.0
*/
function bp_ga_analytics() {
?>
<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-XXX");
pageTracker._trackPageview();
} catch(err) {}</script>
<?php
}
add_action('bp_after_footer', 'bp_ga_analytics');
?>
@r-a-y… or anyone else
I modified sandeep’s code as per your instructions and it worked fine BUT… Google Analytics hijacks my pages with their Content Overlay view, even if I’m signed out of Analytics, and covers up the admin bar so I can’t even access the dashboard. (I know, weird). I’ve deleted the file for now.
Any ideas on this one?
Plus, the code only showed in the source of my main site, but not in any member blogs. Know if this or any other similar plugin can be installed site-wide?
I’ve never used GA’s content overlay, so I can’t tell you the specifics.
Try clearing your internet cache / cookies to remove the site overlay setting.
—
Member blogs are a different matter, since the member blogs do not use the BP theme.
You can try modifying this line:
add_action('bp_after_footer', 'bp_ga_analytics');
with:
add_action('wp_footer', 'bp_ga_analytics');
Then put the plugin in /wp-content/mu-plugins/THEGAPLUGINFILE.php to activate Google Analytics on all your WPMU blogs.
Thanks r-a-y! That worked on both accounts (cookies, huh).
I kinda figured the file would have to go in mu-plugins, but hesitated trying anything for fear of really mucking things up
Thanks again! I’m learning… slowly.
I am looking to install GA on the main blog as well as all other sub blogs. Is the above method still the best way to do this? This was posted a few months ago so I wanted to double check. Thanks.
It still applies, @jwack .
Yup, works great across all blogs. Also, when I signed up for GA account it had an option specifically for sub-domains, which generated a slightly different script than the one in the example.
@jwack – That’s why it’s called example code
When viewing on google analytics it give me the stats across all blogs, but it just says /pagename for all the page views etc. Can’t really tell what blog its coming from.
Is there a better way to view stats (doesnt have to be GA)? GA’s documentation says I can use an “advanced filter” to view the full path, but it seems really confusing.