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
Name | Description | Type | Default |
---|---|---|---|
Transaction ID | The unique identifier for the transaction | String/Number | undefined |
Transaction Options | Options for the transaction | Object | {} |
Items | A list of items/products that have been purchased in this transaction | Array 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.
Key | Description | Type | Default |
---|---|---|---|
revenue | The total revenue from this transaction | String/Number | Sum of revenue from items (or 0 ) |
quantity | The total number of items ordered | Number | Sum of the quantity from items (or 0 ) |
Item Properties
Key | Description | Type | Default |
---|---|---|---|
name | The name of the item/product | String | undefined |
category / categories | The category (String) or categories (Array) the item belongs to | String/Array | undefined |
revenue | The total revenue from this item | String/Number | 0 (or price x quantity ) |
quantity | The total number of this item ordered | Number | 1 |
price | The price per item | String/Number | 0 |
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();
});