Your Dashboard Guides You Through This
When you log in to einstein.clickstream.com, the onboarding wizard walks you through SDK installation step by step. This guide covers the same steps in detail, plus advanced configuration.
Method 1: Script Tag (Recommended)
The fastest way to get started. Add this snippet before the closing </head> tag on every page:
Replace t.yourdomain.com with your tracking subdomain (see the Tracking Domain Setup Guide) and YOUR_SITE_ID with the Site ID from your ClickStream dashboard.
What the Script Does
- Sets a first-party cookie on your domain with 365-day persistence
- Auto-captures page views, clicks, scroll depth, and form interactions
- Captures UTM parameters and ad platform click IDs (gclid, fbclid, msclkid, ttclid)
- Runs 26 behavioral scoring models at the edge in under 3ms
- Builds a cross-device identity graph anchored to first-party cookies
Script Tag Attributes
| Attribute | Required | Description |
|---|---|---|
src |
Yes | URL of the ClickStream SDK on your tracking domain |
data-site-id |
Yes | Your unique Site ID from the ClickStream dashboard |
data-key |
Yes | Your API key (starts with cs_live_ or cs_test_) |
defer |
Recommended | Loads the script without blocking page render |
data-consent |
No | Set to "required" to block tracking until consent is granted |
data-auto-capture |
No | Set to "false" to disable automatic event capture |
Method 2: NPM Package
For projects using a JavaScript build system:
Then initialize in your application entry point:
NPM Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
siteId |
string | — | Your unique Site ID (required) |
apiKey |
string | — | Your API key (required) |
trackingDomain |
string | — | Your CNAME tracking subdomain (required) |
autoCapture |
boolean | true | Automatically capture page views, clicks, scrolls |
consentRequired |
boolean | false | Block tracking until consent is granted |
cookieDomain |
string | auto | Override the cookie domain (e.g., .yourdomain.com) |
debug |
boolean | false | Enable console logging for debugging |
SPA Route Change Tracking
Single-page applications need to track virtual page views when routes change. ClickStream handles this automatically for popular routers.
React Router
Next.js (App Router)
Vue Router
Identity Tracking
Connect anonymous visitors to known identities. Call identify when a user logs in, signs up, or provides their email:
CRM ID Mapping
Map visitors to your CRM records for full-funnel attribution:
The identity graph will merge all sessions for this visitor — including past anonymous sessions that were linked via the first-party cookie — into a single unified profile.
Custom Events
Track business-specific events beyond the auto-captured defaults:
Event Naming Conventions
- Use
snake_casefor event names (e.g.,purchase_completed) - Use
camelCasefor property names (e.g.,orderId) - Keep event names descriptive:
noun_verbpattern (e.g.,video_played,cart_updated) - Avoid high-cardinality event names (do not include IDs in the event name itself)
Consent Management
ClickStream integrates with your existing Consent Management Platform (CMP) or can operate in standalone consent mode.
Before Consent (Default Mode)
When consentRequired is set to true, the SDK loads but does not set cookies or send tracking data until consent is granted:
Granting Consent
When the user accepts tracking (e.g., clicks "Accept All" on your cookie banner):
Revoking Consent
When a user revokes consent:
CMP Integration Example (OneTrust)
Cookieless Fallback
For the 15-22% of visitors who decline cookies, ClickStream falls back to a cookieless device recognition mode that still provides basic behavioral scoring (reduced from 26 to 4 models) without persistent identity. This data is session-scoped and not linked to the identity graph.
Verification
After installing the SDK, verify it is working correctly:
- Check the Network tab — Open DevTools > Network. Filter for your tracking domain. You should see requests to
/cs.js(SDK load) and/e(event payloads). - Check cookies — Open DevTools > Application > Cookies. Look for the
_cs_idcookie on your domain with a 365-day expiration. - Check the dashboard — Log into the ClickStream dashboard. Navigate to Live View. You should see your visit appear within seconds.
- Enable debug mode — Add
data-debug="true"to the script tag (ordebug: truein the NPM config). Open the browser console to see detailed SDK logging.
Performance Impact
ClickStream is designed to have minimal impact on page performance:
| Metric | Impact |
|---|---|
| SDK file size | 8.2 KB gzipped |
| Load strategy | Async/deferred — does not block page render |
| Event payload size | ~1.2 KB per event |
| Edge processing latency | <3ms (Cloudflare Workers) |
| Main thread impact | <2ms per event |
| Lighthouse score impact | Negligible (0-1 point on Performance) |
Full Configuration Reference
| Option | Type | Default | Description |
|---|---|---|---|
siteId |
string | — | Your unique Site ID (required) |
apiKey |
string | — | Your API key (required) |
trackingDomain |
string | — | Your CNAME tracking subdomain (required) |
autoCapture |
boolean | true | Auto-capture page views, clicks, scroll depth, form interactions |
consentRequired |
boolean | false | Require consent before tracking |
cookieDomain |
string | auto | Override cookie domain for cross-subdomain tracking |
cookieExpiry |
number | 365 | Cookie expiration in days |
debug |
boolean | false | Enable console debug logging |
respectDoNotTrack |
boolean | false | Honor the browser DNT header |
sessionTimeout |
number | 30 | Session timeout in minutes of inactivity |
batchSize |
number | 10 | Number of events to batch before sending |
batchInterval |
number | 5000 | Max time (ms) before flushing event batch |