Sign in

Analytics Help



How do I track e-commerce transactions?

Print
Note: This article is for the latest version of the tracking code. If you are using the older version, please read the following article.

To determine which tracking code you are using, please see Which version of the tracking code am I using?

(If you're looking for information on tracking visitor movement through your checkout pages, please read How do I use Google Analytics to track a 3rd-party shopping cart?)

Enabling E-Commerce Reporting in the Profile

The first step of tracking e-commerce transactions is to enable e-commerce reporting for your website's profile. To enable e-commerce reporting, please follow these steps:

  1. Log in to your account.
  2. Click Edit next to the profile you'd like to enable.
  3. On the Profile Settings page, click edit next to Main Website Profile Information.
  4. Change the E-Commerce Website radio button from No to Yes.

Receipt Page Format

The second step is to ensure that the tracking code is included in the receipt page in the standard fashion. This may be done using a server side include, or other template driver, or can simply be hand-coded into your HTML code:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>

<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
} catch(err) {} </script>

Next, somewhere in the receipt below the tracking code, call the _addTrans() and _addItem() functions. Begin with a call to _addTrans() to establish a transaction. _addTrans() takes the following arguments: Order ID,Affiliation, Total, Tax, Shipping, City, State, Country. For each item that the visitor purchases, call _addItem(). _addItem() takes the following arguments: Order ID, SKU or Code, Product Name, Category, Price, Quantity.

Here is a complete example:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-XXXXX-1");
pageTracker._trackPageview();
pageTracker._addTrans(
"1234", // Order ID
"Mountain View", // Affiliation
"18.28", // Total
"1.29", // Tax
"5", // Shipping
"San Jose", // City
"California", // State
"USA" // Country
);
pageTracker._addItem(
"1234", // Order ID
"DD44", // SKU
"T-Shirt", // Product Name
"Green Medium", // Category
"11.99", // Price
"1" // Quantity
); pageTracker._trackTrans();
} catch(err) {}</script>

 

Was this information helpful?

Learn from other users

Find answers, ask questions, and share your expertise with others in the Analytics help forum.

Tell us how we're doing: Please answer a few questions about your experience to help us improve our Help Center.