設定 Google 代碼

Google 代碼可讓您將網站資料傳送到已連結的 Google 產品目的地,以便評估網站和廣告的成效。目前您只能透過 Google Ads 和 Google Analytics (分析) 4 存取及設定 Google 代碼。

Google 代碼管理工具尚未支援所有 Google 代碼功能。瞭解詳情

A concept illustration demonstrating how to set up your Google tag.

由於 Cookie 等網站技術會因隱私權、瀏覽器和法規變動而持續演進,因此如果想取得最準確的評估結果,就必須加入高品質的全網站代碼。

如要開始收集資料,您必須在網站的程式碼中加入 Google 代碼。Google 代碼必須安插在您要收集資料的每個網頁上。

Google 代碼設定完成後,您可以:

  1. 配置 Google 代碼設定
  2. 管理 Google 代碼 (選用)
  3. 管理 Google 代碼使用者 (選用)
注意:所有全域網站代碼皆已轉換為 Google 代碼。如果您已在網站上加入全域網站代碼,不必更新網站就能使用 Google 代碼

如要以您的語言顯示字幕,請開啟 YouTube 字幕。選取影片播放器底部的設定圖示 YouTube 設定圖示的圖片,接著點選「字幕/CC」,然後選擇所需語言。


什麼是目的地?

目的地」是已連結的 Google 評估產品帳戶,採用與特定代碼相同的設定,且會從該代碼接收資料。「目的地 ID」則是用於代表目的地 (亦即已連結的 Google 產品) 的 ID。代碼主要會使用這類 ID 載入目的地專屬設定,以及轉送事件。

目的地目前只能是:

  • Google Ads 帳戶
  • Google Analytics (分析) 4 資源中的網站資料串流

如何查看代碼 ID

「設定」分頁的「您的 Google 代碼」部分會列出所有代碼 ID。

An illustration demonstrating where to locate Tag IDs on Google tag.

代碼 ID代碼 ID是您為了載入特定代碼,而在網頁上加入的 ID。代碼 ID 會顯示在 Google 代碼「設定」分頁左側的 Google 代碼下方。根據預設,如果只有一個目的地,就只會顯示一個代碼 ID。

一個代碼可有多個 ID。系統會顯示「主要」ID。有時候,您會在合併代碼後看到多個代碼 ID。移除目的地並不會變更現有的代碼 ID。

注意:如果您合併或分割代碼,標記操作說明程式碼片段中顯示的主要代碼 ID 可能會有所變更。此時,您不需要在網頁中重新加入代碼。只要網頁上有其中一個代碼 ID,這個 ID 就會載入相同的代碼。如果您想透過 CMS 整合 (又稱「網站製作工具」) 部署代碼,但 CMS 整合不接受 GT- 代碼 ID,這種做法就很有幫助。您可以使用 CMS 整合支援的別名 (AW-XXXXX 或 G-XXXXX)。

目的地 ID目的地 ID 用於代表已連結的 Google 產品,可決定哪些 Google 產品帳戶會接收這個代碼所傳送的事件。

Google Ads 的目的地 ID 通常與轉換追蹤 ID 相同,Google Analytics (分析) 的目的地 ID 則通常與網站資料串流的評估 ID 相同。

如要查看目的地 ID,請按一下目的地名稱。「管理 Google 代碼」分頁的「目的地」部分會列出所有目的地及其 ID 和新增日期。代碼 ID 最多可以連結 10 個目的地。

按照 Google Ads 操作說明設定 Google 代碼

設定 Google 代碼前,請確認您已為網站設定轉換追蹤。在「設定 Google 代碼」頁面上,選取最符合自身情況的選項,然後按照操作說明安插代碼:
  1. 使用網站上的 Google 代碼 (建議)
  2. 使用現有的 Google 代碼
  3. 安插 Google 代碼

使用網站上的 Google 代碼 (建議)

使用網站上偵測到的代碼完成設定,不必修改網站程式碼。帳戶的使用者會新增為代碼的使用者。進一步瞭解如何管理 Google 代碼

  1. 按一下「詳情」查看代碼詳情。
  2. 按一下「完成」。

注意:建議您不要在網站的每個網頁中加入多個 Google 代碼。

使用現有的 Google 代碼

這個選項會顯示系統是否在您輸入的網站上偵測到該代碼。選擇標有「在網站內」字樣的代碼完成設定,不必修改網站程式碼。

請注意,如果網站流量偏低,代碼可能會顯示為「偵測不到」。如果您選擇標示為「偵測不到」的代碼,則可能需要自行安插代碼。帳戶的使用者會新增為代碼的使用者。進一步瞭解如何管理 Google 代碼

如果您對列出的代碼擁有管理員存取權,就能找到這些代碼。如果找不到所需代碼,可能是因為您沒有適當的使用者權限,無法修改該 Google 代碼。

  1. 按一下「選擇代碼」探索下列項目:
    1. 您擁有管理員存取權的代碼清單
    2. 代碼編號
    3. 偵測到代碼的位置
      • 如果系統在您輸入的網站上偵測到代碼,您就可以選擇標有「在網站內」字樣的代碼來完成設定,不必修改網站程式碼。如果您選擇標示為「偵測不到」的代碼,則可能需要自行安插代碼。
  2. 選取要使用的 Google 代碼,然後按一下「確認」

安插 Google 代碼

安插 Google 代碼的方式有 2 種:

使用網站製作工具

您可以使用網站製作工具或內容管理系統 (CMS) (如 Wix 或 Duda) 部署 Google 代碼。選取所需網站製作工具,然後按照操作說明完成 Google 代碼的設定,無須變更程式碼。如果您要透過 CMS 或網站製作工具整合部署代碼,但 CMS 整合不接受 GT 代碼 ID,您可以使用 CMS 整合支援的別名 (AW-XXXXX 或 G-XXXXX)。

如果透過以下任一平台管理網站,無須變更程式碼就能完成 Google 代碼設定:

進一步瞭解如何使用網站製作工具安插 Google 代碼

安插完成後:

  1. 按一下「完成」,Google 將會掃描您的網站。
  2. 按一下「完成」來完成 Google 代碼設定。

手動安裝

如果您是第一次在帳戶中為轉換動作設定代碼,且尚未安插 Google 代碼,請選擇這個選項。

  1. 如要安插代碼,請複製代碼並貼入網站每個網頁的程式碼,緊接在 <head> 元素後方。每個網頁只能加入一個 Google 代碼。動畫:示範如何在 Google Ads 中加入 Google 網站代碼以進行轉換追蹤。 在以下的 Google 代碼範例中,「TAG_ID」代表 Google Ads 帳戶專用的代碼 ID:

    <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>
  2. (選用) 按照自己的需求修改 Google 代碼:
    1. 如果您不希望 Google 代碼在網頁初次載入時,將網站訪客加進再行銷名單,請將下方醒目顯示的部分加進 Google 代碼的 'config' 指令中:
      gtag('config',' TAG_ID',{'send_page_view': false});
    2. 如果不希望 Google 代碼在網站網域上設定第一方 Cookie,請將下方醒目顯示的部分加進 Google 代碼的 'config' 指令中:
      gtag('config',' TAG_ID',{'conversion_linker': false});
      • 注意:我們不建議這麼做,因為這會導致轉換評估的準確度降低。如要停用再行銷資料收集功能,請將下方醒目顯示的 gtag('set') 指令加進 Google 代碼中 gtag('js') 指令的上方,這樣就能讓所有已設定的 Google Ads 帳戶停止蒐集再行銷資料。
        <script async
        src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
        <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('set', 'allow_ad_personalization_signals', false);
        gtag('js', new Date());
        gtag('config', 'TAG_ID');
        </script>
  3. 複製 Google 代碼並加進您的網站
  4. 找出客戶在網站上完成轉換後到達的網頁 (例如「感謝購買」頁),並開啟該頁的 HTML 程式碼。這類網頁也就是所謂的「轉換頁」。
  5. 在網頁的 head 代碼 (<head></head>) 之間貼上全域網站代碼,接著貼上適用該網頁的任何事件程式碼片段。
  6. 儲存您對網頁所做的變更。
  7. 按一下 [完成]。
  8. 按一下「安插事件代碼」
  9. 在「事件程式碼片段」旁,選擇要追蹤網頁載入還是點擊所帶來的轉換。
    • 網頁載入:在客戶造訪轉換頁 (如購物或註冊確認頁) 時計算轉換。這是預設選項,也是最常用的選項。進一步瞭解 Google 安全性標準
    • 點擊:在客戶點選按鈕或連結 (例如「立即購買」按鈕) 時計算轉換。GIF 動畫,呈現事件程式碼片段偏好設定的編輯方式。
  10. 複製事件程式碼片段,然後按照操作說明將程式碼片段加進網站;如果想稍後再加入,請點選「下載程式碼片段」。
    • 如果您追蹤的是網頁載入轉換,請將事件程式碼片段加進要追蹤的網頁。
    • 如果您追蹤的是點擊轉換,請將事件程式碼片段加進要追蹤點擊的按鈕或連結所在的網頁。
  11. 點選「下一步」。
  12. 按一下「完成」。GIF 動畫,呈現 Google Ads 使用者介面中事件程式碼片段的複製或下載選項。
  13. 按一下 [Finish],如果您是追蹤網站上的點擊轉換,請按照「追蹤網站點擊轉換」一文的操作說明,將另一段程式碼加入要追蹤的按鈕或連結中。您必須採取這個步驟,轉換追蹤功能才會運作。
注意:建議您不要在網站的每個網頁中加入多個 Google 代碼。

代碼設定完成後,您必須配置 Google 代碼設定

您可以啟動 Tag Assistant 來測試轉換動作/資料收集。

按照 Google Analytics (分析) 操作說明設定 Google 代碼

您在 Google Analytics (分析) 中設定 Google 代碼的方法取決於:您是否第一次在網站上設定 Analytics (分析);或者您是否要在已有通用 Analytics (分析) 的網站中加入 Google Analytics (分析) 4 資源。

如果您是第一次設定 Google Analytics (分析)

  1. 登入 Google Analytics (分析) 帳戶
  2. 按一下「管理」
  3. 使用「資源」欄頂端的下拉式選取器,選擇要在哪個資源設定資料串流的 Google 代碼。
  4. 在「資源」欄中,按一下「資料串流」
  5. 按一下要編輯的資料串流。
  6. 在「Google 代碼」下方,按一下「進行代碼設定」
  1. 在「您的 Google 代碼」部分,按一下「安裝操作說明」
  2. 在「安裝操作說明」頁面中,選取「使用網站製作工具加入代碼」或「手動安裝」:
    • 如果您透過網站製作工具 (亦即「CMS 平台」,例如 Wix 或 Wordpress) 管理網站,請採用「使用網站製作工具加入代碼」。選取所需網站製作工具,然後按照操作說明完成 Google 代碼的設定,無須變更程式碼。
    • 如果您選擇手動安插,請前往「手動安插」部分。畫面上會顯示帳戶 Google 代碼的 JavaScript 程式碼片段。如要連結您的網站與 Google Analytics (分析),請複製整個 Google 代碼片段,然後貼到網站的每個網頁上,緊接在 <head> 元素後方。Google 代碼是指系統顯示的一整段程式碼,開頭為:

      <!-- 全域代碼 (gtag.js) -->

      且結尾為

      </script>
注意:建議您不要在網站的每個網頁中加入多個 Google 代碼。

系統最多可能需要 30 分鐘才會開始收集資料。接著,您可以透過即時報表來確認資料是否已開始傳入。

代碼設定完成後,您必須配置 Google 代碼設定

您可以啟動 Tag Assistant 來測試轉換動作/資料收集。

如果您要在已有通用 Analytics (分析) 的網站中加入 Google Analytics (分析) 4 資源

您可以使用 GA4 設定輔助程式,在已有通用 Analytics (分析) 的網站中加入 Google Analytics (分析) 4 資源。您必須具備 Analytics (分析) 帳戶的編輯者角色。請按照以下操作說明建立 GA4 資源。無論您的網頁有 Google Analytics (分析) 代碼 (gtag.js 或 analytics.js)、Google Ads 代碼 (gtag.js) 還是 Google 代碼管理工具容器,都可以使用這個精靈。

  1. In Google Analytics, click 設定 Admin (lower left).
  2. In the Account column, make sure that your desired account is selected. (If you only have one Google Analytics account, it's already selected.)
  3. In the Property column, select the Universal Analytics property that currently collects data for your website.
  4. In the Property column, click GA4 Setup Assistant. It's the first option in the Property column.
  5. Click Get started under I want to create a new Google Analytics 4 property.
  6. In the Create a new Google Analytics 4 property pop-up screen, you'll have one of the following options, depending on how your site is currently tagged:
  7. On the Set up a Google tag page, select the option that best describes your situation and follow the instructions to finish creating your new GA4 property:
     

    Use the Google tag found on your website (Recommended)

    Select this option to use the Google tag detected on your website to complete setup without making changes to your site's code.

    If desired, click Details to view your tag details.

    Click Confirm to finish creating your new GA4 property.

    Users on your property will be added as users on the Google tag. Learn more about managing your Google tag.

    Use a Google tag you already have

    Select this option to reuse a Google tag that you already have admin access to.

    Click Choose a tag. You'll see:

    • A list of tags you have admin access to. (If you don't see the tag you are looking for, you might not have the appropriate user permissions to make changes to that Google tag.)
    • Tag IDs
    • Whether or not the tag was detected on your website. Choose a tag labeled "On site" to complete setup without making changes to your site's code. If you choose a tag labeled "Not detected", you might need to install it. (Note that if your site has low traffic volume, your tag may be shown as "Not detected".)
    • The destinations that are associated with the tag

    Select the Google tag you want to use, then click Confirm to finish creating your new GA4 property.

    Users on your property will be added as users on the tag. Learn more about managing your Google tag

    Install a Google tag

    Select this option if you don't have the Google tag installed on your website.

    1. Click Next to install a new Google tag on your website.
    2. On the Installation instructions page, you have 2 options:
      • Install with a website builder: If you manage your site using certain website builders (or "CMS platforms," like Wix or Duda), you can finish setting up your Google tag without making changes to your code.
      • Install manually: Choose this option if one of the following is true:
        • Your website builder/CMS does not yet support the Google tag (gtag.js)
        • You or your web developer are manually tagging your website
        • Your website is tagged with analytics.js
        • You use Google Tag Manager

    Option 1: Install with a website builder or CMS

    If you manage your site using one of the following platforms, select your platform and follow the instructions  to finish setting up your Google tag without making changes to your code.

    When you've finished installing your Google tag, click Done to finish creating your new GA4 property.

    If your platform doesn't yet support the Google tag, you can use the manual installation option (below).

    We're continually updating our CMS instructions to make it as easy as possible for you to set up your Google tag. If you don't see your platform on the Installation instructions page, you might still be able to paste your Google tag ID into your website builder or CMS. Before installing manually, check for your platform on this list 

    Learn more about installing your Google tag with a website builder.

    Option 2: Install manually

    Choose this option if one of the following is true:

    How to manually install the Google tag

    On the Install manually tab, you'll see the JavaScript snippet for your Google tag. To establish a connection between your website and Google Analytics, copy and paste your entire Google tag in the code of every page of your website, immediately after the <head> element. Don’t add more than one Google tag to each page.

    If you're using a website builder/CMS that doesn't yet support the Google tag, copy and paste your entire Google tag  using your platform's custom HTML field.

    Your Google tag is the entire section of code that appears, beginning with:

    <!-- Google tag (gtag.js) -->

    and ending with

    </script>

    When you've finished installing your Google tag on your website, click Done to finish creating your new GA4 property.

    When you've set up your tag, you need to configure your Google tag settings

    If your website is tagged with analytics.js, either manually or with a CMS

    If your website is manually tagged with analytics.js, don't remove the old analytics.js tag when you add the Google tag (above). The analytics.js tag will continue to collect data for your Universal Analytics property. The Google tag (gtag.js) that you're adding will collect data for your new GA4 property.

    If you're using a website builder/CMS that tags your pages with analytics.js, you can use the custom HTML feature to add the Google tag to your pages. Leave the analytics.js tag in place so that Analytics still sends data to your Universal Analytics property.

    The following table lists website builders and CMSs that use analytics.js and require that you add your Google tag as custom HTML in order to have both tags on your site.

    請使用 CMS 的自訂 HTML 功能,複製 Google 代碼並貼入網站中。

    使用即時報表來確認資料是否已開始傳入。

    網站製作工具/CMS 新增自訂 HTML 的選項
    Blogger 操作說明
    Cart.com 如需操作說明,請與 Cart.com 支援團隊聯絡
    Salesforce (Demandware) 如需操作說明,請與 Salesforce 支援團隊聯絡
    VTEX 如需操作說明,請與 VTEX 支援團隊聯絡
    Weebly 操作說明
    If you add your tag using Google Tag Manager

    For basic data collection, follow the Google Tag Manager help center instructions to add the Google Analytics: GA4 Configuration tag using your Google Tag Manager account.

    After you're finished, make sure to click Done in the GA4 Setup Assistant to finish creating your connected GA4 property.

找不到代碼

目的地可能會處於未附加至 Google 代碼的狀態。該目的地必須連結至 Google 代碼,才能接收資料。

如果目的地未連結至任何標記,您會在開啟 Google 代碼頁面時收到通知。此時,您可以選擇將目的地連結至現有的 Google 代碼,或建立新的 Google 代碼。

相關連結

這對您有幫助嗎?
我們應如何改進呢?
搜尋
清除搜尋內容
關閉搜尋
Google 應用程式
主選單
搜尋說明中心
true
true
false
true
true
102259