Tracking API
Website personalisation: JavaScript integration
Reference
Options and parameters for the tracking API reference.
<script>
$g.track({
request_id : "{{ request_id }}", // optional (String or Number)
scope : "{{ scope }}",
action : "{{ action }}",
data : { /* specific parameters */ }
});
</script>
Parameter | Required? | Type | Description |
---|---|---|---|
request_id | Optional | String or number | A string or number containing a unique identifier. This is an optional value that you provide to the API. The API will return this value back with the response. |
scope | Required | String | A string that defines the type of tracking event being recorded. Allowed values: - view - basket - order |
action | Required | String | This string defines the type of tracking event being recorded. The allowed values are depend on the event: - basket - add, remove- order - add, cancel, return |
data | Required | Object | An object which contains information specific to the current event. The allowed values are depend on the event: - basket - product_id , quantity - order - order_id , order_total , order_currency, order_lines . See: Tracking API examples |
success | Optional | Function | A callback function which will fire upon successful completion of the tracking event. |
Tracking API examples
See some common tracking scenarios by example.
Product view
Track a product view event:
<script>
$g.track({
scope : "view",
action : "add",
data : { product_id: "{{ product_id }}" }
});
</script>
Add to basket
Track an add to basket event:
<script>
$g.track({
scope : "basket",
action : "add",
data : { product_id: "{{ product_id }}", quantity: 1 }
});
</script>
Order placed
Note
For Shopify users we are able to retrieve this data automatically via webhook and there is no need to implement order tracking.
Typically this would be placed on the order confirmation page.
The order line total is the cost of the item (after tax) x the quantity purchased.
For example, if a t-shirt cost $10.00 but the customer bought 2, then the order_line_total would be $20.00.
<script>
$g.track({
scope : "order",
action : "add",
data : {
order_id : "ABC-123",
order_total : 74.96,
order_tax : 11.66,
order_shipping : 4.99,
order_currency : "USD",
order_lines: [
{
product_id : "6560241647794",
product_sku : "blk-drss",
product_name : "Maxi Dress",
variant_id : "39380778287282",
variant_sku : "mxi-drs-red",
quantity : 1,
unit_rrp : 40.00, // if available (includes tax)
order_line_total : 49.99 // includes tax
},
{
product_id : "abc",
product_sku : "123",
product_name : "Rainbow Scarf",
variant_id : "xyz",
variant_sku : "321",
quantity : 2,
unit_rrp : 8.00, // if available (includes tax)
order_line_total : 19.98 // item price 9.99 (including tax) x quantity 2
}
]
}
});
</script>
Order cancelled
Notify Ometria of any cancelled orders.
On some ecommerce platforms this may have to be processed via webhooks instead of JavaScript.
<script>
$g.track({
scope : "order",
action : "cancel",
data : { order_id: "{{ order_id }}", }
});
</script>
Updated 2 days ago