IntemptJS API Documentation#
Overview#
IntemptJS is a JavaScript SDK for tracking user events, managing user identification, and handling consent management. This document describes all public methods available in the IntemptJs class.We highly recommend using all SDK methods inside a <script> tag placed at the bottom of the <body> element.
Installation#
Add both snippets to your page <head>, in this order. The first installs a small
queue stub so window.intempt.* calls work immediately; the second loads the SDK
asynchronously and replays anything that was queued. There's no constructor to call —
your account settings go in the SDK URL's query parameters.| Parameter | Description |
|---|
organization | Organization identifier |
project | Project identifier |
source | Source ID (sourceId) you're sending data to |
key | API key, in username.password form |
shopify | Shopify tracking — add &shopify=1 to enable, omit to disable |
magento | Magento product detection — add &magento=1 to enable, omit to disable |
shopify and magento are enabled by presence: including the parameter with any
non-empty value turns it on. To disable, leave it out entirely (note that =0 or
=false will not disable it).
Once loaded, the SDK takes over window.intempt, replays any queued calls, and starts
auto-tracking. Because the SDK loads with async, it never blocks page rendering.
Quick Start#
All event methods take a single object argument:
User Tracking Control Methods#
optIn()#
Enables tracking for the current user.
optOut()#
Disables tracking for the current user.
isUserOptIn()#
Checks if the user has opted in to tracking.Returns: boolean - true if tracking is enabled, false otherwise
User Identification Methods#
identify(params: IdentifyParams)#
Identifies a user and associates them with a user ID. This method is used to link user actions to a specific user identity.| Parameter | Type | Required | Description |
|---|
params.userId | string | Yes | Unique identifier for the user |
params.eventTitle | string | No | Custom event title (default: "Identify") |
params.userAttributes | {[key: string]: any} | No | User attributes object (requires eventTitle if provided) |
params.data | {[key: string]: any} | No | Additional event data |
If userAttributes is provided, eventTitle must also be provided
Forbidden event titles: 'auto-track', 'view page', 'leave page', 'change on', 'click on', 'submit on', 'identify', 'consent'
intempt:identify - Custom event with event name
intempt:event - Event data payload
alias(params: AliasParams)#
Creates an alias between two user IDs. Used when a user is identified with different IDs (e.g., anonymous ID and authenticated ID).| Parameter | Type | Required | Description |
|---|
params.userId | string | Yes | Primary user ID |
params.anotherUserId | string | Yes | Secondary user ID to alias |
Both userId and anotherUserId are required
intempt:alias - Custom event with event name
intempt:event - Event data payload
Group/Account Methods#
group(params: GroupParams)#
Associates a user with a group or account.| Parameter | Type | Required | Description |
|---|
params.accountId | string | Yes | Unique identifier for the account/group |
params.eventTitle | string | No | Custom event title (default: "Identify") |
params.accountAttributes | {[key: string]: any} | No | Account attributes object (requires eventTitle if provided) |
If accountAttributes is provided, eventTitle must also be provided
Forbidden event titles: same as identify method
intempt:group - Custom event with event name
intempt:event - Event data payload
Event Tracking Methods#
track(params: TrackParams)#
Tracks a custom event with associated data.| Parameter | Type | Required | Description |
|---|
params.eventTitle | string | Yes | Name of the event |
params.data | {[key: string]: any} | Yes | Event data object (must not be empty) |
data must be provided and non-empty
Forbidden event titles: same as identify method
intempt:track - Custom event with event name
intempt:event - Event data payload
record(params: RecordParams)#
Records an event with optional user and account information.| Parameter | Type | Required | Description |
|---|
params.eventTitle | string | Yes | Name of the event |
params.accountId | string | No | Account identifier |
params.userId | string | No | User identifier |
params.accountAttributes | {[key: string]: any} | No | Account attributes |
params.userAttributes | {[key: string]: any} | No | User attributes |
params.data | {[key: string]: any} | No | Additional event data |
Forbidden event titles: same as identify method
intempt:record - Custom event with event name
intempt:event - Event data payload
Consent Management#
consent(params: ConsentParams)#
Records user consent preferences.| Parameter | Type | Required | Description |
|---|
params.action | 'accept' | 'reject' | Yes | Consent action |
params.validUntil | number | Yes | Timestamp when consent expires |
params.email | string | No | User email address |
params.message | string | No | Consent message |
params.category | string | No | Consent category |
action is required and must be either 'accept' or 'reject'
validUntil is required (Unix timestamp)
intempt:consent - Custom event with event name
intempt:event - Event data payload
Product Tracking Methods#
productAdd(params: ProductParams)#
Tracks when a product is added to cart.| Parameter | Type | Required | Description |
|---|
params.productId | string | Yes | Product identifier |
params.quantity | number | No | Quantity added (default: 1) |
intempt:product - Custom event with event name
intempt:event - Event data payload
Event Title: "Added to cart"
productOrdered(params: ProductParams[])#
Tracks when products are ordered (purchased).| Parameter | Type | Required | Description |
|---|
params | ProductParams[] | Yes | Array of product objects |
productId (string, required): Product identifier
quantity (number, optional): Quantity ordered
intempt:product - Custom event with event name
intempt:event - Event data payload
Event Title: "Product ordered"
productView(productId: string)#
Tracks when a product is viewed.| Parameter | Type | Required | Description |
|---|
productId | string | Yes | Product identifier |
intempt:product - Custom event with event name
intempt:event - Event data payload
Event Title: "Product viewed"
Session Management#
logOut()#
Handles user logout by refreshing the auto tracker and clearing session data.intempt:logOut - Custom event with event name "Log Out"
Note: This method only executes if the user has opted in to tracking.
Recommendation API#
recommendation(params: RecommendationParams)#
Fetches product recommendations from the Intempt API.| Parameter | Type | Required | Description |
|---|
params.id | number | Yes | Feed ID for recommendations |
params.quantity | number | Yes | Number of recommendations to return |
params.fields | string[] | Yes | Fields to include in the response |
Returns: Promise<any> - Recommendation data or null on errorEndpoint: {api}/{organization}/projects/{project}/feeds/{id}/data
Authentication: Basic Auth (derived from writeKey)
profileId: Current user's profile ID
sourceId: Source identifier from config
limit: Number of recommendations
fields: Array of field names
productId: Optional product ID from localStorage
Returns null if the request fails
Uses keepalive: true for better reliability
Common Behavior#
Opt-In Requirement#
Most tracking methods (identify, group, track, record, alias, consent, productAdd, productOrdered, productView, logOut) will silently return without executing if the user has opted out of tracking. Use isUserOptIn() to check the current status.Automatic IDs#
The following IDs are automatically included in all tracking events:profileId: Generated/retrieved from auto tracker
sessionId: Current session identifier
pageId: Current page identifier
Event Dispatching#
All tracking methods dispatch custom DOM events that can be listened to:Method-specific events: intempt:identify, intempt:track, intempt:record, etc.
Generic event: intempt:event (dispatched by all methods)
Forbidden Event Titles#
The following event titles are forbidden and will throw an error:
Type Definitions#
IntemptConfig#
IdentifyParams#
GroupParams#
TrackParams#
RecordParams#
AliasParams#
ConsentParams#
ProductParams#
RecommendationParams#
Error Handling#
All validation errors throw exceptions with descriptive messages. Common errors include:Configuration errors: "IntemptJs initialization failed: All config fields must be provided."
Parameter validation errors: "Parameters for the '{method}' method are required."
Field-specific errors: "{Method} parameters are invalid: '{field}' is required."
Forbidden event titles: "The '{eventTitle}' event title is forbidden"
Always wrap method calls in try-catch blocks when appropriate:
Keeping sensitive text out of events#
Some on-screen values shouldn't be sent to analytics (account numbers, balances,
personal info shown on a button or field). Add the doNotCapture attribute and the
SDK masks that element's captured text as ********:Password inputs (<input type="password">) are masked automatically — you don't need
to add anything.doNotCapture masks the text/value captured when an element is clicked or
changed. It doesn't hide the element's tag, id, or classes, and it doesn't strip
values submitted through a form — so avoid relying on it for whole-form secrecy.
Best Practices#
1.
Additional snippet during initialization: Installs a small
queue stub so window.intempt.* calls work immediately.
2.
Check opt-in status: Before tracking, check if the user has opted in: 3.
Handle errors: Wrap tracking calls in try-catch blocks for production code.
4.
Use meaningful event titles: Choose descriptive event titles that clearly indicate what action occurred.
5.
Include relevant data: Provide comprehensive data objects to enable better analytics.
6.
Consent management: Always respect user consent preferences and use the consent() method to record consent decisions.
SDK Version: 0.0.0 (from package.json)
Documentation Version: 1.0.0
Modified at 2026-06-30 20:35:25