使用 gtag.js 設定 Google 代碼
Google 代碼是一組代碼,可新增至網站使用
Google 成效評估和廣告產品,例如 Google Ads、Google
Analytics、Campaign Manager、多媒體廣告與Video 360 和 Search Ads 360。而不是
管理不同 Google 產品的多個代碼時,您可以使用
適用於整個網站的 Google 代碼,並將代碼連結至多個目的地。
進一步瞭解 Google 代碼
本頁將說明如何使用
gtag.js 架構如果您不熟悉 JavaScript,建議您改用
Google 代碼管理工具,而非 gtag.js。
優點
評估轉換並改善廣告價值的最佳方式
Google 行銷投資是在網站的每個網頁放置代碼。變更者:
在整個網站中導入 Google 代碼後,您就能使用下列功能:
優點:
- 符合未來趨勢的轉換評估。善用最新功能
及整合推出的功能,讓你在使用時更加得心應手
,在發生變化時準確評估轉換。
- 無程式碼的代碼管理:在 Google 中啟用評估功能
而不必手動變更網頁上的標記
- 整合更簡單更簡單、更簡潔
與其他 Google 產品 (例如
Analytics 和 Google Ads。
- 更準確的轉換評估準確度:Google 代碼可助您一臂之力
在無法使用 Cookie 的情況下,提高轉換評估的準確度,
補回目前因產業因素而未觀察到的轉換。
在網站中加入 Google 代碼
透過 Google 代碼收集資料的步驟如下:
開啟您使用的 Google 產品,並存取 Google 代碼畫面。
如何查看代碼 ID:
複製 Google 代碼 ID。
在以下程式碼範例中貼上 Google 代碼 ID。加入 Google 代碼
加進每個所需網頁,緊接在 <head>
HTML 開頭標記後面的位置
。
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TAG_ID');
</script>
必須使用 config
指令,才能將資料傳送至 Google 廣告產品。
您必須在網站上設定 config
指令才能使用許多功能,例如
自動收集的事件和轉換連結
進一步瞭解 config 指令
驗證 Google 代碼
如要確認代碼是否正在傳送資料,請按照下列步驟操作:
- 前往 tagassistant.google.com/。
- 按一下「Add domain」(新增網域)。
- 輸入要偵錯的網站網址 (開頭為「https://」)或「http://」
- 點選「連線」。
將 Tag Assistant 連結至網站後,請檢查 Google 代碼 ID
列於「找到 Google 代碼」標題中。如果 Tag Assistant 無法辨識
代碼,請前往
代碼管理工具說明中心
也可查看代碼涵蓋範圍摘要瞭解網站的
標記狀態
後續步驟
Google 代碼已設定完成,接著請設定 Google 產品並傳送事件資料。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-09-10 (世界標準時間)。
[null,null,["上次更新時間:2024-09-10 (世界標準時間)。"],[[["The Google tag is a versatile tag that streamlines the use of various Google products like Google Ads and Analytics, replacing the need for multiple individual tags."],["Implementing the Google tag offers benefits like future-proof conversion measurement, codeless tag management, easier integration with other Google products, and more accurate conversion tracking."],["To use the Google tag, copy your tag ID from a Google product (e.g., Google Ads, Analytics), paste it into the provided code snippet, and place the snippet on every page you want to track."],["Verify your Google tag implementation using Tag Assistant to ensure it's sending data correctly by checking for your tag ID and consulting the Tag Manager help center for troubleshooting."]]],["The Google tag, a single tag for Google measurement and advertising products, can be implemented across an entire website via the gtag.js framework. To set up, users need to locate their Google tag ID within Google Ads, Analytics, or Floodlight, copy it, and paste it into the provided code snippet within the `\u003chead\u003e` of each web page. Verification involves using Tag Assistant to confirm tag detection and to ensure data is being sent. Once confirmed, the tag must be configured with the config command.\n"]]