Branch8

Shopify Plus 香港 GTM 同意模式 v2 設定教學

Matt Li
September 25, 2026
12 mins read
Shopify Plus 香港 GTM 同意模式 v2 設定教學

Key Takeaways

  • Default consent 必須寫在 GTM 容器碼之前,否則代碼會先行觸發
  • 同意模式 v2 新增 ad_user_data 與 ad_personalization 兩個參數
  • Shopify 與 CMP 的同意狀態需雙向同步,避免 app pixel 漏網
  • 結帳頁已沙箱化,追蹤必須改用 Web Pixels Custom Pixel
  • 用 GTM Preview 的 Consent 分頁與 gcs 參數驗證設定

在 Shopify Plus 上部署 Google 同意模式 v2,核心是三步:於 GTM 載入前設定 default consent 狀態、以 Shopify Customer Privacy API 同步訪客選擇並呼叫 gtag('consent', 'update', ...)、再於結帳用 Custom Pixel 讀取同意狀態。香港商戶若有 EEA/英國流量,必須完成此設定。

為何香港 Shopify Plus 商戶避不開同意模式 v2?

很多香港團隊的第一反應是:香港《個人資料(私隱)條例》並沒有像 GDPR 那樣強制 cookie banner,為何要花工夫做同意模式?

原因不在本地法規,而在 Google 的廣告產品規則。根據 Google 的 EU User Consent Policy(Google 官方政策頁),任何向歐洲經濟區(EEA)及英國使用者投放 Google 廣告、或從該地區收集資料的廣告主,都必須取得符合要求的同意並將訊號傳回 Google。根據 Google Tag Platform 開發者文件,同意模式 v2 在 2024 年 3 月起新增 ad_user_data 與 ad_personalization 兩個參數,缺少這兩個訊號的 EEA 流量將無法用於再行銷受眾建立,轉換建模(conversion modelling)亦會退化。

對香港、新加坡、台北的跨境 DTC 品牌來說,這是很實際的營收問題:你的網站放在 shopify.com 網域上、用同一個 GA4 資源與同一個 Google Ads 帳戶服務全球市場,只要有一部分流量來自歐洲,整個帳戶的受眾質素就受影響。

同時,APAC 各市場的監管方向亦在收緊:

  • 香港:個人資料私隱專員公署(PCPD)在《保障個人資料私隱指引》中要求收集前作出明確告知(DPP1),跨境轉移條款(第 33 條)雖未生效但一直在討論中。
  • 新加坡:PDPC 的 PDPA 對 cookie 採「合理人」同意標準,deemed consent 在行為廣告情境下並不穩妥。
  • 澳洲:OAIC 推動的 Privacy Act 改革已明確提出要處理線上追蹤與定向廣告。
  • 台灣:個資法對「特定目的外利用」有嚴格限制。

換句話說,把同意訊號做好一次,換來的是多市場合規的共同基礎,而不是只為歐洲做一套臨時方案。

開始前需要準備什麼?

動手前先確認以下前置條件,否則你會在第三步卡住:

  1. Shopify Plus 方案,並已啟用 Checkout Extensibility(新版結帳)。舊版 checkout.liquid 將被淘汰,所有結帳追蹤必須改用 Web Pixels API。
  2. GTM 容器(Web)已建立,並有編輯權限。
  3. Shopify Admin 權限:需要存取 Online Store → Themes → Edit code,以及 Settings → Customer privacy、Settings → Customer events。
  4. 一個 CMP 或自建 banner。Shopify 內建的 cookie banner 只在你於 Customer privacy 設定中選取的地區顯示(預設是 GDPR 地區);若你要在香港、台灣也顯示,需要手動加入地區或改用 Google 認證的第三方 CMP(如 Cookiebot、OneTrust、Usercentrics)。
  5. GA4 資源與 Google Ads 帳戶已與 GTM 連結。
  6. 建議安裝 Google Tag Assistant 及瀏覽器的 GTM Preview 模式。

驗證 Shopify Customer Privacy API 是否已載入,最快的方法是在店面 console 執行:

1window.Shopify.customerPrivacy.currentVisitorConsent()
2// 預期輸出:{marketing: "", analytics: "", preferences: "", sale_of_data: ""}

若回傳 undefined,代表 Customer Privacy API 尚未載入,請先到 Settings → Customer privacy 啟用 cookie banner 或 Privacy API。

Ready to Transform Your Ecommerce Operations?

Branch8 specializes in ecommerce platform implementation and AI-powered automation solutions. Contact us today to discuss your ecommerce automation strategy.

同意模式的邏輯是「先預設拒絕,再按使用者選擇更新」。這段 default 指令必須在 GTM container snippet 之前執行,否則 Google 代碼會在沒有 consent 狀態下先行觸發。

在 Shopify 後台開啟 layout/theme.liquid,於 <head> 內最上方加入:

1<!-- Google Consent Mode v2 — default state -->
2<script>
3 window.dataLayer = window.dataLayer || [];
4 function gtag(){dataLayer.push(arguments);}
5
6 // 歐洲 / 英國:全部拒絕
7 gtag('consent', 'default', {
8 'ad_storage': 'denied',
9 'ad_user_data': 'denied',
10 'ad_personalization': 'denied',
11 'analytics_storage': 'denied',
12 'functionality_storage': 'denied',
13 'personalization_storage': 'denied',
14 'security_storage': 'granted',
15 'wait_for_update': 500,
16 'region': ['EU','EEA','GB','IS','LI','NO','CH']
17 });
18
19 // 其他市場(HK / SG / TW / AU / US):analytics 先允許,廣告仍需同意
20 gtag('consent', 'default', {
21 'ad_storage': 'denied',
22 'ad_user_data': 'denied',
23 'ad_personalization': 'denied',
24 'analytics_storage': 'granted',
25 'functionality_storage': 'granted',
26 'personalization_storage': 'granted',
27 'security_storage': 'granted',
28 'wait_for_update': 500
29 });
30
31 gtag('set', 'ads_data_redaction', true);
32 gtag('set', 'url_passthrough', true);
33</script>

幾個關鍵設定的意義:

  • wait_for_update: 500:給 CMP 500 毫秒時間回傳使用者已儲存的選擇,避免代碼在 consent 更新前就以 denied 狀態送出。網速較慢的市場(例如印尼、越南的行動流量)可調高至 2000,但要留意會延後 page_view。
  • ads_data_redaction:在 ad_storage 為 denied 時,移除廣告點擊識別碼(gclid)。
  • url_passthrough:在無 cookie 情況下,透過 URL 參數傳遞點擊 ID,讓轉換仍能歸因。
  • region 陣列:後一個沒有 region 的 default 指令會套用到所有未被覆蓋的地區。順序很重要——把有 region 的放前面。

如果你用 Google 認證的 CMP 模板(GTM 內建有 Cookiebot、OneTrust 等模板),則不要重複寫 default 指令,改在 GTM 內用 Consent Initialization — All Pages 觸發條件載入 CMP 模板即可。

步驟二:把 GTM 容器碼放進 Shopify Plus 主題

Shopify 不允許在 theme.liquid 以外的地方插入 GTM,而結帳頁則完全隔離。標準做法是在同一段 default consent 之後緊接容器碼:

1<!-- Google Tag Manager -->
2<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
3new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
4j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
5'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
6})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
7<!-- End Google Tag Manager -->

同時建議把 Shopify 的商品與訂單資料推進 dataLayer,方便 GA4 電商事件:

1{% if template contains 'product' %}
2<script>
3 window.dataLayer.push({
4 event: 'view_item',
5 ecommerce: {
6 currency: '{{ cart.currency.iso_code }}',
7 value: {{ product.selected_or_first_available_variant.price | divided_by: 100.0 }},
8 items: [{
9 item_id: '{{ product.selected_or_first_available_variant.sku }}',
10 item_name: {{ product.title | json }},
11 item_brand: {{ product.vendor | json }},
12 price: {{ product.selected_or_first_available_variant.price | divided_by: 100.0 }}
13 }]
14 }
15 });
16</script>
17{% endif %}

注意:在 theme.liquid 直接放 GTM 只影響店面(online store),不包含結帳與訂單完成頁。結帳部分見步驟四。

Ready to Transform Your Ecommerce Operations?

Branch8 specializes in ecommerce platform implementation and AI-powered automation solutions. Contact us today to discuss your ecommerce automation strategy.

步驟三:用 Customer Privacy API 同步訪客選擇

這是整個設定最容易出錯的環節。Shopify 有自己的一套同意狀態儲存(_tracking_consent cookie),而 Google 有自己的一套。兩者必須雙向對齊。

根據 Shopify 開發者文件,Customer Privacy API 會在訪客作出選擇時派發 visitorConsentCollected 事件。加入以下腳本(放在 GTM 容器碼之後):

1<script>
2 function mapShopifyConsentToGoogle(consent) {
3 var marketing = consent.marketing === true ? 'granted' : 'denied';
4 var analytics = consent.analytics === true ? 'granted' : 'denied';
5 var prefs = consent.preferences === true ? 'granted' : 'denied';
6
7 gtag('consent', 'update', {
8 'ad_storage': marketing,
9 'ad_user_data': marketing,
10 'ad_personalization': marketing,
11 'analytics_storage': analytics,
12 'functionality_storage': prefs,
13 'personalization_storage': prefs
14 });
15
16 window.dataLayer.push({
17 event: 'consent_updated',
18 consent_marketing: marketing,
19 consent_analytics: analytics
20 });
21 }
22
23 document.addEventListener('visitorConsentCollected', function (event) {
24 mapShopifyConsentToGoogle(event.detail);
25 });
26
27 // 回訪訪客:讀取已儲存的選擇
28 window.Shopify.loadFeatures(
29 [{ name: 'consent-tracking-api', version: '0.1' }],
30 function (error) {
31 if (error) { console.warn('Consent API load failed', error); return; }
32 var saved = window.Shopify.customerPrivacy.currentVisitorConsent();
33 if (saved.marketing !== '' || saved.analytics !== '') {
34 mapShopifyConsentToGoogle({
35 marketing: saved.marketing === 'yes',
36 analytics: saved.analytics === 'yes',
37 preferences: saved.preferences === 'yes'
38 });
39 }
40 }
41 );
42</script>

若你用第三方 CMP,方向要反過來

用 Cookiebot / OneTrust / Usercentrics 時,CMP 是唯一真相來源,你需要把它的選擇寫回 Shopify,否則 Shopify 自家的 app pixel(例如 Meta、TikTok 的官方 app)仍會照跑:

1window.Shopify.customerPrivacy.setTrackingConsent({
2 analytics: true,
3 marketing: true,
4 preferences: true,
5 sale_of_data: false
6}, function () {
7 console.log('Shopify consent synced from CMP');
8});

把這段放在 CMP 的 onAccept / onConsentChanged callback 內。跨境品牌最常見的合規缺口就是這裡——CMP banner 顯示「已拒絕」,但 Shopify 的 marketing pixel 照樣傳送資料。

步驟四:結帳頁怎麼辦?Custom Pixel 的沙箱限制

Checkout Extensibility 之後,Shopify 結帳頁跑在沙箱化的 iframe 中,GTM 容器不能注入。你必須用 Settings → Customer events → Add custom pixel 建立 Web Pixel。

在 Custom Pixel 編輯器中:

1// Shopify Custom Pixel — Consent-aware GA4
2const MEASUREMENT_ID = 'G-XXXXXXXXXX';
3
4api.customerPrivacy.setTrackingConsent; // 可用於沙箱內同意操作
5
6const consent = init.customerPrivacy;
7const marketing = consent.marketingAllowed ? 'granted' : 'denied';
8const analyticsOk = consent.analyticsProcessingAllowed ? 'granted' : 'denied';
9
10// 載入 gtag
11const s = document.createElement('script');
12s.src = `https://www.googletagmanager.com/gtag/js?id=${MEASUREMENT_ID}`;
13s.async = true;
14document.head.appendChild(s);
15
16window.dataLayer = window.dataLayer || [];
17function gtag(){dataLayer.push(arguments);}
18
19gtag('consent', 'default', {
20 ad_storage: 'denied',
21 ad_user_data: 'denied',
22 ad_personalization: 'denied',
23 analytics_storage: 'denied'
24});
25
26gtag('consent', 'update', {
27 ad_storage: marketing,
28 ad_user_data: marketing,
29 ad_personalization: marketing,
30 analytics_storage: analyticsOk
31});
32
33gtag('js', new Date());
34gtag('config', MEASUREMENT_ID, { send_page_view: false });
35
36analytics.subscribe('checkout_completed', (event) => {
37 const c = event.data.checkout;
38 gtag('event', 'purchase', {
39 transaction_id: c.order?.id,
40 value: c.totalPrice?.amount,
41 currency: c.currencyCode,
42 items: c.lineItems.map(li => ({
43 item_id: li.variant?.sku,
44 item_name: li.title,
45 price: li.variant?.price?.amount,
46 quantity: li.quantity
47 }))
48 });
49});

在 Custom Pixel 的設定畫面中,記得把 Permission 設為 Analytics 或 Marketing,Shopify 便會依訪客同意狀態自動決定是否載入該 pixel——這是沙箱模式的一層額外保護。

更嚴謹的做法是改用 Server-side GTM:把 Shopify 的 customer events 送到你自建的 sGTM 端點(可託管於 GCP 的 asia-east2 香港區或 asia-southeast1 新加坡區),再由伺服器端依 consent 狀態分派給 GA4 與 Google Ads。這樣可以同時解決 Safari ITP 的 7 天 cookie 限制,代價是需要維運一個 Cloud Run 服務。

Ready to Transform Your Ecommerce Operations?

Branch8 specializes in ecommerce platform implementation and AI-powered automation solutions. Contact us today to discuss your ecommerce automation strategy.

步驟五:在 GTM 為每個代碼設定同意檢查

進入 GTM → Admin → Container Settings,勾選 Enable consent overview。之後在 Tags 列表左上會出現盾牌圖示。

建議的對應關係:

  • GA4 Configuration / GA4 Event:內建同意檢查已處理 analytics_storage,無需額外設定。
  • Google Ads Conversion / Remarketing:內建處理 ad_storage、ad_user_data、ad_personalization。
  • Meta Pixel(Custom HTML):在 Consent Settings → Additional consent checks 加入 ad_storage。
  • TikTok / LINE / Xiaohongshu 等自訂 HTML 代碼:同樣加入 ad_storage,否則它們會無視同意狀態直接執行。
  • Consent Initialization — All Pages 觸發條件:只給 CMP 模板使用,其他代碼一律不要掛這個觸發條件。

對於亞太多市場店舖,額外建立一個 Lookup Table 變數判斷國家,再決定是否啟用某些區域專屬像素(例如只在台灣載入 LINE Tag、只在印尼載入 TikTok Pixel),可以減少不必要的第三方請求。

如何驗證設定真的生效?

按順序做這五項檢查:

  1. GTM Preview 模式:開啟 Tag Assistant,載入店面。在左側事件列點擊任一事件,右上角有 Consent 分頁。確認初次載入時 ad_storage 為 denied、點擊接受後變 granted。
  2. Console 檢查 dataLayer:執行 dataLayer.filter(i => i[0] === 'consent'),應看到一組 default 與一組 update。
  3. 網路請求檢查:在 DevTools Network 篩選 collect?v=2,未同意時的 GA4 請求應包含 gcs=G100(拒絕)或 G111(全部允許)。gcd 參數則反映 v2 的四個狀態。
  4. Shopify cookie 檢查:Application → Cookies 查看 _tracking_consent,解碼後應與 CMP 顯示一致。
  5. 結帳流程:用測試訂單走完整個 checkout,確認 purchase 事件在同意情況下送出、在拒絕情況下不送出。

Ready to Transform Your Ecommerce Operations?

Branch8 specializes in ecommerce platform implementation and AI-powered automation solutions. Contact us today to discuss your ecommerce automation strategy.

常見問題排查

代碼在同意前就觸發

通常是 GTM 容器碼被放在 default consent 之前,或有 app 在 theme.liquid 上方注入了自己的腳本。檢查 view-source,確認 consent 區塊確實是 <head> 第一個 <script>。

visitorConsentCollected 永不觸發

多數情況是沒有呼叫 Shopify.loadFeatures 載入 consent-tracking-api,或 Customer privacy 設定中並未為該訪客所在地區啟用 banner。香港 IP 在預設設定下不會看到 banner,需在 Settings → Customer privacy → Region visibility 手動加入香港。

GA4 即時報表流量暴跌

這通常是預期行為而非錯誤——歐洲區在同意前不再寫入 cookie。確認 Google Ads 與 GA4 已啟用建模(modelling)。根據 Google Analytics 說明文件,行為建模需要資源連續達到一定的每日事件門檻才會啟動,小型站點可能無法補回缺口。

Custom Pixel 完全沒載入

檢查 pixel 的 Permission 設定。若設為 Marketing 而訪客拒絕了行銷同意,Shopify 會直接不載入該 pixel——這時你在 console 看不到任何錯誤,只是安靜地不執行。

多幣別/多地區店舖狀態不一致

Shopify Markets 下的不同地區使用同一個 theme.liquid。若你需要按市場差異化 default consent,用 {{ localization.country.iso_code }} 在 Liquid 層輸出地區,再於 JS 判斷。

跨境營運的實務考量

我們曾協助一個從香港出發、同時經營歐洲與東南亞市場的多品牌零售集團整理 Shopify Plus 的追蹤層。當時的狀況很典型:歐洲站用 OneTrust、亞洲站用 Shopify 內建 banner、結帳仍停在舊版 checkout.liquid 的 additional scripts。處理方式是先把所有結帳追蹤遷移到 Web Pixels API,再讓 CMP 單向寫回 setTrackingConsent,最後用 GTM 的 consent overview 逐個代碼補上 additional consent checks。工具層面用的是 GTM Web 容器搭配 Cloud Run 上的 server-side 容器;最花時間的不是寫程式,而是盤點歷年累積、散落在 apps 與主題檔案中的第三方像素。

對於總部在美國或歐洲、但把數位營運放在亞洲的團隊,這類設定有一個結構性優勢:亞太時區可以在歐美團隊下班後完成 GTM 版本發佈與 QA,第二天早上直接看驗證報告。而對香港、新加坡出海的品牌,提早把同意訊號做對,等於為進入歐盟市場預先鋪好路,不必在廣告帳戶已經累積資料後才回頭補救。

Ready to Transform Your Ecommerce Operations?

Branch8 specializes in ecommerce platform implementation and AI-powered automation solutions. Contact us today to discuss your ecommerce automation strategy.

上線後的維護清單

  • 每季重新執行一次第三方像素盤點——新安裝的 Shopify app 經常自帶未受同意管制的 pixel。
  • GTM 版本發佈時附上變更說明,方便日後追查同意行為異動。
  • 監控 GA4 的 gcs 參數分佈,同意率突然變化通常代表 banner 或 CMP 出了問題。
  • 留意 Shopify 對 checkout.liquid 的淘汰時間表,以及 Google 對同意模式參數的更新公告。

如果你的 Shopify Plus 店舖需要一次過整理同意模式、Web Pixels 遷移與 server-side 追蹤,Branch8 在香港、新加坡、台灣與澳洲都有電商工程團隊,可以按市場分工處理合規與追蹤架構。歡迎聯絡我們討論你的現況。

Sources

FAQ

如果你的 Shopify Plus 店舖有任何來自 EEA 或英國的流量,並使用 Google Ads 或 GA4,就必須設定,這是 Google 的 EU User Consent Policy 要求而非香港法規要求。即使目前只做亞洲市場,提早設定可避免日後進入歐盟時重做整個追蹤層。

About the Author

Matt Li

Co-Founder & CEO, Branch8 & Second Talent

Matt Li is Co-Founder and CEO of Branch8, a Y Combinator-backed (S15) Adobe Solution Partner and e-commerce consultancy headquartered in Hong Kong, and Co-Founder of Second Talent, a global tech hiring platform ranked #1 in Global Hiring on G2. With 12 years of experience in e-commerce strategy, platform implementation, and digital operations, he has led delivery of Adobe Commerce Cloud projects for enterprise clients including Chow Sang Sang, HomePlus (HKBN), Maxim's, Hong Kong International Airport, Hotai/Toyota, and Evisu. Prior to founding Branch8, Matt served as Vice President of Mid-Market Enterprises at HSBC. He serves as Vice Chairman of the Hong Kong E-Commerce Business Association (HKEBA). A self-taught software engineer, Matt graduated from the University of Toronto with a Bachelor of Commerce in Finance and Economics.