子域的谷歌分析代码跟踪器(跟踪两个页面)
我在同一域上有两个页面,但在两个不同的子域
- french.domain.com/french.html
- english.domain.com/english.html
下,现在相同的分析跟踪代码被放入两个页面中,并且我的统计数据正在跟踪正确(我认为)
所以问题是,这是做到这一点的好方法吗?如果这是两个完全不同的页面,例如:
- domain1.com/page1.htmldomain2.com/page3.html
谷歌会正确跟踪页面吗?我从来没有尝试过,我通常对每个域进行一次分析。 如果一项分析正确跟踪来自不同域的所有不同页面,为什么要为所有页面/域创建超过 1 个分析?
这么多问题,没有足够的答案
I have two pages on the same domain but under two different sub-domain
- french.domain.com/french.html
- english.domain.com/english.html
now THE SAME analytic tracking code is put into both page, and my stats is tracking properly (i think)
So the question is, it is the GOOD way to do that ?, if that was two complete different pages like :
- domain1.com/page1.html
- domain2.com/page3.html
will Google track the page correctly, i never try, i do one analytic for each domain usually.
And if one analytic track all different page from different domain properly, why making more than 1 for all the page/domains?
So many questions, not enough answer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TL;DR:对于您的第一个示例,当且仅当您使用
_setDomainName
配置 cookie 的根域。否则,两个域之间的流量每次从一个域移动到另一个域时都会创建“新”访问,从而导致访问计数膨胀和归因报告不准确(因为您自己的域被视为外部引荐来源网址)。对于第二种情况,如果不采取缓解措施,您将遇到与第一个相同的问题,但解决方案是一个名为
_link
的函数。信息
Google Analytics 默认情况下根据 2 个规则运行来确定其数据的一致性:
根据浏览器 Cookie 的规则进行:根据您设置 Cookie 的域,默认情况下,Google Analytics 可以通过子域访问它们。 在当前站点的域上设置这些 cookie
,
对于子域,您可以使用一个功能来配置应在哪个域上设置 cookie
_gaq.push(["_setDomainName","domain.com"]);
此配置将设置 cookie,以便foo.domain.com
可以访问它们和www.domain.com
,以及domain.com
。但是,如果没有一致使用确切的_setDomainName
在所有这些网站上,您可能会遇到跟踪问题。例如,即使 Google Analytics 可以访问 cookie,它仍然会根据存储的 cookie 的“哈希值”检查当前(或配置的)域的“哈希值”。如果它们不匹配,它将创建一组新的 cookie,表示新的访问,并将前一页设置为其引用者。 (这表现为“自我引用”,您将自己的域视为自己的顶级引用者之一。)跨域
对于跨域情况(domain1.com 和 domain2.com),事情要困难得多。由于这些是第一方 Cookie,因此没有为您提供跨 2 个域共享 Cookie 的本地途径。一旦有人转换到第二个域,该访问部分的 cookie 将无法访问,因此 Google Analytics 将创建一个新的访问,并将其来源归因于第一个域。
如果这两个站点在概念上非常独立,并且您想要完全独立地跟踪这两个站点之间的流量(即使您将数据存储在同一个配置文件中),那么这可能没问题。
但是,如果这两个域之间的统一数据至关重要(例如,第一个域有您的登录页面,第二个域有您的结账页面),您别无选择,只能利用特殊的 Google Analytics 功能,
_link
,与_setAllowLinker
为设置为true
,这会将 Google Analytics cookie 附加到查询字符串中,并指示接收站点将其 cookie 设置为这些值。更改 `_setDomainName` 值
如果您有兴趣跟踪第三级子域(例如,
american.english.example.com
),则需要使用前导配置_setDomainName
时期。 (即.example.com
而不是example.com
)。这样做的缺点是由此产生的“散列”将不再与根级域上的“默认”散列匹配。也就是说,如果到目前为止您尚未使用
setDomainName
,将其更改为带有前导句点的域名将导致您所有“过去”的 Cookie 丢失,这意味着您的回访指标会不太可靠。TL;DR: For your first example, both sites will track correctly if and only if you use
_setDomainName
to configure the root domain for the cookies. Otherwise, traffic between the 2 domains will create "new" visits every time they move from one domain to another, causing an inflation of visit counts and inaccurate attribution reporting (since your own domains are credited as being external referrers.For the second case, without mitigation, you'll have the same problem as the first, but the solution is a function called
_link
.Details
Google Analytics, by default, operates under 2 rules for determining the consistency of its data:
Cookie access works under the rules of browser cookies: Depending on the domain you set cookies to, they can be accessed by subdomains. By default, Google Analytics will set those cookies on the current site's domain.
Subdomains
In the case of subdomains, you're provided a function that lets you configure which domain the cookies should be set on,
_gaq.push(["_setDomainName","domain.com"]);
This configuration will set the cookies such that they'll be accessible tofoo.domain.com
andwww.domain.com
, as well as justdomain.com
. However, without consistent use of that exact_setDomainName
across all these sites, you may run into tracking problems. For example, even if Google Analytics has access to the cookies, it will still check the "hash" of the current (or configured) domain against that of the stored cookie. If they don't match, it'll create a new set of cookies, signaling a new visit, with the previous page set as its referrer. (This manifests itself as "self-referral", where you see your own domain as one of its own top referrers.)Cross Domain
For the cross-domain case (domain1.com and domain2.com), things are much harder. Since these are first-party cookies, you're provided no native avenue for sharing cookies across 2 domains. The cookies from the part of the visit will be inaccessible once someone transitions to the second domain, so Google Analytics will create a new visit, attributing its source as the first domain.
This can be OK if the 2 sites are conceptually very separate, and you want to track traffic between these 2 sites totally separately (even if you're storing the data in the same profile.)
However, if unified data across those 2 domains is crucial (for example, the first domain has your landing page and the second domain has your checkout page), you have no recourse but to utilize a special Google Analytics function,
_link
, in concert with_setAllowLinker
being set totrue
, which appends the Google Analytics cookies in a query string and instructs the receiving site to set its cookies to those values.Changing `_setDomainName` values
If you're interested in tracking third level subdomains (e.g,
american.english.example.com
), you need to configure the_setDomainName
with a leading period. (ie,.example.com
instead ofexample.com
).The drawback to doing this is that the "hash" resulting from it will no longer match the "default" hash on the root level domain. That is, if up until now, you hadn't been using
setDomainName
, changing it to one with a leading period will result in all of your "past" cookies from being lost, meaning your returning visit metrics will be less reliable.