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 the required sku parameter. However, it 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 ecommerce calculations, such as quantity calculations. Therefore, if the item being added is a duplicate (by SKU) of an existing item for that session, then the old information is replaced with the new. Additionally, while the _addItem() method does not enforce the creation of a parent transaction object, you should set this up explicitly in your transaction tracking code. If no parent transaction object exists for an added item, the item is attached to an empty transaction object instead. In this case, your reports will show products by SKU that are not associated with any transaction.

       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
    );

    parameters

      String   orderId Order ID of the transaction to associate with item.
      String   sku Required. Item's SKU code.
      String   name Product name.
      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
    "11.99", // 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
    "11.99", // 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();