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.