Skip to content

Analytics

Track user behaviour and route events to Facebook, Google Tag Manager, and TikTok.

The SDK includes a built-in analytics module for tracking user interactions. Events are sent to the Session Services analytics backend and can be automatically forwarded to third-party pixels configured on your promoter account.

Setup

Vanilla JavaScript

import { createClient } from '@session-services/sdk';
import { createAnalytics } from '@session-services/sdk/analytics';

const client = createClient({
  environment: 'prod',
  tenantId: 'tnt_01jqpj2t2kfvmstt6f6tzkbaf2',
});

const analytics = createAnalytics({
  client,
  debug: false, // set true to log events to the console
});

React

Wrap your app in the AnalyticsProvider:

import { createClient } from '@session-services/sdk';
import { AnalyticsProvider } from '@session-services/sdk/analytics/react';

const client = createClient({
  environment: 'prod',
  tenantId: 'tnt_01jqpj2t2kfvmstt6f6tzkbaf2',
});

export default function App() {
  return (
    <AnalyticsProvider client={client}>
      <YourApp />
    </AnalyticsProvider>
  );
}

Tracking Events

Vanilla

analytics.track('Product Viewed', {
  promoter_id: 'pmt_01jqpjksnsen9vprw95et60t2m',
  product_id: 'evt_01jps5cgsenjrazw6wswmyspa3',
  name: 'Summer Festival',
  price: 4500,
  currency: 'AUD',
});

analytics.page('Event Page', { promoter_id: 'pmt_01jqpjksnsen9vprw95et60t2m' });

React Hooks

import { useTrack, usePageView } from '@session-services/sdk/analytics/react';

function EventPage({ event }) {
  const track = useTrack();

  usePageView('Event Page', { promoter_id: event.promoterId });

  return (
    <button
      onClick={() =>
        track('Product Viewed', {
          promoter_id: event.promoterId,
          product_id: event.id,
          name: event.name,
        })
      }
    >
      View Details
    </button>
  );
}

Available Methods

MethodDescription
trackRecord a named event with properties
pageRecord a page view
screenRecord a screen view (mobile)
identifyAssociate a user ID with the current session
aliasLink two user IDs together
groupAssociate the user with a group
resetClear the current session (e.g. on logout)

React Hooks

HookReturns
useTrack(event, properties) => void
usePageViewFires a page view on mount
useIdentify(userId, traits) => void
useReset() => void
useAnalyticsThe full analytics instance

Standard Events

These event names follow the Segment e-commerce spec and are used by the Ticketing Element automatically:

EventWhen it fires
Product ViewedUser views event details
Product List ViewedUser views the admissions list
Product AddedTicket added to cart
Product RemovedTicket removed from cart
Cart ViewedCart quote updated
Checkout StartedUser begins checkout
Order CompletedPurchase complete

Event Properties

Every track call accepts an optional properties object. Include promoter_id to enable pixel forwarding.

PropertyTypeDescription
promoter_idstringRequired for pixels. Routes events to the promoter’s configured pixels.
product_idstringEvent or ticket ID
namestringEvent or product name
pricenumberUnit price in cents
quantitynumberNumber of items
currencystringISO 4217 currency code
totalnumberOrder total in cents
order_idstringOrder ID
productsarrayArray of product items (for multi-item events)

Pixel Integrations

When a promoter_id is included in event properties, the analytics module fetches the promoter’s pixel configuration and forwards events to any configured destinations:

DestinationPromoter fieldDescription
Facebook PixelfbIdFacebook/Meta conversion tracking
Google Tag ManagergtmIdGTM container for custom tags
TikTok PixeltikTokIdTikTok conversion tracking

Pixel configuration is managed on your promoter account. Contact us to set up your pixel IDs.


Automatic Context

Every event automatically includes:

FieldDescription
page.urlCurrent page URL
page.pathURL path
page.titleDocument title
page.referrerReferring URL
userAgentBrowser user agent
campaign.sourceutm_source query parameter
campaign.mediumutm_medium query parameter
campaign.nameutm_campaign query parameter

Ticketing Element

The Ticketing Element tracks analytics automatically when enableAnalytics is set (enabled by default). Set debugAnalytics to log events to the console during development.

<session-services-ticketing
  tenant-id="tnt_01jqpj2t2kfvmstt6f6tzkbaf2"
  event-id="evt_01jps5cgsenjrazw6wswmyspa3"
  enable-analytics="true"
  debug-analytics="true"
></session-services-ticketing>