<!-- 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 当前的跨网域衡量指南仍以位于 example-petstore.com 的网站及位于 example-commerce-host.com/example-petstore 的购物车作为开场示例;其代码示例使用的是 example.com。在 Google Analytics 4 中,域名在管理界面中设置:Admin › Data collection and modification › Data streams › 您的网站数据流 › Configure tag settings。
Configure your domains:您的商店和购物车服务提供商。
List unwanted referrals:显示为引荐来源的付款页面。
如果不进行此设置,从商店进入购物车的顾客会被计算两次,这笔销售也无法再追溯到顾客最初是如何找到您商店的。在 Google Tag Manager 中,相同的设置位于 Google tags › 您的代码 › Show all 下。
或在代码中设置
// 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']
});
带有请求正文或发往 API 式路径的请求,来自将此域名用作地址的代码。这些请求会收到 410 Gone 以及 JSON 格式的说明。
请改用:从配置中读取地址
# Python: read the address from configuration, not from the code
import os
BASE_URL = os.environ["API_BASE_URL"]
// JavaScript / Node.js
const baseURL = process.env.API_BASE_URL;
// PHP 8
$baseUrl = getenv('API_BASE_URL') ?: throw new RuntimeException('API_BASE_URL is not set');