November Happy Hour will be moved to Thursday December 5th.

Google Analytics plugin manually set domain

Vote:
 

Is it possible to manually set the domain using this plugin?

We require tracking across multiple subdomains, so we need to set the domain to be at a higher level as per google's requirements (https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSite#domainSubDomains).

For example the site is uk.example.com, so we need to set it to example.com so users are tracked across all sites.

There is an option in the admin tool for 'One domain with multiple subdomain' - but this sets the domain to the full host.

#85003
Apr 10, 2014 17:16
Vote:
 

Hi Sam, 

Have you had a chance to look at the user guide for GA ? 
http://webhelp.episerver.com/addons/googleanalytics/#GoogleAnalytics/Developers_GoogleAnalytics.htm%3FTocPath%3D_____4

Hope it helps. 

#85341
Apr 23, 2014 14:02
Vote:
 

Hi Shahid,


Thanks for getting back to me. No I hadn't seen that guide, does it relate to both CMS6R2 and 7? In any case the domain wasn't altered in either my local or our test environment so I wrote my own method and which did a find and replace:

        public static void GenerateEpiGoogleAnalytics(this PageBase page, HttpContext context)
        {

            string existingDomain = UriSupport.SiteUrl.Host.ToString();
            string gaDomain = SiteSettings.GlobalHomePage.GoogleAnalyticsDomain;

            ScriptBuilder scriptBuilder = new ScriptBuilder();
            if (!scriptBuilder.ShouldAppendScript((HttpContextBase)new HttpContextWrapper(context)))
                return;
            bool requiresScriptReference;
            string str = scriptBuilder.BuildTrackingScript(out requiresScriptReference, (HttpContextBase)new HttpContextWrapper(context), page.CurrentPage);

            str = str.Replace(existingDomain, gaDomain);
            page.Page.ClientScript.RegisterStartupScript(typeof(ScriptAppender), "CustomEpiGoogleAnalytics", str, true);
            if (requiresScriptReference)
            {
                string webResourceUrl = page.Page.ClientScript.GetWebResourceUrl(typeof(ScriptAppender), "EPiServer.GoogleAnalytics.Scripts.Tracking.js");
                page.Page.ClientScript.RegisterClientScriptInclude("EpiGat", webResourceUrl);
            }

        }

#85510
Apr 28, 2014 17:28
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.