Website Analytics
Track first-party website analytics with the DOM Package
Website analytics starts automatically when you initialize Tiquo, unless you set analytics: false or the consent mode is none.
import { Tiquo } from '@tiquo/dom-package';
const tiquo = new Tiquo({
publicKey: 'pk_dom_your_key_here',
});The SDK records cookie-free first-party analytics events to Tiquo, including:
- Pageviews, including the current path, URL, page title, and referrer
- Single-page app navigation through
history.pushState,history.replaceState, and browser back/forward navigation - Engagement events when the visitor leaves a page or the page becomes hidden
- Session attribution through a browser-session ID stored in
sessionStorage - UTM parameters from the current URL:
utm_source,utm_medium,utm_campaign,utm_content, andutm_term - Browser, device type, operating system, language, screen size, and viewport size
- Known-customer identity when the visitor authenticates through the DOM Package and consent is
full
Tiquo records the source hostname for each event. www.example.com is normalized to example.com; other subdomains are tracked separately.
Consent
From version 1.19.0, the consent option and setConsent() control how much the SDK records. full links events to the signed-in customer, anonymous sends them without the customer's identity, and none sends nothing. Version 1.20.0 adds cookieless, which sends events without the customer's identity and stores nothing in the browser. The default is full.
const tiquo = new Tiquo({
publicKey: 'pk_dom_your_key_here',
consent: 'cookieless',
});
// After the visitor accepts your consent banner
tiquo.setConsent('full');See Consent and security for how the choice is saved, and for a workaround on earlier versions.
Sending custom events
Use tiquo.analytics?.track() to send custom analytics events from your website.
await tiquo.analytics?.track('booking_started', {
eventName: 'Booking Started',
eventProperties: {
serviceId: 'svc_123',
locationId: 'loc_456',
},
});Custom events accept the same page context fields used by automatic pageviews:
| Option | Type | Description |
|---|---|---|
eventName | string | Human-readable event name |
eventProperties | object | Custom structured event data |
siteSlug | string | Optional website slug for analytics site resolution |
pageSlug | string | Optional page slug |
path | string | Override the current path |
url | string | Override the current URL |
title | string | Override the current document title |
referrer | string | Override the document referrer |
Identifying customers
After a customer signs in with verifyOTP(), the SDK automatically sends an identify analytics event when consent is full. The event includes the current access token so Tiquo can associate website activity with the authenticated customer.
You can also send an identify event manually when you link an analytics session to a customer through another flow:
await tiquo.analytics?.identify({
identityLinkType: 'email_capture',
});identify() sends nothing unless consent is full. Supported identityLinkType values are auth_dom_login, email_capture, booking, enquiry, order, customer_portal, and manual.
Manual pageviews
Automatic pageview tracking is enabled by default. If you need to control pageview timing yourself, create a standalone analytics instance with autoTrackPageviews: false.
import { TiquoAnalytics } from '@tiquo/dom-package';
const analytics = new TiquoAnalytics({
publicKey: 'pk_dom_your_key_here',
autoTrackPageviews: false,
});
await analytics.trackPageview({
path: '/pricing',
title: 'Pricing',
});Disabling analytics
Set analytics: false when creating Tiquo.
const tiquo = new Tiquo({
publicKey: 'pk_dom_your_key_here',
analytics: false,
});Standalone analytics
You can use TiquoAnalytics without authentication if a site only needs first-party website analytics.
import { TiquoAnalytics } from '@tiquo/dom-package';
const analytics = new TiquoAnalytics({
publicKey: 'pk_dom_your_key_here',
siteSlug: 'main-site',
});
await analytics.track('newsletter_signup', {
eventName: 'Newsletter Signup',
identityLinkType: 'email_capture',
});