Google Analytics for Multiple Domains - Same Store

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 13 ans
Hi Guys,
I have two options for analytics across multiple domains.. some site's i've seen register different accounts..

others specify the current domain by doing the following:


<script type="text/javascript">

  //<![CDATA[

  var pageTracker = _gat._getTracker('UA-xxxxxxx-x');

  pageTracker._setDomainName('.domainname.com.au');

  pageTracker._trackPageview();

  //]]>

</script>


and then on the .co.uk domain it looks like:

<script type="text/javascript">

  //<![CDATA[

  var pageTracker = _gat._getTracker('UA-xxxxxxx-x');

  pageTracker._setDomainName('.domainname.co.uk');

  pageTracker._trackPageview();

  //]]>

</script>


has anyone implemented this before for nop?

Cheers.
Tom
Il y a 13 ans
I use the same thing but for 2 languages !!
I have 2 GAnalytics accounts for each langage.

Which file can i change to support this ??

Thank you
Il y a 13 ans
My solution:

(Create a new analytics profile so you can get a new analytics profile number for your new domain):

Now go under: "Admin->Configuration->All Settings", select: "Analytics.GoogleJS", and copy Google analytics JS.

Create a new setting "Analytics.GoogleJS1", paste the Google analytics JS (into value). Now replace the current profile code with your new profile code that you just created, example:

Analytics.GoogleJS
<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXXXXX-1']); _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> 


Analytics.GoogleJS1
<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXXXXX-2']); _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> 


Create another new setting:
Analytics.Website, and place a value in this setting that makes it unique to the url of your original domain ("domain1.com") for example.

Analytics.Website
domain1.com


Now edit Root.Master.cs (codebehind for the master page), and add the following immediately after

            if (this.SettingManager.GetSettingValueBoolean("Analytics.GoogleEnabled"))
            {


                
                string url = Request.Url.Host;
                string googleJS;

                //Get our original Google Analytics code
                if(url.Contains(this.SettingManager.GetSettingValue("Analytics.Website")))
                {
                    googleJS = this.SettingManager.GetSettingValue("Analytics.GoogleJS");
                }
                //Get our new analytics code which contains a new profile id
                else{
                    googleJS = this.SettingManager.GetSettingValue("Analytics.GoogleJS1");
                }


As you can see, this gives you a logic that chooses which Google Analytics code will be displayed in the browser and thus gives you an idea of which website profile should be recorded as a visit.

When the user visits from "www.domain1.com", the original Google Analytics code is shown, otherwise, if they are not visiting the store from that domain, they will see our new Google Analytics code with the newly embedded profile id.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.