追蹤程式碼:電子商務

注意:這份參考資料說明您在 Google Analytics (分析) 報表中使用電子商務的方法。如要進一步瞭解如何設定電子商務追蹤,請參閱「電子商務追蹤」一文。

GATC 電子商務方法

  • _addItem(transactionId, sku, name, category, price, quantity)
  • _addTrans(transactionId, affiliation, total, tax, shipping, city, state, country)
  • _trackTrans()

方法說明

_addItem()

    _addItem(transactionId, sku, name, category, price, quantity)

    使用這個方法,即可追蹤您電子商務網站訪客購買的商品。這個方法會依 SKU 追蹤個別商品。因此,sku 參數為必要參數。這個方法接著會透過 transactionId 引數,將項目與父項交易物件建立關聯。

    這個方法的引數與位置相符,因此即使有些參數有空白值,也請務必提供所有參數。

    這個方法不會執行其他計算,例如數量計算。因此,請謹記下列最佳做法:

    • 使用自己的軟體計算數量。
      • 在同一個工作階段中新增的重複項目 (依據 SKU) 不會影響數量計算。
      • 在同一個工作階段中新增兩個項目,且每個項目都具有相同的 SKU 時,第一個項目資訊會替換為第 2 項。
    • 確認商品目錄中的每個商品都有專屬的 SKU。
      • 如果您的商品目錄資料中有不同商品 (SKU 相同),且訪客購買了這兩個產品,您只會收到最近新增的資料。
    • 確保已為新增的項目設定父項交易物件。
      • 如果新增的項目沒有任何父項交易物件,則該項目會改為附加至空白交易物件。
      • 如果新增的項目沒有父項交易物件,報表會依 SKU 顯示與任何交易無關的產品。
    • 請一律為 name 參數提供值。
      • 雖然 name 參數並非必要,但新增至交易時沒有 name 參數的項目就不會出現在交易的產品細目中。雖然您還是可以查看交易的總收益,但無法查看特定項目對交易總收益所貢獻的收益。
       _gaq.push(['_addItem',
          '1234',         // transaction ID - necessary to associate item with transaction
          'DD44',         // SKU/code - required
          'T-Shirt',      // product name - necessary to associate revenue with product
          'Olive Medium', // category or variation
          '11.99',        // unit price - required
          '1'             // quantity - required
       ]);

    參數

      String   transactionId 選填 要與項目建立關聯的交易訂單 ID。
      String   sku 必填。項目的 SKU 代碼。
      String   name 必填。產品名稱。必須才能在產品詳細資料報表中查看資料。
      String   category 選填。產品類別。
      String   price 這是必要欄位。產品價格。
      String   quantity 必填。購買數量。

_addTrans()

    _addTrans(transactionId, affiliation, total, tax, shipping, city, state, country)
    使用指定值建立交易物件。與 _addItem() 相同,這個方法只會處理交易追蹤,不提供額外的電子商務功能。因此,如果交易與該工作階段現有交易的重複,系統會以新交易值覆寫舊交易值。這個方法的引數與位置相符,因此即使有些參數有空白值,也請務必提供所有參數。
       _gaq.push(['_addTrans',
          '1234',           // transaction ID - required
          'Womens Apparel', // affiliation or store name
          '28.28',          // total - required; Shown as "Revenue" in the
                            // Transactions report. Does not include Tax and Shipping.
          '1.29',           // tax
          '15.00',          // shipping
          'San Jose',       // city
          'California',     // state or province
          'USA'             // country
       ]);
    

    參數

      String   transactionId 必要。 這筆交易的內部專屬交易 ID 號碼。
      String   affiliation 選填。合作夥伴或商店聯盟 (如果沒有,則定義)。
      String   total 必填。 交易的總金額。不含稅金和運費,只有在明確包含運費和稅金的情況下,才應將其視為「總計」。
      String   tax 選填。交易的稅金金額。
      String   shipping 選填。交易的運費。
      String   city 選填。要與交易建立關聯的城市。
      String   state 選填。要與交易建立關聯的狀態。
      String   country 選填。要與交易建立關聯的國家/地區。

    returns

      _gat.GA_EComm_.Transactions_ 已建立或修改的交易物件。

_trackTrans()

    _trackTrans()
    將交易和項目資料傳送至 Google Analytics (分析) 伺服器。 此方法應在 _trackPageview() 之後呼叫,並與 _addItem()addTrans() 方法搭配使用。在設定項目和交易元素之後,應呼叫這個方法。
    _gaq.push(['_setAccount', 'UA-XXXXX-X']);
    _gaq.push(['_trackPageview']);
    _gaq.push(['_addTrans',
       '1234',           // transaction ID - required
       'Womens Apparel', // affiliation or store name
       '28.28',          // total - required
       '1.29',           // tax
       '15.00',          // shipping
       'San Jose',       // city
       'California',     // state or province
       'USA'             // country
    ]);
    _gaq.push(['_addItem',
       '1234',           // transaction ID - necessary to associate item with transaction
       'DD44',           // SKU/code - required
       'T-Shirt',        // product name
       'Olive Medium',   // category or variation
       '11.99',          // unit price - required
       '1'               // quantity - required
    ]);
    _gaq.push(['_trackTrans']);