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
| Method | Description |
|---|---|
track | Record a named event with properties |
page | Record a page view |
screen | Record a screen view (mobile) |
identify | Associate a user ID with the current session |
alias | Link two user IDs together |
group | Associate the user with a group |
reset | Clear the current session (e.g. on logout) |
React Hooks
| Hook | Returns |
|---|---|
useTrack | (event, properties) => void |
usePageView | Fires a page view on mount |
useIdentify | (userId, traits) => void |
useReset | () => void |
useAnalytics | The full analytics instance |
Standard Events
These event names follow the Segment e-commerce spec and are used by the Ticketing Element automatically:
| Event | When it fires |
|---|---|
Product Viewed | User views event details |
Product List Viewed | User views the admissions list |
Product Added | Ticket added to cart |
Product Removed | Ticket removed from cart |
Cart Viewed | Cart quote updated |
Checkout Started | User begins checkout |
Order Completed | Purchase complete |
Event Properties
Every track call accepts an optional properties object. Include
promoter_id to enable pixel forwarding.
| Property | Type | Description |
|---|---|---|
promoter_id | string | Required for pixels. Routes events to the promoter’s configured pixels. |
product_id | string | Event or ticket ID |
name | string | Event or product name |
price | number | Unit price in cents |
quantity | number | Number of items |
currency | string | ISO 4217 currency code |
total | number | Order total in cents |
order_id | string | Order ID |
products | array | Array 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:
| Destination | Promoter field | Description |
|---|---|---|
| Facebook Pixel | fbId | Facebook/Meta conversion tracking |
| Google Tag Manager | gtmId | GTM container for custom tags |
| TikTok Pixel | tikTokId | TikTok conversion tracking |
Pixel configuration is managed on your promoter account. Contact us to set up your pixel IDs.
Automatic Context
Every event automatically includes:
| Field | Description |
|---|---|
page.url | Current page URL |
page.path | URL path |
page.title | Document title |
page.referrer | Referring URL |
userAgent | Browser user agent |
campaign.source | utm_source query parameter |
campaign.medium | utm_medium query parameter |
campaign.name | utm_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>