Hi,
I would like to setup google analytics on two SharePoint Online site collection only which are:
I have modified the google analytics provided by google to cater for both site collections as follows:
<script type="text/javascript"> function googleAnalytics() { (function (i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m) })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga'); if (location.href == "https://test.sharepoint.com/sites/LIVE") { ga('create', 'UA-00000000-0', 'sharepoint.com'); } else if (location.href == "https://test.sharepoint.com/sites/UAT/Pages/Home.aspx") { ga('create', 'UA-00000000-1', 'sharepoint.com'); } ga('send', 'pageview'); }; if (_spBodyOnLoadFunctionNames.indexOf("googleAnalytics") < 0) { _spBodyOnLoadFunctionNames.push("googleAnalytics"); };</script>
This is working partially, i.e. when I navigate to "https://test.sharepoint.com/LIVE" google's realtime overview pick's me up correctly and the tracking cookie is correctly created and sent. But when I go into "https://test.sharepoint.com/LIVE/Pages/test.aspx" or "https://test.sharepoint.com/LIVE/sub-site1/pages/default.aspx" it no longer works and the tracking cookie is not created/sent which results in google's realtime overview no longer tracking me.
Is there anything that can be addeded to the script to ensure google analytics works on all section (pages/subsites) of "https://test.sharepoint/sites/LIVE" and not just on "https://test.sharepoint.com/LIVE"? (this goes for "https://test.sharepoint.com/UAT/Pages/Home.aspx" also)
Any help will greatly appreciated,
Thanks in advance