Transaction

Track a transaction

POSTtracking/transaction

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

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

If a transaction ID is specified, it will be checked for uniqueness to prevent duplicate transactions from being tracked.

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.

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.

POST Body

visitor_id

String

The anonymous visitor ID that this action is associated with.

timestamp

String

A valid ISO 8601 timestamp of when this transaction happened

page

Object

url

String

title

String

previous

Number

The index of the previous page, which will be immediately unloaded

index

Number

The page index that this event is associated with

referrer

String

ip

String

IP address of the visitor. Used to detect the visitor's location

character_set

String

language

String

user_agent

String

returning

Boolean

screen

Object

height

Number

width

Number

pixel_ratio

Number

Screen DPR

depth

Number

Screen colour depth

scroll

Object

top

Number

left

Number

max

Object

The furthest the user has scrolled on the page during this session

top

Number

left

Number

document

Object

height

Number

width

Number

viewport

Object

height

Number

width

Number

campaign

Object

name

String

source

String

medium

String

content

String

term

String

location

Object

timezone_offset

Number

last_pageview

String

ISO 8601 timestamp of when this visitor/person last did a pageview

total

Object

visits

Number

pageviews

Number

person_id

String

The People person ID that this action is associated with.

If the identifier used is an email it should be prefixed with email: like this: email:jon@example.com

transaction

ObjectRequired

id

String

revenue

Number

The total revenue from this transaction, defaults to the sum of item revenues

quantity

Number

The total number of units sold, defaults to the sum of item quantities

previous_transaction_timestamp

String

ISO 8601 timestamp of when this visitor/person last completed a transaction

items

Array

name

String

The name of this item

price

NumberDefault Value: 0

The price per unit

quantity

NumberDefault Value: 1

The number of units sold

revenue

Number

The total revenue of this item. Defaults to price ✕ quantity

categories

Array

A list of categories that this item/product is in

Definition

POST https://api.gosquared.com/tracking/v1/transaction

Example Request

var transactionID = 'transaction-id';

var opts = {
  // 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: 6
};
var transaction = gosquared.createTransaction(transactionID, opts);
transaction.addItems([
  {
    name: 'Product 1',
    price: 1,
    quantity: 4
  },
  {
    name: 'Product 2',
    price: 56,
    category: 'Test Products'
  }
]);

transaction.track(function(err, resp) {

});


// Associate transaction with a user

var person = gosquared.createPerson('user-id');
var transaction = person.createTransaction('transaction-id');
transaction.addItem({
  name: 'Product 1',
  price: 1,
  quantity: 5
});

transaction.track(function(err, resp) {

});

Live Responseundefined undefined

Your API Key is not authorised for this endpoint