Intempt Docs
Developer DocsSDK

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

ParameterDescription
organizationOrganization identifier
projectProject identifier
sourceSource ID (sourceId) for data transmission
keyAPI credentials in username.password format
shopifyInclude to enable Shopify tracking
magentoInclude 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:

EventWhen it fires
Page viewOn first load and on every SPA route change (pushState, replaceState, back/forward)
Page exitWhen the visitor leaves, including time spent on the page
SessionStarted on first interaction and kept alive as the visitor engages
ClickAny element clicked on the page
Form changeAny form field value change
Form submitAny 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.

ParameterTypeRequiredDescription
userIdstringYesUnique user identifier
eventTitlestringNoCustom event name (default: "Identify")
userAttributesobjectNoUser properties (requires eventTitle if supplied)
dataobjectNoSupplementary 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.

ParameterTypeRequiredDescription
userIdstringYesPrimary user identifier
anotherUserIdstringYesSecondary identifier to alias
intempt.alias({
  userId: 'anonymous_123',
  anotherUserId: 'authenticated_user456'
});

Group / Account

group(params)

Connects a user with a group or business account.

ParameterTypeRequiredDescription
accountIdstringYesUnique account/group identifier
eventTitlestringNoCustom event label (default: "Identify")
accountAttributesobjectNoAccount 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.

ParameterTypeRequiredDescription
eventTitlestringYesEvent name
dataobjectYesEvent 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.

ParameterTypeRequiredDescription
eventTitlestringYesEvent name
userIdstringNoUser identifier
accountIdstringNoAccount identifier
userAttributesobjectNoUser properties
accountAttributesobjectNoAccount properties
dataobjectNoSupplementary event data
intempt.record({
  eventTitle: 'Feature Used',
  userId: 'user123',
  accountId: 'account456',
  data: { feature: 'analytics_dashboard', duration: 300 },
  userAttributes: { role: 'admin' },
  accountAttributes: { plan: 'enterprise' }
});

consent(params)

Registers user consent preferences.

ParameterTypeRequiredDescription
action'accept' | 'reject'YesConsent decision
validUntilnumberYesExpiration timestamp (Unix)
emailstringNoUser email
messagestringNoConsent statement
categorystringNoConsent 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".

ParameterTypeRequiredDescription
productIdstringYesProduct identifier
quantitynumberNoQuantity 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.

ParameterTypeRequiredDescription
idnumberYesFeed identifier
quantitynumberYesNumber of recommendations
fieldsstring[]YesFields 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:

ErrorCause
"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 are productView('id') (a plain string) and productOrdered([...]) (an array).
  • Validation throws. Missing a required field (like userId on identify) or using a reserved title raises an error. Wrap calls in try/catch if 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[];
}

On this page