Note: This reference describes the methods that you use for ecommerce in Google Analytics reporting. For more information on setting up ecommerce tracking, see Ecommerce Tracking.
GATC Ecommerce Methods
_addItem(transactionId, sku, name, category, price, quantity)
_addTrans(transactionId, affiliation, total, tax, shipping, city, state, country)
_trackTrans()
Method Details
_addItem()
- Calculate quantities with your own software.
- In the same session, duplicate items added (by SKU) do not affect the quantity calculation.
- In the same session, if two items are added where each have the same SKU, the first item information is replaced with the 2nd.
- 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 aname
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.
- While the
_addItem(transactionId, 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 transactionId
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:
_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 ]);
parameters
String transactionId
Optional Order ID of the
transaction to associate with item.
String sku
Required. Item's
SKU code.
String name
Required. Product name. Required
to see data in the product detail report.
String category
Optional. Product category.
String price
Required. Product
price.
String quantity
Required. Purchase
quantity.
_addTrans()
_addTrans(transactionId, 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.
_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 ]);
parameters
String transactionId
Required.
Internal unique transaction ID number for this transaction.
String affiliation
Optional. Partner
or store affiliation (undefined if absent).
String total
Required.
Total dollar amount of the transaction. Does not include tax and shipping
and should only be considered the "grand total" if you explicity include
shipping and tax.
String tax
Optional. Tax amount
of the transaction.
String shipping
Optional. Shipping
charge for the transaction.
String city
Optional. City to associate
with transaction.
String state
Optional. State to
associate with transaction.
String country
Optional. 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.
_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']);