Track Transactions

Transactions

Transactions are a special type of event, used to track when a user has purchased something from you. The data is reported in the Ecommerce dashboard and in the People.

Transactions can be tracked either in the browser using the JavaScript Tracker when a user completes a purchase, or on the backend using the backend tracking modules when your application processes the transaction.

Each transaction requires an ID, which must be unique to that transaction.

Note: it is not possible to remove test transactions from your Ecommerce dashboard. Therefore we highly recommend creating a test project in your GoSquared account before you start sending data to your production project.

Parameters

NameDescriptionTypeDefault
Transaction IDThe unique identifier for the transactionString/Numberundefined
Transaction OptionsOptions for the transactionObject{}
ItemsA list of items/products that have been purchased in this transactionArray of Objects[]

Transaction Options

By default, GoSquared calculates the total revenue and quantity amount from the items in the transaction. You may want to override this in some cases, such as when a discount was applied.

This is possible by specifying revenue and quantity totals in the transaction options.

KeyDescriptionTypeDefault
revenueThe total revenue from this transactionString/NumberSum of revenue from items (or 0)
quantityThe total number of items orderedNumberSum of the quantity from items (or 0)

Item Properties

KeyDescriptionTypeDefault
nameThe name of the item/productStringundefined
category / categoriesThe category (String) or categories (Array) the item belongs toString/Arrayundefined
revenueThe total revenue from this itemString/Number0 (or price x quantity)
quantityThe total number of this item orderedNumber1
priceThe price per itemString/Number0

Usage

_gs('transaction', 'transaction-id', {
  // track immediately
  track: true,
  // if you wish to explicitly set revenue and quantity totals
  // for this transaction, specify them here. They will be used
  // instead of the default totals calculated from the items.
  // revenue: 50,
  // quantity: 5
}, [
  {
    name: 'Product 1',
    price: 1,
    quantity: 4
  },
  {
    name: 'Product 2',
    price: 56,
    category: 'Test Products'
  }
]);

The tracking code provides helper functions to make it easier to manipulate and track transactions.

The tracking code must have loaded before these can be used, using the _gs(function() ) callback.

_gs(function() {
  var transaction = _gs('transaction', 'transaction-id');

  transaction.addItems([
    {
      name: 'Product 1',
      price: 1,
      quantity: 4
    },
    {
      name: 'Product 2',
      price: 56,
      category: 'Test Products'
    }
  ]);

  transaction.addItem('Product 3', {
    revenue: 10,
    categories: [ 'Test Products', 'Random Products' ]
  });

  transaction.track();
});