將 Shopify 商店的 Google Ads 和 Google Analytics 評估遷移至 Google & YouTube 應用程式後,請務必移除先前安裝的重複代碼。如果您目前是針對透過自訂像素追蹤的 Shopify 轉換出價,請將轉換動作切換為由 Google & YouTube 應用程式評估的轉換動作。進一步瞭解如何將代碼遷移至 Google & YouTube 應用程式。
如果未移除重複代碼,可能會發生下列情況:
- 重複追蹤
- 資料不正確
- 對廣告活動最佳化造成負面影響
如何修正問題
請參閱下列各節的操作說明,瞭解如何根據代碼的導入位置移除重複的代碼:
移除重複的自訂像素廣告代碼
Google Analytics [Video] Remove duplicate custom pixel 2nd entry
- 在 Shopify 管理頁面中,依序前往「Settings」和「Customer events」。
- 找出要停用的自訂像素。
- 按一下像素旁的「Disconnect」。
- 如要徹底移除像素,請按一下「Delete」,然後確認刪除。
從其他指令碼中移除重複的直接代碼
注意:Shopify 管理頁面中的「Order status page additional scripts」部分無法展開。如果這個部分有很多程式碼,建議您將程式碼複製並貼到外部文字編輯器工具,然後找出要停用的特定指令碼。
如果您已升級感謝頁面,新版結帳程序將無法再存取或支援其他指令碼。這些指令碼應該會自動停止運作,因此不需要手動移除。
- 在 Shopify 管理頁面中,依序前往「Settings」和「Checkout」。
- 在「其他指令碼」部分,找出要移除的指令碼。
- 按一下「停用指令碼」。
- 檢查 Google 代碼,確認系統是否仍收到事件。
從 checkout.liquid 中移除重複的直接代碼
如果您已升級感謝頁面,新版結帳程序將無法再存取或支援 check.liquid 指令碼。這些指令碼應該會自動停止運作,因此不需要手動移除。
Google Analytics [Video] Remove duplicate direct tags from checkout liquid All steps
步驟 1:備份主題
Google Analytics [Video] Remove duplicate direct tags from checkout liquid Step 1
- 在 Shopify 管理頁面中,依序前往「Online Store」和「Themes」。
- 找出目前使用的主題 (標示為「Current theme」),然後依序點按三點圖示和「Duplicate」。這會建立主題的完整副本,因此如果發生任何問題,您就可以還原到該主題。
步驟 2:存取 checkout.liquid
Google Analytics [Video] Remove duplicate direct tags from checkout liquid Step 2
- 在 Shopify 管理頁面中,依序前往「Online Store」和「Themes」。
- 找出目前使用的主題 (標示為「Current theme」),或您剛建立的重複副本 (如果您想使用該副本),然後依序點按三點圖示和「Edit code」。
- 在左側邊欄中,向下捲動至「Layout」部分,然後按一下
checkout.liquid。
步驟 3:找出並移除重複的代碼
Google Analytics [Video] Remove duplicate direct tags from checkout liquid Steps 3 4
請仔細找出先前用於追蹤,但現在由 Google & YouTube 應用程式處理的代碼。這些代碼通常包括 Google Analytics、Google Ads 轉換評估、Merchant Center、Floodlight,且可能包括 Google 代碼管理工具。請按照下列步驟找出並移除重複的代碼:
應尋找 (並移除) 的常見程式碼片段:
- 舊版 Google Analytics (通用 Analytics 或 GA4) 代碼
找出含有 google-analytics.com/analytics.js 的指令碼代碼。
- 通用 Analytics (UA-XXXXX-Y):
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
gtag.js適用於 Google Analytics (GA4)、Google Ads 轉換追蹤、Merchant Center 或 Floodlight:找出含有 googletagmanager.com/gtag/js? 的<script>代碼。
<script async src="https://www.googletagmanager.com/gtag/js?id=X-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'X-XXXXXXXXXX');
</script>
- 事件程式碼片段
- 找出包含 gtag (「event」...) 的
<script>代碼
- 找出包含 gtag (「event」...) 的
<script>
gtag('event', 'XXXX', {
'send_to': 'XX-XXXXXXXXX/YYYYYYYYYY',
'value': {{ checkout.total_price | money_without_currency | remove: "," }},
'currency': '{{ shop.currency }}',
'transaction_id': '{{ order.order_number }}'
});
</script>
- Google 代碼管理工具 (GTM) 程式碼片段
- 如果您使用 Google 代碼管理工具,通常會有兩個部分:
<head>中的<script>標記,以及緊接在<body>標記後的<noscript>標記。
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>- 以及
<noscript>部分:
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>移除步驟:
- 仔細檢查
checkout.liquid檔案。捲動瀏覽檔案,找出與上述範例類似的程式碼片段。 - 反白選取與重複代碼相關聯的整個程式碼區塊。包括開頭和結尾的指令碼代碼,以及與其相關的任何註解。
- 刪除反白選取的程式碼。
重要注意事項:
- 請勿刪除重要的 Shopify Liquid 程式碼:請務必小心,不要刪除任何屬於 Shopify 核心功能的 Liquid 物件或代碼 (例如:
{{ content_for_header }}、{{ content_for_layout }}、{{ page_title }}等)。 - 尋找條件陳述式:有時追蹤代碼會包裝在
{% if first_time_accessed %}或{% if thank_you_page %}中。請在這些條件式中移除重複的代碼。 - 搜尋功能:在程式碼編輯器中使用搜尋功能 (Cmd/Ctrl + F),搜尋常見的 ID,例如
gtag、UA-、AW-、GTM-、google-analytics.com、googletagmanager.com、googleadservices.com。
步驟 4:儲存您的變更
- 刪除重複的程式碼後,按一下編輯器右上角的「Save」按鈕。
步驟 5:測試結帳程序
- 這是重要步驟,請在商店中進行測試購買。完成整個結帳程序,確認一切運作正常。
- 驗證追蹤:使用 Google Tag Assistant 等工具,驗證代碼是否只從 Google & YouTube 應用程式正確觸發,而非從
checkout.liquid檔案觸發。
如果對任何特定程式碼有問題,建議您諮詢 Shopify 專家或開發人員。
從 theme.liquid 中移除重複的代碼
Google Analytics [Video] Remove duplicate tags from theme liquid All steps
步驟 1:備份主題
- 在 Shopify 管理頁面中,依序前往「Online Store」和「Themes」。
- 找出目前使用的主題,然後按一下三點圖示,再點選「Duplicate」。這會建立主題的完整副本,因此如果發生任何問題,您就可以還原到該主題。
步驟 2:存取 theme.liquid
Google Analytics [Video] Remove duplicate tags from theme liquid Step 2
- 在 Shopify 管理頁面中,依序前往「Online Store」和「Themes」。
- 找出目前使用的主題 (或您剛建立的重複副本),然後依序點按三點圖示和「Edit code」。
- 在左側欄的「Layout」部分下方,按一下
theme.liquid。
步驟 3:找出並移除重複的代碼
Google Analytics [Video] Remove duplicate tags from theme liquid Steps 3 4
與 checkout.liquid 相同,您需要尋找與 Google Analytics、Google Ads 和 Google 代碼管理工具相關的程式碼片段,這些片段先前是由您手動新增,現在則由 Google & YouTube 應用程式處理。這些程式碼片段通常會放在 theme.liquid 檔案的 <head> 區段中。請按照下列步驟找出並移除重複的代碼:
應尋找 (並移除) 的常見程式碼片段:
- 舊版 Google Analytics (通用 Analytics 或 GA4) 代碼
找出含有 google-analytics.com/analytics.js 的指令碼代碼。
- 通用 Analytics (UA-XXXXX-Y):
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
gtag.js適用於 Google Analytics (GA4)、Google Ads 轉換追蹤、Merchant Center 或 Floodlight:找出含有 googletagmanager.com/gtag/js? 的 <script> 代碼。
<script async src="https://www.googletagmanager.com/gtag/js?id=X-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'X-XXXXXXXXXX');
</script>
- 事件程式碼片段
- 找出包含 gtag (「event」...) 的
<script>代碼
- 找出包含 gtag (「event」...) 的
<script>
gtag('event', 'XXXX', {
'send_to': 'XX-XXXXXXXXX/YYYYYYYYYY',
'value': {{ checkout.total_price | money_without_currency | remove: "," }},
'currency': '{{ shop.currency }}',
'transaction_id': '{{ order.order_number }}'
});
</script>
- Google 代碼管理工具 (GTM) 程式碼片段
- 如果您使用 Google 代碼管理工具,通常會有兩個部分:
<head>中的<script>標記,以及緊接在<body>標記後的<noscript>標記。
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>- 以及
<noscript>部分:
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>移除步驟:
- 仔細檢查
theme.liquid檔案。捲動瀏覽檔案,找出與上述範例類似的程式碼片段。這些代碼最常位於<head>區段中,但有時指令碼代碼位於<body>底部,也就是</body>結尾代碼之前。 - 反白選取與重複代碼相關聯的整個程式碼區塊。包括開頭和結尾的指令碼代碼,以及與其相關的任何註解。
- 刪除反白選取的程式碼。
重要注意事項:
- 請勿刪除必要的 Shopify Liquid 程式碼:請務必小心,不要刪除任何屬於 Shopify 核心功能的 Liquid 物件或代碼 (例如:
{{ content_for_header }}、{{ content_for_layout }}、{{ page_title }}等)。 - 尋找條件陳述式:有時追蹤代碼會包裝在
{% if template == 'index' %}或其他條件邏輯中。請在這些條件式中移除重複的代碼。 - 搜尋功能:在程式碼編輯器中使用搜尋功能 (Cmd/Ctrl + F),搜尋常見的 ID,例如
gtag、UA-、AW-、GTM-、google-analytics.com、googletagmanager.com、googleadservices.com。
步驟 4:儲存您的變更
- 刪除重複的程式碼後,按一下編輯器右上角的「Save」按鈕。
步驟 5:測試商店
- 瀏覽商店中的各種頁面 (首頁、產品頁面、系列頁面)。
- 使用 Google Tag Assistant (Chrome 擴充功能) 驗證代碼是否只從 Google & YouTube 應用程式正確觸發,而非從
theme.liquid檔案觸發。您應該會看到與 Google & YouTube 應用程式相關聯的代碼觸發,而不會再看到舊的重複代碼。
如果不確定是否要移除特定程式碼,建議您諮詢 Shopify 專家或網頁程式開發人員。
後續步驟
完成系統提示的變更後,請前往「需要處理」頁面,確認是否仍有問題;如果未列出,代表問題已解決。