Intempt
  1. SDK
Intempt
  • SDK
    • JS SDK
    • Android SDK
  • API Reference
    • Track data
      POST
    • Consent
      POST
    • Choose API
      POST
    • Recommendations Feed API
      POST
  1. SDK

JS SDK

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#

Parameters:
ParameterTypeRequiredDescription
config.organizationstringYesOrganization identifier
config.sourceIdstringYesSource identifier
config.projectstringYesProject identifier
config.writeKeystringYesWrite key for authentication (format: username.password)
config.shopifybooleanYesEnable Shopify integration
config.magentobooleanYesEnable Magento integration
Example:
Validation:
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
Example:

optIn()#

Enables tracking for the current user.
Returns: void
Example:

optOut()#

Disables tracking for the current user.
Returns: void
Example:

isUserOptIn()#

Checks if the user has opted in to tracking.
Returns: boolean - true if tracking is enabled, false otherwise
Example:

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.
Parameters:
ParameterTypeRequiredDescription
params.userIdstringYesUnique identifier for the user
params.eventTitlestringNoCustom event title (default: "Identify")
params.userAttributes{[key: string]: any}NoUser attributes object (requires eventTitle if provided)
params.data{[key: string]: any}NoAdditional event data
Returns: void
Validation:
userId is required
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'
Example:
Events Dispatched:
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).
Parameters:
ParameterTypeRequiredDescription
params.userIdstringYesPrimary user ID
params.anotherUserIdstringYesSecondary user ID to alias
Returns: void
Validation:
Both userId and anotherUserId are required
Example:
Events Dispatched:
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.
Parameters:
ParameterTypeRequiredDescription
params.accountIdstringYesUnique identifier for the account/group
params.eventTitlestringNoCustom event title (default: "Identify")
params.accountAttributes{[key: string]: any}NoAccount attributes object (requires eventTitle if provided)
Returns: void
Validation:
accountId is required
If accountAttributes is provided, eventTitle must also be provided
Forbidden event titles: same as identify method
Example:
Events Dispatched:
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.
Parameters:
ParameterTypeRequiredDescription
params.eventTitlestringYesName of the event
params.data{[key: string]: any}YesEvent data object (must not be empty)
Returns: void
Validation:
eventTitle is required
data must be provided and non-empty
Forbidden event titles: same as identify method
Example:
Events Dispatched:
intempt:track - Custom event with event name
intempt:event - Event data payload

record(params: RecordParams)#

Records an event with optional user and account information.
Parameters:
ParameterTypeRequiredDescription
params.eventTitlestringYesName of the event
params.accountIdstringNoAccount identifier
params.userIdstringNoUser identifier
params.accountAttributes{[key: string]: any}NoAccount attributes
params.userAttributes{[key: string]: any}NoUser attributes
params.data{[key: string]: any}NoAdditional event data
Returns: void
Validation:
eventTitle is required
Forbidden event titles: same as identify method
Example:
Events Dispatched:
intempt:record - Custom event with event name
intempt:event - Event data payload

Consent Management#

consent(params: ConsentParams)#

Records user consent preferences.
Parameters:
ParameterTypeRequiredDescription
params.action'accept' | 'reject'YesConsent action
params.validUntilnumberYesTimestamp when consent expires
params.emailstringNoUser email address
params.messagestringNoConsent message
params.categorystringNoConsent category
Returns: void
Validation:
action is required and must be either 'accept' or 'reject'
validUntil is required (Unix timestamp)
Example:
Events Dispatched:
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.
Parameters:
ParameterTypeRequiredDescription
params.productIdstringYesProduct identifier
params.quantitynumberNoQuantity added (default: 1)
Returns: void
Example:
Events Dispatched:
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).
Parameters:
ParameterTypeRequiredDescription
paramsProductParams[]YesArray of product objects
ProductParams:
productId (string, required): Product identifier
quantity (number, optional): Quantity ordered
Returns: void
Example:
Events Dispatched:
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.
Parameters:
ParameterTypeRequiredDescription
productIdstringYesProduct identifier
Returns: void
Example:
Events Dispatched:
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.
Returns: void
Example:
Events Dispatched:
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.
Parameters:
ParameterTypeRequiredDescription
params.idnumberYesFeed ID for recommendations
params.quantitynumberYesNumber of recommendations to return
params.fieldsstring[]YesFields to include in the response
Returns: Promise<any> - Recommendation data or null on error
Example:
API Details:
Endpoint: {api}/{organization}/projects/{project}/feeds/{id}/data
Method: POST
Authentication: Basic Auth (derived from writeKey)
Request Body:
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
Error Handling:
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)
Example Event Listener:

Forbidden Event Titles#

The following event titles are forbidden and will throw an error:
'auto-track'
'view page'
'leave page'
'change on'
'click on'
'submit on'
'identify'
'consent'

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.

Version Information#

SDK Version: 0.0.0 (from package.json)
Documentation Version: 1.0.0
Last Updated: 2024
Modified at 2025-11-26 16:08:40
Next
Android SDK
Built with