限制部署代碼

雖然不建議使用 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 類別。類別有助於封鎖目前和未來代碼、觸發條件和變數的功能。

請務必瞭解許可清單和封鎖清單的相關規則:

  1. 許可清單 設定許可清單後,只有位於許可清單中的相關代碼、觸發條件和變數才會執行,無論是明確 (依類型 ID) 或隱含 (所有類別都位於清單中)
  2. 封鎖清單 設定封鎖清單後,只有在代碼、觸發條件和變數不在封鎖清單中時,系統才會執行這些項目 (無論是明確 (依類型 ID) 或隱含 (類別任何項目在清單中) 都是如此)。
  3. 封鎖清單會覆寫許可清單 如果同時設定這兩者,系統會優先採用封鎖清單。您可以針對某類廣告代碼使用許可清單,並針對該類別中的特定廣告代碼使用封鎖清單,但反過來則不行。您無法對某類標記使用封鎖清單,並對該類中的特定標記使用許可清單。
  4. 類別之間有關係 有些類別與其他類別有關係。舉例來說,可以執行非 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 Journey Tag awj nonGoogleScripts
Bing 廣告通用事件追蹤 baut nonGoogleScripts
Bizrate Insights 買方調查解決方案 bb nonGoogleScripts
Bizrate Insights 網站放棄瀏覽率調查解決方案 bsa nonGoogleScripts
ClickTale 標準追蹤代碼 (已淘汰) cts nonGoogleScripts
comScore 統一數位評估法代碼 csm nonGoogleScripts
Conversant Mediaplex - IFRAME MCT 代碼 mpm nonGoogleIframes
Conversant Mediaplex - 標準 IMG 投資報酬率代碼 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 設定) gaawc google
Google Analytics 4 事件 gaawe google
Google Analytics 代碼 (舊版) ga google
Google 消費者問卷調查網站滿意度 gcs google
Google 商店信譽標章代碼 ts
Hotjar 追蹤程式碼 hjtc nonGoogleScripts
Infinity Call Tracking 代碼 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 內容分析代碼 nudge nonGoogleScripts
Oktopost 追蹤程式碼 okt nonGoogleScripts
Optimise 轉換代碼 omc nonGoogleScripts
OwnerListens Message Mate messagemate nonGoogleScripts
Perfect Audience Pixel pa nonGoogleScripts
Personali Canvas pc nonGoogleScripts
Pinterest pntr nonGoogleScripts
已撥電話 placedPixel nonGoogleScripts
Pulse Insights Voice of Customer 平台 pijs nonGoogleScripts
Quantcast 目標對象評估 qcm nonGoogleScripts
Quora Pixel qpx nonGoogleScripts
Rawsoft FoxMetrics fxm nonGoogleScripts
SaleCycle JavaScript 代碼 scjs customScripts
SaleCycle 像素代碼 scp customPixels
轉換頁的 SearchForce JavaScript 追蹤 sfc nonGoogleScripts
到達網頁的 SearchForce JavaScript 追蹤 sfl nonGoogleScripts
SearchForce 重新導向追蹤代碼 sfr nonGooglePixels
Shareaholic shareaholic nonGoogleScripts
Survicate 小工具 svw nonGoogleScripts
Tradedoubler 待開發客戶轉換代碼 tdlc nonGooglePixels
Tradedoubler 銷售轉換代碼 tdsc nonGooglePixels
啟用轉換追蹤代碼 tc nonGoogleScripts
Turn 資料收集代碼 tdc nonGoogleScripts
Twitter 通用網站代碼 twitter_website_tag nonGoogleScripts
Upsellit 全域頁尾代碼 uslt customScripts
Upsellit 確認代碼 uspt customScripts
Ve Interactive JavaScript 代碼 vei nonGoogleScripts
Ve Interactive 像素 veip nonGooglePixels
VisualDNA 轉換代碼 vdc nonGoogleScripts
Xtremepush xpsh nonGoogleScripts
Yieldify yieldify nonGoogleScripts
可用區 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 customScripts
html
customScripts 可執行使用者提供的 JavaScript 程式碼。 html
customPixels
nonGooglePixels
nonGoogleScripts
nonGoogleIframes
html
google 只能執行 Google 代管的指令碼,並將像素傳送至 Google。
html customScripts 的別名。請注意,這也是自訂 HTML 標記的 ID。確保舊版使用者也能享有 customScripts 類別的優點。 customScripts
customPixels
nonGooglePixels
nonGoogleScripts
nonGoogleIframes
customScripts
nonGooglePixels 能夠將像素傳送至非 Google 網域。 customPixels
customScripts
html
nonGoogleScripts
nonGoogleIframes
nonGoogleScripts 可執行非 Google 提供的指令碼。 nonGooglePixels
customScripts
html
nonGoogleIframes 可從非 Google 網域插入 iframe。 nonGooglePixels
customScripts
html
nonGoogleScripts
sandboxedScripts 沙箱 JavaScript 用於自訂範本