Google Analytics Domain With and Without WWW - google-analytics

If I store a cookie or set a session associated with http://mydomain.com, the same cookie or session will not be picked up on http://www.mydomain.com. I am putting down http://mydomain.com as my default URL.
Will Google Analytics track both the www and non-www domains as one in this case?

If you set your own cookie with a domain of "mydomain.com", then it will only be visible on that domain (no subdomains). If you set your own cookie as ".mydomain.com" (prefix it with a dot), then it will be visible "mydomain.com" and any subdomain of mydomain.com.
GA by default sets its cookie on the exact domain, so if you are on "www.mydomain.com" then it will set it for "www.mydomain.com" and it will not be visible on "mydomain.com" or some other subdomain. If however you specify to GA to use "mydomain.com" then it will be available on any subdomain. Note the lack of dot, which is not consistent with how you would normally set a cookie domain with your own code. This is because GA automatically prefixes a dot to it, within their own code.
For more info, refer to their document entry on Tracking Multiple Domains

Related

How To Prevent Cookies From Being Created Under Different Hosts

I've run into a problem and I'm not sure how to go about fixing it. Here is the scenario.
A user visits my website (www.MyWebSite.com) and clicks on a button that puts a cookie on their computer. If I examined that cookie on their machine it would list the "host" as www.MyWebSite.com.
If the user then changes the URL in their browser to MyWebSite.com (without the www) reloads the page and then clicks on the button, a brand new cookie with the same name as the first cookie is created. The host of this cookie is MywebSite.com
Obviously this is not good - beside two cookies with the same name, only the cookie with the corresponding URL address is being read by my program.
Can I force cookies to be created with the www host and/or can I force the page to be www or what??? What and how is the best way to prevent this problem?
Cookie Creation using VB.net
Response.Cookies("AAA")("bbb") = strABC
Response.Cookies("AAA").Expires = DateTime.Now.AddDays(1)
Any help is greatly appreciated.
For (obvious) security reasons you can only read cookies that are set by the same domain the user requests. It doesn't matter if it is just a difference like in your example, or an entirely different domainname.
What you could do in this situation (it should improve your SEO as well), is redirect (301) all traffic from the site without www to the site with www.
If you're using IIS 7 or higher, you can find an example on how to do that with URL Rewrite here: http://weblogs.asp.net/owscott/archive/2009/11/27/iis-url-rewrite-rewriting-non-www-to-www.aspx
That's for security reasons. Any subdomain of a host is considered to be another realm, another world.
If you want your cookies to be sent to your subdomains too, then start the Host attribute of the cookie with a .. In other words, set your cookie for .MyWebSite.Com.
See Wikipedia for more information.

Can a subdomain delete a domain cookie?

Suppose I have a cookie that is set for .domain.com, and my subdomain is sub.domain.com. Can I delete cookies that are set for the main domain? I know it is possible to read them, but is it possible to delete these cookies, or overwrite their values?
Yes, a subdomain can set/expire a cookie for the main domain, but the main domain cannot set/expire a cookie for a subdomain. See RFC 6265 Sections 5.1.3, 5.3 (see point #6), and 8.6. Section 8.6 in particular describes how a subdomain can set a cookie for the main domain and have it affect a sibling subdomain.

Does Google Analytics track the traffic of multiple domains?

I have a website subdomain.domain.com. I created an analytics account for this and included the tracking code. Later I registered a new domain xyz.com and pointed to the same website subdomain.domain.com. In Google analytics report, will the analytics display the traffic from both domains or do I need to make some alterations?
Google Analytics tracks website traffic no matter what hostname is specified in the page URL. You can use the Hostname dimension in the content report to find out.
In your case, depending on the type of hostname redirection you may or may not see the xyz.com in your reports. When you navigate to the xyz.com in browser, pick any page and can see in your browser xyz.com - it will be tracked. If you can see subdomain.domain.com - the last will be tracked.
If you website is accessible via subdomain.domain.com and xyz.com - you may have an issue with cross-domain users and duplicated (inflated count of) users since GA cookie in a browser is set per hostname
I have the same situation where our URL has changed and we are now in a crossover period while both URLs are active.
Without changing the tracking code I am getting our stats as before but I cannot tell in the analytics reports which URL the visitor used to access the site. If that is not of concern to you then you don't need to update your tracking code.
There is a secondary dimension under Content called "Hostname", this will break out your traffic by whether or not it was visited from subdomain.domain.com or xyz.com

Authentication cookie with subdomains

i have an asp.net website http://www.site.com. This web app is also running on http://subdomain1.site.com and http://subdomain2.site.com. Now i want to set authentication cookie in such a way that http://site.comand http://www.site.comshare authentication cookie but it should not be shared by http://subdomain1.site.com. similarly, http://www.domain1.site.com and http://domain1.site.com should share cookie but it should not be shared by http://domain2.site.com or http://www.domain2.site.com. How can i handle this with asp.net?
By default, cookies are associated with a specific domain. For example, if your site is www.contoso.com, the cookies you write are sent to the server when users request any page from that site. (This might not include cookies with a specific path value.) If your site has subdomains—for example, contoso.com, sales.contoso.com, and support.contoso.com—then you can associate cookies with a specific subdomain.
Response.Cookies["domain"].Domain = "support.contoso.com";
Normally a cookie set on contoso.com will be accessed by all subdomain. but if you want to limit sub domain for the cookie you should manually set domain property for each domain you want them to access.
Regards.
I ended up using different cookie names on different domains as described in this article

when creating a cookie, how can I specify www and no www cookie?

when I create a cookie for a domain, is it possible for me to set that this domain should be on both the www and non www domain?
I check for a cookie, and if not present I rediret to login page (its not a super secure thing). it seems when the user has a cookie, if the url changes to www. it gets redirected to login again.
When you drop the cookie specify .mydomain.com - note the leading period. That should work for both the root domain and the www subdomain.
#electronherders' solution works, but you should also consider canonicalising either the www or the no-www domain. Redirect visitors from one to the other, so there's only one correct URL for your site.

Resources