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.Initialization#
Constructor#
| Parameter | Type | Required | Description |
|---|
config.organization | string | Yes | Organization identifier |
config.sourceId | string | Yes | Source identifier |
config.project | string | Yes | Project identifier |
config.writeKey | string | Yes | Write key for authentication (format: username.password) |
config.shopify | boolean | Yes | Enable Shopify integration |
config.magento | boolean | Yes | Enable Magento integration |
All config fields must be provided (non-empty strings)
Throws error if any required field is missing
User Tracking Control Methods#
getProfileId()#
Retrieves the current user's profile ID.Returns: string - The profile ID
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:
Best Practices#
1.
Initialize once: Create a single IntemptJs instance and reuse it throughout your application.
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 2025-11-26 16:08:40