雖然我們不建議使用 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 |
| 聯盟窗口歷程代碼 | 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 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 Trusted Stores 代碼 | 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 Pixel | 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 |
pntr |
nonGoogleScripts |
|
| Placed | 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 |
| 啟用資料收集代碼 | tdc |
nonGoogleScripts |
| Twitter 通用網站代碼 | twitter_website_tag |
nonGoogleScripts |
| Upsellit 全域頁尾代碼 | uslt |
customScripts |
| 追加銷售確認標記 | uspt |
customScripts |
| Ve Interactive JavaScript 代碼 | vei |
nonGoogleScripts |
| Ve 互動式像素 | 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 |
下表列出可用的類別,以及這些類別與其他類別的關係。「自動加入白名單」欄代表當該列的類別也加入白名單時,會隱含加入白名單的類別清單。同樣,「Block Lists Automatically」資料欄代表類別,當來自該資料列的類別列入封鎖清單時,系統會隱含封鎖該類別的類別。
| 類別 | 說明 | 自動加入許可清單 | 自動加入封鎖清單 |
|---|---|---|---|
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,用於自訂範本。 | 無 | 無 |