I am trying to let authors on my site retrieve their own Google analytics data by setting up a channel in Analytics and submitting it via their profile. I ahve been trying plenty of ways to do this, but here is what I have so far.
window.google_analytics_uacct = “UA-xxxxxxx-xx”;
<script type="text/javascript">//<![CDATA[
var _gaq = _gaq || [];
_gaq.push(['_setAccount','UA-xxxxxxx-xx']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setAccount', 'UA-xxxxxxx-xx']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
//]]></script>
I was trying to incorporate the following PHP around the second account data is pushed to.
<?php if ( get_the_author_meta( 'analytics' ) ) { ?>
<?php the_author_meta( 'analytics' ); ?>
<?php } ?>
I was using the if statement around the second set of
_gaq.push(['_setAccount', 'UA-xxxxxxx-xx']);
_gaq.push(['_trackPageview']);
With the view of only displaying this set if the site author has submitted their Analytics ID.
Unfortunately just getting the value from the database in itself is causing me a lot of problems! Any help would be appreciated 🙂
Kind Regards
Oli
-Try this one. Author meta ‘analytics’ must be like UA-1234567-12