My favorites | English | Sign in

Google Analytics

Tracking API: Ecommerce

This reference describes the methods that you use for customizing ecommerce in Google Analytics reporting. For more information on setting up ecommerce tracking, see Ecommerce Tracking under "Setting Up Analytics."

GATC Ecommerce Methods

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

Method Details

_addItem()

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

    Use this method to track items purchased by visitors to your ecommerce site. This method tracks individual items by their SKU. This means that the sku parameter is required. This method then associates the item to the parent transaction object via the orderId argument. Arguments for this method are matched by position, so be sure to supply all parameters, even if some of them have an empty value.

    This method performs no additional calculations, such as quantity calculations. Therefore, you should keep in mind the following best practices:

    • Calculate quantities with your own software.
      • Duplicate items added by SKU do not affect the quantity calculation.
      • If two items are added, where each have the same SKU, the old information is replaced with the new.
    • Ensure that each item in your inventory has a unique SKU.
      • If your inventory has different items with the same SKU, and a visitor purchases both of them, you will receive data for only the most recently added.
    • Make sure that a parent transaction object is set up for items added.
      • If no parent transaction object exists for an added item, the item is attached to an empty transaction object instead.
      • If an item is added without a parent transaction object, your reports will show products by SKU that are not associated with any transaction.
    • Supply a value for the name parameter at all times.
      • While the name parameter is not required, items added to a transaction without a name parameter do not appear in the product breakdown for a transaction. While you will still see the total revenue for the transaction, you will not be able to see how much revenue a particular item contributed to the transaction total.
       pageTracker._addItem(
          '1234',         // order 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
       );

    parameters

      String   orderId Order ID of the transaction to associate with item.
      String   sku Required. Item's SKU code.
      String   name Product name. Required to see data in the product detail report.
      String   category Product category.
      String   price Required. Product price.
      String   quantity Required. Purchase quantity.

_addTrans()

    _addTrans(orderId, affiliation, total, tax, shipping, city, state, country)
    Creates a transaction object with the given values. As with _addItem(), this method handles only transaction tracking and provides no additional ecommerce functionality. Therefore, if the transaction is a duplicate of an existing transaction for that session, the old transaction values are over-written with the new transaction values. Arguments for this method are matched by position, so be sure to supply all parameters, even if some of them have an empty value.
       pageTracker._addTrans(      
          '1234',           // order 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
       );
    

    parameters

      String   orderId Required. Internal unique order id number for this transaction.
      String   affiliation Partner or store affiliation (undefined if absent).
      String   total Required. Total dollar amount of the transaction.
      String   tax Tax amount of the transaction.
      String   shipping Shipping charge for the transaction.
      String   city City to associate with transaction.
      String   state State to associate with transaction.
      String   country Country to associate with transaction.

    returns

      _gat.GA_EComm_.Transactions_ The transaction object that was created or modified.

_trackTrans()

    _trackTrans()
    Sends both the transaction and item data to the Google Analytics server. This method should be called after _trackPageview(), and used in conjunction with the _addItem() and addTrans() methods. It should be called after items and transaction elements have been set up.
    var pageTracker = _gat._getTracker('UA-12345-1');
    pageTracker._trackPageview();
    pageTracker._addTrans(
       '1234',           // order 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
    );
    pageTracker._addItem(
       '1234',           // order 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
    );
    pageTracker._trackTrans();