Tamio

Tracking API

Enable tracking by pasting the Google or Meta tracking ID/snippet in the site admin under Site Settings > Tracking.

Tamio then tracks 14 built-in commerce and engagement events automatically, including product views, cart actions, checkout steps, purchases, search, login, sign-up, and page duration - see the full table below.

Developers can also use xScripts.tracking from merchant header or footer scripts to observe Tamio events, forward them to custom endpoints, or send custom events through the same consent-aware dispatcher.

Events

EventWhen It FiresGA4 EventMeta Event
View productProduct page loadsview_itemViewContent
View category/listCategory, listing, or search listing page loadsview_item_listViewItemList custom
Add to cartProduct is added to cartadd_to_cartAddToCart
Remove from cartProduct is removed from cartremove_from_cartRemoveFromCart custom
View cartCart or checkout modal opensview_cartViewCart custom
Begin checkoutCustomer continues from cart into checkoutbegin_checkoutInitiateCheckout
Add shipping infoShipping step is completedadd_shipping_infoAddShippingInfo custom
Add payment infoPayment step loadsadd_payment_infoAddPaymentInfo
PurchaseThank-you page loads after a paid orderpurchasePurchase
SearchSearch results are shown or submittedsearchSearch
LoginPortal login succeedsloginLogin custom
Sign upPortal registration succeedssign_upCompleteRegistration
Page duration milestoneVisible page time reaches a milestonepage_durationPageDuration custom
Page duration exitVisitor leaves or an attention-taking overlay opens after minimum visible timepage_duration_endPageDurationEnd custom

Default page-duration milestones are 5, 10, 30, 60, 120, and 300 seconds.

Observe Tamio Events

Use onEvent to listen to native Tamio tracking events and merchant custom events after Tamio has resolved consent and active destinations.

HTML
1<script>
2xScripts.tracking.onEvent(function (event) {
3 console.log('Tracking event:', event.type, event.data, event.targets);
4});
5</script>

The event object contains:

FieldDescription
typeGeneric event name, such as add_to_cart or purchase
dataNormalized event payload
targetsDestinations that will receive the event, such as ["google"] or ["google", "facebook"]

Forward Events To A Custom Endpoint

Use onEvent when you want your own analytics endpoint to receive the same events Tamio tracks.

HTML
1<script>
2var endpoint = 'https://example.com/tracking/tamio';
3
4xScripts.tracking.onEvent(function (event) {
5 var payload = {
6 event: event.type,
7 data: event.data,
8 targets: event.targets,
9 page_url: window.location.href,
10 page_path: window.location.pathname,
11 sent_at: new Date().toISOString()
12 };
13
14 try {
15 if (navigator.sendBeacon) {
16 var blob = new Blob([JSON.stringify(payload)], { type: 'application/json' });
17 if (navigator.sendBeacon(endpoint, blob)) return;
18 }
19
20 fetch(endpoint, {
21 method: 'POST',
22 headers: { 'Content-Type': 'application/json' },
23 body: JSON.stringify(payload),
24 keepalive: true
25 }).catch(function () {});
26 } catch (error) {
27 console.warn('Custom tracking endpoint failed:', error);
28 }
29});
30</script>

Transform And Forward Events

You can also listen for a Tamio event, build your own payload, and send that version to a custom endpoint.

HTML
1<script>
2var endpoint = 'https://example.com/tracking/purchase';
3
4xScripts.tracking.onEvent(function (event) {
5 if (event.type !== 'purchase') return;
6
7 var payload = {
8 order_id: event.data.transaction_id,
9 total: event.data.value,
10 currency: event.data.currency,
11 product_ids: (event.data.items || []).map(function (item) {
12 return item.item_id;
13 }),
14 product_count: (event.data.items || []).length,
15 source: 'tamio',
16 page_path: window.location.pathname
17 };
18
19 fetch(endpoint, {
20 method: 'POST',
21 headers: { 'Content-Type': 'application/json' },
22 body: JSON.stringify(payload),
23 keepalive: true
24 });
25});
26</script>

Track Specific Pages

Use page rules when a merchant wants a custom event on specific paths.

HTML
1<script>
2var pageEvents = [
3 {
4 match: /^\/(en|sv)\/wholesale(\/|$)/,
5 event: 'view_wholesale_page',
6 data: { area: 'wholesale' }
7 },
8 {
9 match: /^\/(en|sv)\/campaign\/summer-sale(\/|$)/,
10 event: 'view_summer_campaign',
11 data: { campaign: 'summer-sale' }
12 }
13];
14
15pageEvents.forEach(function (rule) {
16 if (!rule.match.test(window.location.pathname)) return;
17
18 xScripts.tracking.track(rule.event, Object.assign({}, rule.data, {
19 page_location: window.location.href,
20 page_path: window.location.pathname,
21 page_title: document.title || ''
22 }));
23});
24</script>

Send Custom Events

Use track to add merchant-defined events to the same tracking pipeline. These events still go through Tamio consent checks and destination routing.

HTML
1<script>
2xScripts.tracking.track('merchant_custom_event', {
3 label: 'Example custom event',
4 value: 123,
5 currency: 'SEK',
6 page_path: window.location.pathname
7});
8</script>

Derive Custom Events From Tamio Events

You can listen to a native Tamio event and create a new custom event from it. The custom event is sent through the normal Tamio tracking pipeline to configured destinations such as GA4 and Meta.

HTML
1<script>
2xScripts.tracking.onEvent(function (event) {
3 if (event.type !== 'purchase') return;
4
5 xScripts.tracking.track('high_value_purchase', {
6 transaction_id: event.data.transaction_id,
7 value: event.data.value,
8 currency: event.data.currency,
9 product_count: (event.data.items || []).length
10 });
11});
12</script>

You can use the same pattern for other source events:

HTML
1<script>
2xScripts.tracking.onEvent(function (event) {
3 if (event.type !== 'add_to_cart') return;
4
5 xScripts.tracking.track('merchant_add_to_cart', {
6 value: event.data.value,
7 currency: event.data.currency,
8 source_event: event.type
9 });
10});
11</script>

Notes

  • onEvent is for observing events.
  • track is for adding merchant custom events.
  • Use generic event names and plain JSON payloads.
  • Avoid overwriting window.xScripts or xScripts.tracking.