JavaScript SDK
Full API reference for IntemptJS — event tracking, user identification, consent, and product tracking in the browser.
JavaScript SDK
IntemptJS is a browser SDK for tracking user events, managing identities, and handling consent. All public methods are available on the global window.intempt object.
Place all SDK method calls inside a
<script>tag at the bottom of the<body>element.
Installation
Add two snippets to your page <head>. The first creates a queue buffer so window.intempt.* works immediately; the second loads the SDK asynchronously.
<!-- 1. Queue stub — buffers calls until the SDK is ready -->
<script>
(function () {
if (window.intempt) return;
var queue = [], pending = [];
var methods = ['identify','group','track','record','alias','consent',
'productAdd','productOrdered','productView','logOut',
'optIn','optOut','isUserOptIn','recommendation'];
var stub = { _isStub: true, _queue: queue, _pendingPromises: pending };
methods.forEach(function (m) {
stub[m] = function () {
var args = [].slice.call(arguments);
if (m === 'recommendation') {
return new Promise(function (resolve, reject) {
pending.push({ resolve: resolve, reject: reject });
queue.push({ method: m, args: args });
});
}
queue.push({ method: m, args: args });
};
});
window.intempt = stub;
})();
</script>
<!-- 2. Load the SDK asynchronously -->
<script
async
src="https://cdn.intempt.com/intempt.min.js?organization=my-org&project=my-project&source=web-source&key=username.password">
</script>Configuration Parameters
| Parameter | Description |
|---|---|
organization | Organization identifier |
project | Project identifier |
source | Source ID (sourceId) for data transmission |
key | API credentials in username.password format |
shopify | Include to enable Shopify tracking |
magento | Include to enable Magento product detection |
Parameters are activated by presence — include with any non-empty value to enable, omit entirely to disable. Note: =0 and =false do not disable shopify or magento — only omitting the parameter entirely does.
Tracking is off on localhost. By default the SDK blocks all tracking on localhost / 127.0.0.1 and for bot/crawler user agents. If nothing appears while developing locally, that's expected — test on a real or staging domain.
Auto-Tracking
You don't need to wire anything up for the basics. Once the SDK loads it automatically records:
| Event | When it fires |
|---|---|
| Page view | On first load and on every SPA route change (pushState, replaceState, back/forward) |
| Page exit | When the visitor leaves, including time spent on the page |
| Session | Started on first interaction and kept alive as the visitor engages |
| Click | Any element clicked on the page |
| Form change | Any form field value change |
| Form submit | Any form submission, including submitted field values |
For clicks and form events the SDK captures useful context: element tag, id, classes, visible text, link target, CSS-selector path, and — on submit — submitted field values.
Protecting sensitive text
Add the doNotCapture attribute to any element whose text should be masked. The SDK replaces captured text with ********:
<button doNotCapture>Show balance: $12,500</button>
<span doNotCapture>john.doe@private.com</span><input type="password"> elements are masked automatically.
doNotCapture only masks the text/value captured on click or change. It does not hide the element's tag, id, or classes, and it does not strip values submitted through a form. Don't rely on it for whole-form secrecy.
User Tracking Control
optIn()
Activates tracking for the current user.
intempt.optIn();optOut()
Deactivates tracking for the current user.
intempt.optOut();isUserOptIn()
Returns boolean — whether the user has tracking enabled.
if (intempt.isUserOptIn()) {
intempt.track({ eventTitle: 'Button Click', data: { button: 'signup' } });
}All tracking methods (identify, group, track, record, alias, consent, productAdd, productOrdered, productView, logOut) silently do nothing when the user is opted out. The only exception is recommendation, which works regardless of opt-in status.
User Identification
identify(params)
Links user actions to a specific identity.
| Parameter | Type | Required | Description |
|---|---|---|---|
userId | string | Yes | Unique user identifier |
eventTitle | string | No | Custom event name (default: "Identify") |
userAttributes | object | No | User properties (requires eventTitle if supplied) |
data | object | No | Supplementary event data |
intempt.identify({
userId: 'user123',
eventTitle: 'User Registration',
userAttributes: {
email: 'user@example.com',
name: 'John Doe',
plan: 'premium'
},
data: {
registrationSource: 'website',
referrer: 'google'
}
});alias(params)
Links two distinct user identifiers together.
| Parameter | Type | Required | Description |
|---|---|---|---|
userId | string | Yes | Primary user identifier |
anotherUserId | string | Yes | Secondary identifier to alias |
intempt.alias({
userId: 'anonymous_123',
anotherUserId: 'authenticated_user456'
});Group / Account
group(params)
Connects a user with a group or business account.
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Unique account/group identifier |
eventTitle | string | No | Custom event label (default: "Identify") |
accountAttributes | object | No | Account properties (requires eventTitle if supplied) |
intempt.group({
accountId: 'company_abc',
eventTitle: 'Account Created',
accountAttributes: {
name: 'Acme Corp',
plan: 'enterprise',
employees: 500
}
});Event Tracking
track(params)
Records a custom event with associated data.
| Parameter | Type | Required | Description |
|---|---|---|---|
eventTitle | string | Yes | Event name |
data | object | Yes | Event data (must be non-empty) |
intempt.track({
eventTitle: 'Purchase Completed',
data: {
orderId: 'order_123',
amount: 99.99,
currency: 'USD',
items: ['product1', 'product2']
}
});record(params)
Captures an event with optional user and account context.
| Parameter | Type | Required | Description |
|---|---|---|---|
eventTitle | string | Yes | Event name |
userId | string | No | User identifier |
accountId | string | No | Account identifier |
userAttributes | object | No | User properties |
accountAttributes | object | No | Account properties |
data | object | No | Supplementary event data |
intempt.record({
eventTitle: 'Feature Used',
userId: 'user123',
accountId: 'account456',
data: { feature: 'analytics_dashboard', duration: 300 },
userAttributes: { role: 'admin' },
accountAttributes: { plan: 'enterprise' }
});Consent Management
consent(params)
Registers user consent preferences.
| Parameter | Type | Required | Description |
|---|---|---|---|
action | 'accept' | 'reject' | Yes | Consent decision |
validUntil | number | Yes | Expiration timestamp (Unix) |
email | string | No | User email |
message | string | No | Consent statement |
category | string | No | Consent classification |
intempt.consent({
action: 'accept',
validUntil: Date.now() + (365 * 24 * 60 * 60 * 1000),
email: 'user@example.com',
category: 'analytics'
});Product Tracking
productAdd(params)
Logs when a product is added to the cart. Fires event title "Added to cart".
| Parameter | Type | Required | Description |
|---|---|---|---|
productId | string | Yes | Product identifier |
quantity | number | No | Quantity added (default: 1) |
intempt.productAdd({ productId: 'prod_123', quantity: 2 });productOrdered(params[])
Records purchased products on checkout completion. Fires event title "Product ordered".
intempt.productOrdered([
{ productId: 'prod_123', quantity: 2 },
{ productId: 'prod_456', quantity: 1 }
]);productView(productId)
Captures when a product page is viewed. Fires event title "Product viewed".
intempt.productView('prod_123');On Shopify stores (with &shopify=1 in the script URL), product views and add-to-cart events are also detected automatically — no manual calls needed.
Session Management
logOut()
Clears session data and refreshes auto-tracking state. Only executes if the user is currently opted in.
intempt.logOut();Recommendations
recommendation(params)
Fetches personalized product recommendations.
| Parameter | Type | Required | Description |
|---|---|---|---|
id | number | Yes | Feed identifier |
quantity | number | Yes | Number of recommendations |
fields | string[] | Yes | Fields to include in response |
Returns: Promise<any> — recommendation data, or null on failure.
Unlike the other tracking methods, recommendation works even when the user is opted out.
const recommendations = await intempt.recommendation({
id: 123,
quantity: 10,
fields: ['productId', 'name', 'price', 'image']
});
if (recommendations) {
console.log('Recommended products:', recommendations);
}DOM Events
Every tracking call fires custom DOM events you can listen to:
// Fires on every tracking method
window.addEventListener('intempt:event', (event) => {
console.log('Intempt event:', event.detail);
});
// Method-specific events
window.addEventListener('intempt:identify', handler);
window.addEventListener('intempt:alias', handler);
window.addEventListener('intempt:group', handler);
window.addEventListener('intempt:track', handler);
window.addEventListener('intempt:record', handler);
window.addEventListener('intempt:consent', handler);
window.addEventListener('intempt:product', handler); // productAdd, productOrdered, productView
window.addEventListener('intempt:logOut', handler);Forbidden Event Titles
The following titles are reserved and will throw an error:
auto-track · view page · leave page · change on · click on · submit on · identify · consent
Error Handling
try {
intempt.identify({ userId: 'user123' });
} catch (error) {
console.error('Tracking error:', error.message);
}Common errors:
| Error | Cause |
|---|---|
"All config fields must be provided." | Missing SDK config params |
"Parameters for the '{method}' method are required." | Called with no arguments |
"'{field}' is required." | Missing required field |
"The '{eventTitle}' event title is forbidden" | Reserved event title used |
Tips & Gotchas
- All methods take a single object — e.g.
track({ eventTitle, data }). The two exceptions areproductView('id')(a plain string) andproductOrdered([...])(an array). - Validation throws. Missing a required field (like
userIdonidentify) or using a reserved title raises an error. Wrap calls intry/catchif a bad payload shouldn't break your page. - No
getProfileId(). Profile, session, and page IDs are managed internally and attached to events automatically — there is no public getter to read them back. - Local testing. The localhost guard is active by default. Use a staging domain to see events flow through.
Type Reference
interface IdentifyParams {
userId: string;
eventTitle?: string;
userAttributes?: Record<string, any>;
data?: Record<string, any>;
}
interface GroupParams {
accountId: string;
eventTitle?: string;
accountAttributes?: Record<string, any>;
}
interface TrackParams {
eventTitle: string;
data: Record<string, any>;
}
interface RecordParams {
eventTitle: string;
accountId?: string;
userId?: string;
accountAttributes?: Record<string, any>;
userAttributes?: Record<string, any>;
data?: Record<string, any>;
}
interface AliasParams {
userId: string;
anotherUserId: string;
}
interface ConsentParams {
action: 'accept' | 'reject';
validUntil: number;
email?: string;
message?: string;
category?: string;
}
interface ProductParams {
productId: string;
quantity?: number;
}
interface RecommendationParams {
id: number;
quantity: number;
fields: string[];
}API Overview & Authentication
Base URLs, request format, and the three ways to authenticate with the Intempt API: JWT bearer tokens, API keys, and SCIM bearer tokens.
Event Tracking (SDK deep-dive)
How Intempt receives events: auto-tracking, the browser SDK's custom event methods, and the server-side Track Data API.
