结构化数据
站点链接搜索框与网站名称
包含 query.example-petstore.com 的搜索框标记有什么作用、Google 为何停用它,以及现在应使用的 WebSite 标记。
指南 · Google Analytics
从 Google Classic Analytics 示例中复制的代码至今仍包含 example-petstore.com 和 example-commerce-host.com。这些代码已无法衡量任何数据,其中的示例链接还会将访问者引导到错误的网站。本指南将介绍如何用 Google Analytics 4 取而代之。
2009 年至 2024 年间,Google 关于使用 Classic Analytics(ga.js)跟踪多个域名的指南以位于 example-petstore.com 的宠物商店及位于 example-commerce-host.com 的购物车为例。常被复制的典型代码行如下:
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'example-petstore.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setCookiePath', '/myStore/']);
<a href="http://dogs.example-petstore.com/intro.html"
onclick="_gaq.push(['_link', 'http://dogs.example-petstore.com/intro.html']); return false;">See my pet store</a>
<form onSubmit="pageTracker._linkByPost('www.example-commerce-host.com/petStoreCart/begin.php');">
更早的变体使用带前导点的 pageTracker._setDomainName(".example-petstore.com"),或 _setDomainName("none")。Universal Analytics(analytics.js)代码则改用 ga('create', …, {'allowLinker': true}) 和 ga('linker:autoLink', […])。
http://dogs.example-petstore.com/intro.html)的链接和表单会将真实访问者带到示例域名,而不是您自己的网页。href="www.example-petstore.com" 会被解析为您自己网站上的路径,最终指向“未找到”页面。_setDomainName 从来就没有生效过。_gaq、pageTracker、urchin、ga.js、analytics.js、ga('create'、example-petstore 和 example-commerce-host。_link、_linkByPost 或 pageTracker 的 onclick 和 onsubmit 处理程序。/petStoreCart/begin.php)指向您自己的网页或真实的结账页面,或将其删除。创建一个带有网站数据流的 Google Analytics 4 媒体资源,然后直接或通过 Google Tag Manager 将 Google 代码添加到每个网页。将 G-XXXXXXXXXX 替换为您数据流的衡量 ID。
<!-- Google tag (gtag.js) for Google Analytics 4 -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
仅当一次访问跨越您的多个域名时才需要设置,例如商店和结账服务提供商。在 Google Analytics 4 中,此项在管理界面中设置,而不是在代码中:
_gl 参数。在 Google Tag Manager 中,同一列表位于 Google tags › 您的代码 › Show all 下。如果您更喜欢使用代码,可在 Google 代码中设置链接器域名:
// Only if you configure cross-domain measurement in code instead of in the admin;
// place this before gtag('config', …)
gtag('set', 'linker', {
'domains': ['www.example.com', 'checkout.example.net']
});
支付服务提供商或其他外部环节可能会显示为销售的来源。请将这类域名添加到 Configure tag settings › Show all › List unwanted referrals 下(每个数据流最多 50 个)。此后,Analytics 不再将这些域名视为引荐来源(它会添加 ignore_referrer=true),因此该访问会保留其原始来源,例如将客户带来的广告或搜索。
ga.js、analytics.js 或示例域名。_gl=。