虽然不建议限制使用 Google 跟踪代码管理器部署的代码类型,但出于各种原因,有时可能需要限制在网站上部署的代码类型。例如,出于代码稳定性或数据收集原因,某些网站所有者可能不希望 Google 跟踪代码管理器用户能够向其网站添加某些代码。本文介绍了如何在跟踪代码管理器中限制代码部署。
若要控制允许在网页上使用哪些代码、触发器和变量,请在数据层中使用 gtm.allowlist 和/或 gtm.blocklist 键。这些键会覆盖容器中的一切配置。只要正确列入屏蔽名单,则凡是列入该名单的代码、触发器和变量均不会触发,即使已在 Google 跟踪代码管理器中将其配置为会触发,也是如此。
以下示例演示了如何使用许可名单和屏蔽名单来初始化数据层。这两种名单是可选的,您可以单独使用,也可以同时使用(如下所示)。这两种名单的类型必须为 Array,且名单中值的类型必须为 String。应在触发任何代码之前将这些值推送到数据层:
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
  'gtm.allowlist': ['<id>', '<id>', ...],
  'gtm.blocklist': ['<id>', '<id>', '<id>', ...]
});
</script>
名单中每个 ID 都对应一个特定的代码类型、触发器类型、变量类型或者一个包含多种类型的类。类表示一组具有相同功能的代码、触发器和变量。例如,凡是可将像素发送到非 Google 网域的代码,均具有 nonGooglePixels 类。如需在当前和未来的代码、触发器和变量中屏蔽某些功能,类就会派上用场。
一定要了解许可名单和屏蔽名单的控制规则,具体如下:
- 许可名单:设置许可名单后,相关代码、触发器和变量只有在列入许可名单后才会执行,这包括以显式方式(通过类型 ID)或隐式方式(通过在名单中包含其所有类)列入许可名单的情况。
- 屏蔽名单:设置屏蔽名单后,代码、触发器和变量只有在未列入屏蔽名单中时才会执行;无论是以显式方式(通过类型 ID)还是隐式方式(通过在名单中包含其任意类)列入了屏蔽名单,都不会执行。
- 屏蔽名单会覆盖许可名单 如果两种名单都设置了,则会优先执行屏蔽名单。您可以将一个代码类列入许可名单,并将该类中的某个特定代码列入屏蔽名单,但反过来操作的话,就行不通。也就是说,您无法将一个代码类列入屏蔽名单,然后将该类中的某个特定代码列入许可名单。
- 类之间存在关联
一些类与其他类是相关联的。例如,凡是可运行非 Google 脚本的代码,就可以(根据定义)发送非 Google 像素。因此,屏蔽 nonGooglePixels也会自动屏蔽nonGoogleScripts。属于其中任一组的所有代码、触发器和变量都将被屏蔽。
下表列出了可用的代码、触发器和变量,以及它们的类型及所属的类:
| 代码 | ID | Classes | 
|---|---|---|
| AB TASTY 通用代码 | abtGeneric | nonGoogleScripts | 
| AdAdvisor 代码 | ta | nonGoogleScripts | 
| Adometry 代码 | adm | google | 
| AdRoll 智能像素代码 | asp | nonGoogleScripts | 
| Google Ads 转化跟踪代码 | awct | google | 
| Google Ads 再营销代码 | sp | google | 
| Affiliate Window 转化代码 | awc | nonGoogleScripts | 
| Affiliate Window 行为历程代码 | awj | nonGoogleScripts | 
| Bing Ads 通用事件跟踪 | baut | nonGoogleScripts | 
| Bizrate Insights 买家调查解决方案 | bb | nonGoogleScripts | 
| Bizrate Insights 网站放弃情况调查解决方案 | bsa | nonGoogleScripts | 
| ClickTale 标准跟踪代码 (OBSOLETE) | cts | nonGoogleScripts | 
| comScore Unified Digital Measurement 代码 | csm | nonGoogleScripts | 
| Conversant Mediaplex - IFRAME MCT 代码 | mpm | nonGoogleIframes | 
| Conversant Mediaplex - 标准 IMG ROI 代码 | mpr | nonGooglePixels | 
| 转化链接器 | gclidw | google | 
| Crazy Egg 代码 | cegg | nonGoogleScripts | 
| Criteo OneTag | crto | nonGoogleScripts | 
| 自定义 HTML 代码 | html | customScripts | 
| 自定义图片代码 | img | customPixels | 
| DistroScale 代码 | dstag | nonGoogleScripts | 
| Floodlight 计数器代码 | flc |  | 
| Floodlight 销售代码 | fls |  | 
| Dstillery 通用像素代码 | m6d | nonGooglePixels | 
| Eulerian Analytics 代码 | ela | customScripts | 
| Google 代码(以前称为“Google Analytics [分析] 4 配置”) | gaawc | google | 
| Google Analytics(分析)4 事件 | gaawe | google | 
| Google Analytics(分析)代码(旧版) | ga | google | 
| Google 消费者问卷调查网站满意度 | gcs | google | 
| Google 信誉商店代码 | ts |  | 
| Hotjar 跟踪代码 | hjtc | nonGoogleScripts | 
| Infinity 通话跟踪代码 | infinity | nonGoogleScripts | 
| Intent Media - 搜索对比广告 | sca | nonGoogleScripts | 
| K50 跟踪代码 | k50Init | nonGoogleScripts | 
| LeadLab | ll | nonGoogleScripts | 
| LinkedIn 代码 | bzi | nonGoogleScripts | 
| Lytics JS 代码 | ljs | nonGoogleScripts | 
| Marin Software 代码 | ms | nonGoogleScripts | 
| Mediaplex - IFRAME MCT 代码 | mpm | nonGoogleIframes | 
| Mediaplex - 标准 IMG ROI 代码 | mpr | nonGooglePixels | 
| Message Mate | messagemate | nonGoogleScripts | 
| Mouseflow 代码 | mf | nonGoogleScripts | 
| Neustar 像素 | ta | nonGoogleScripts | 
| Nielsen DCR Static Lite 代码 | ndcr | nonGoogleScripts | 
| Nudge Content Analytics 代码 | nudge | nonGoogleScripts | 
| Oktopost 跟踪代码 | okt | nonGoogleScripts | 
| Optimise 转化代码 | omc | nonGoogleScripts | 
| OwnerListens Message Mate | messagemate | nonGoogleScripts | 
| Perfect Audience Pixel | pa | nonGoogleScripts | 
| Personali Canvas | pc | nonGoogleScripts | 
| pntr | nonGoogleScripts | |
| Placed | placedPixel | nonGoogleScripts | 
| Pulse Insights 客户心声调查平台 | pijs | nonGoogleScripts | 
| Quantcast 受众群体衡量 | qcm | nonGoogleScripts | 
| Quora 像素 | qpx | nonGoogleScripts | 
| Rawsoft FoxMetrics | fxm | nonGoogleScripts | 
| SaleCycle JavaScript 代码 | scjs | customScripts | 
| SaleCycle 像素代码 | scp | customPixels | 
| 针对转化页的 SearchForce JavaScript 跟踪 | sfc | nonGoogleScripts | 
| 针对着陆页的 SearchForce JavaScript 跟踪 | sfl | nonGoogleScripts | 
| SearchForce Redirection 跟踪代码 | sfr | nonGooglePixels | 
| Shareaholic | shareaholic | nonGoogleScripts | 
| Survicate 微件 | svw | nonGoogleScripts | 
| Tradedoubler 潜在客户转化代码 | tdlc | nonGooglePixels | 
| Tradedoubler 销售转化代码 | tdsc | nonGooglePixels | 
| Turn 转化跟踪代码 | tc | nonGoogleScripts | 
| Turn 数据收集代码 | tdc | nonGoogleScripts | 
| Twitter 通用网站代码 | twitter_website_tag | nonGoogleScripts | 
| Universal Analytics 代码 | ua | google | 
| Upsellit Global Footer 代码 | uslt | customScripts | 
| Upsellit 确认代码 | uspt | customScripts | 
| Ve Interactive JavaScript 代码 | vei | nonGoogleScripts | 
| Ve Interactive 像素 | veip | nonGooglePixels | 
| VisualDNA 转化代码 | vdc | nonGoogleScripts | 
| Xtremepush | xpsh | nonGoogleScripts | 
| Yieldify | yieldify | nonGoogleScripts | 
| Zones | zone |  | 
| 触发器 | ID | Classes | 
|---|---|---|
| 元素可见性监听器/触发器 | evl | google | 
| 点击监听器/触发器 | cl | google | 
| 表单提交监听器/触发器 | fsl |  | 
| 历史记录监听器/触发器 | hl | google | 
| JavaScript 错误监听器/触发器 | jel | google | 
| 链接点击监听器/触发器 | lcl |  | 
| 滚动深度监听器/触发器 | sdl | google | 
| 计时器监听器/触发器 | tl | google | 
| YouTube 视频监听器/触发器 | ytl | google | 
| 变量 | ID | Classes | 
|---|---|---|
| 第一方 Cookie | k | google | 
| 自动事件变量 | v | google | 
| 常量 | c | google | 
| 容器版本号 | ctv | google | 
| 自定义事件 | e | google | 
| 自定义 JavaScript 变量 | jsm | customScripts | 
| 数据层变量 | v | google | 
| 调试模式 | dbg | google | 
| DOM 元素 | d | google | 
| 元素可见性 | vis | google | 
| Google Analytics(分析)设置(旧版) | gas | google | 
| HTTP 引荐来源网址 | f | google | 
| JavaScript 变量 | j | google | 
| 对照表 | smm | google | 
| 随机数字 | r | google | 
| 正则表达式表格 | remm | google | 
| 网址 | u | google | 
下表列出了可用的类以及类之间的关系。自动列入许可名单列中列出了当相应行中的类列入许可名单时将以隐式方式列入许可名单的类。同样,自动列入屏蔽名单列中列出了当相应行中的类列入屏蔽名单时将以隐式方式列入屏蔽名单的类。
| 类 | 说明 | 自动列入许可名单 | 自动列入屏蔽名单 | 
|---|---|---|---|
| customPixels | 能够将像素发送到用户定义的网址。 | nonGooglePixels | customScriptshtml | 
| customScripts | 能够运行用户提供的 JavaScript 代码。 | htmlcustomPixelsnonGooglePixelsnonGoogleScriptsnonGoogleIframes | html | 
| google | 只能运行 Google 托管的脚本以及将像素发送到 Google。 | ||
| html | customScripts的别名。请注意,它也是自定义 HTML 代码的ID。它可确保传统用户也可以获享customScripts类的优势。 | customScriptscustomPixelsnonGooglePixelsnonGoogleScriptsnonGoogleIframes | customScripts | 
| nonGooglePixels | 能够将像素发送到非 Google 网域。 | customPixelscustomScriptshtmlnonGoogleScriptsnonGoogleIframes | |
| nonGoogleScripts | 能够运行并非由 Google 提供的脚本。 | nonGooglePixels | customScriptshtml | 
| nonGoogleIframes | 能够注入来自非 Google 网域的 iframe。 | nonGooglePixels | customScriptshtmlnonGoogleScripts | 
| sandboxedScripts | 用作自定义模板一部分的沙盒化 JavaScript。 | 无 | 无 |