雖然我們不建議限制使用 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 |
聯盟視窗轉換標記 | awc |
nonGoogleScripts |
Affiliate Window Journey 代碼 | 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 |
瘋狂 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 訊息 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 |
Turn 轉換追蹤代碼 | tc |
nonGoogleScripts |
Turn 資料收集標記 | tdc |
nonGoogleScripts |
Twitter 通用網站代碼 | twitter_website_tag |
nonGoogleScripts |
通用 Analytics (分析) 代碼 | ua |
google |
向上銷售全域頁尾代碼 | uslt |
customScripts |
向上銷售確認代碼 | uspt |
customScripts |
Ve 互動式 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 |
下表提供可用類別的清單,以及這些類別與其他類別的關係。「列入許可清單」資料欄代表當該資料列中的類別也加入許可清單時,將自動加入許可清單的類別清單。同樣地,「已列入封鎖清單」資料欄代表該列的類別遭封鎖時,將以隱含方式封鎖的類別清單。
類別 | 說明 | 已自動加入許可清單 | 已自動封鎖 |
---|---|---|---|
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,做為自訂範本的一部分使用。 | 無 | 無 |