Intempt
  1. SDK
Intempt
  • Installation
    • Basic Intempt Installation
    • Create source
    • Web Snippet
    • Google Tag Manager
    • Autocapture setup
    • SPA tracking
    • Environment Setup
    • Validating Installation
  • SDK
    • JS SDK
    • Android SDK
    • iOS SDK
    • Node.js SDK
  • API Reference
    • Track data
      POST
    • Consent
      POST
    • Choose API
      POST
    • Recommendations Feed API
      POST
  • Data Ingestion & Tracking
    • identify()
    • track()
    • record()
    • alias()
    • group()
    • consent()
    • intempt:html / intempt:page / intempt:session
    • Product Catalog Ingestion via API
  • Data Models & Event Schema
    • Event Schema Overview
    • Required Fields
    • Attribute Schema
    • Product Catalog Schema
  • Webhooks
    • Webhook Configuration
  • Server Side Experiments
    • Overview
    • Choose API endpoint
    • Handling Experiment Response
  1. SDK

Node.js SDK

Intempt Node.js SDK API Documentation#

Overview#

Node.js server-side source allows you to collect server-side data and pull data directly from your servers and databases.
Node.js library will be most useful to you if you need to send data from a Node.js server, or for interacting with Intempt APIs in JavaScript outside of the browser.
This SDK is stateless and will only send the data you populate. In contrast, our web & mobile SDKs will automatically collect web and app, like device information or page/screen visited.
SDK capabilities:
Identify users
Record custom events
Track consents
Display experiments and personalization

Installation#

Create a source#

Under the Integrations section -> "Sources" tab, select the "Create source" button and then the "Node.JS" option.
Copy the snippet and use it in the next step - SDK initialization.

Create the API key#

Refer to API keys to create unique API keys that you can use in your project to authenticate SDK access.

Initialize the SDK#

Install the SDK by running the npm package#

To update to the latest version, run:

Import#

Use this command to import the whole SDK:
or:

Create instance#

SDK constructor parameters description:
🚧 Don't miss out!
Remember to replace "YOUR_API_KEY" with the API key you generated via API keys section.

Tracking methods#

Restrictions#

SDK has an event title parameter mandatory for almost all tracking methods. All event titles are acceptable except Identify - it's the default event title for user identification.

Identify#

Our SDK offers a convenient function to identify users using unique identifiers such as email or phone number. Simply call the functions provided below to utilize this feature effectively.

Usage examples#

Connect profileId with a unique user identifier:
Connect profileId with a unique user identifier having a custom event name:
Connect profileId with a unique user identifier, including user attributes. User attributes require a provided event title different from 'Identify':
📘 Important
In your server, it is advisable to use the Id of your users as profileId. That way, it is always unique and you don't need to have a randomizer or generator.

Group#

Our SDK includes a function that helps you identify accounts using unique identifiers such as a domain or work email. To leverage this functionality, simply invoke the functions listed below.

Usage examples#

Connect the user profileId with the unique account identifier:
Connect the user profileId with a unique account having a custom event name:
Connect the user profileId with a unique account, including account attributes. Account attributes require a provided event title different from 'Identify':

Track#

The SDK enables you to track custom events, such as 'Purchase' or 'Add to Cart,' by profileId. To monitor these user actions, simply call the method provided below.

Usage examples#

Method call example:

Alias#

The SDK offers a convenient method to merge two separate user profiles, such as one identified by email and another by phone number, into a single user profile. By linking the two different identifiers, the system will consolidate them into one unified user, associating both the email and phone number with a single user record. Refer to the function below to perform this merge.

Usage examples#

Method call example:

Record#

The SDK offers a versatile method for configuring tracking with extensive customization options. This method enables you to tailor tracking settings according to your specific requirements without restrictions. It provides flexibility to define and monitor data at a granular level, ensuring you can capture and analyze all necessary information for comprehensive insights. Use the function below to access these advanced configuration capabilities.

Usage examples#

Record the item with event properties and user, account identifiers:
Record the item with event properties, user identifier, and attributes:
Record the item with the event properties account identifier and attributes:

OptIn#

This method activates the tracking of user data, allowing you to monitor and analyze user interactions and behaviors. By enabling this feature, you can collect valuable data that can provide insights into user preferences, activities, and trends. By default, it's enabled.

OptOut#

This method disables the tracking of user data, ensuring that no further information about user interactions and behaviors is collected. By turning off this feature, you can respect user privacy and comply with data protection regulations. Use this function when you need to halt the monitoring and analysis of user data, whether temporarily or permanently. This method provides control over your data collection practices and can be a crucial part of your privacy and compliance strategy.

Consent methods#

Consents#

This method manages all user consents for data tracking. It allows you to handle user preferences regarding the collection and processing of their data. By invoking this function, you can set and update a user's consent status, ensuring that your application adheres to privacy regulations and respects user choices.

Usage examples#

Update all consents:
Update all consents with the user's email and message:

Consent#

This method in the library allows you to manage a single consent for a specific type of user data tracking. By calling this function, you can enable or disable tracking for a particular data category according to the user's preference.

Usage examples#

Update single consent:
Update single consent with the user's email and message:

Optimization choose methods#

Choose personalizations by groups#

The SDK provides a method for selecting personalized experiences based on a list of groups. This allows you to tailor the user's experience according to specific segments or groupings, enhancing their overall interaction with your application. By choosing from a variety of groups, you can deliver customized content and features that align with the user's interests and preferences.

Usage examples#

Choose all personalizations:
Choose personalizations by groups:

Choose personalizations by names#

The SDK provides a method to select personalized experiences based on a list of names. This approach enables you to customize the user experience by targeting specific individuals or groups identified by their names. By using this method, you can deliver tailored content and features to enhance the user's interaction with your application, ensuring a more engaging and personalized experience.

Usage examples#

Choose all personalizations:
Choose personalizations by groups:

Choose experiments by groups#

The SDK provides a method to select and manage experiments based on a list of groups. This allows you to efficiently organize and conduct A/B tests or other experimental comparisons within specified groups. By targeting groups directly, you can streamline the process of running experiments and analyzing results, which in turn helps optimize your product or service for better user engagement and performance.

Usage examples#

Choose all personalizations:
Choose personalizations by groups:

Choose experiments by names#

The SDK provides a method to select and manage experiments based on a list of names. This functionality allows you to precisely target and conduct experiments with specific named experiments. By selecting experiments directly by name, you can easily control and track the performance of various tests, which enables efficient optimization and analysis for better user experiences and product improvements.

Usage examples#

Choose all personalizations:
Choose personalizations by groups:

Optimization choose response structure#

[
  {
    "name": "login", // optimization name
    "group": "banner", // optimization choose
    "body": [ // body provided in Intempt application
      {
        "banner": "holiday-banner"
      }
    ]
  }
]

Field Type Validation#

When sending custom events, it’s important that each field matches the data type defined in your event schema. If a field’s type changes (e.g., from a string to an object), the event will be rejected. This ensures data consistency and prevents errors.
Example:
If the field name is defined as a string in the schema:
What to do?
Always ensure that event fields retain the same type as defined in your schema.

Adding New Fields to Custom Events#

You can now safely add new fields to your custom event schema without impacting existing fields. This allows you to extend your event tracking capabilities while keeping previous fields intact and functional.
Example:
Original event - After adding a new field
Existing fields will remain usable even after schema updates.

Recommendation#

The method allows you to get products from a feed using an ID. Fields and quantity are configurable parameters to select the fields returned in the response and the number of products from the feed. Sending nulls means that all fields will be returned, and the product amount will be limited to 5. The product ID is a nullable parameter, and it's necessary for feeds with product input, like "Purchased Together".
This example retrieves five recommended products using the feed with ID 111090, including only the title, image URL, and price in the response.

Declaration#

Parameters
profileId (string, required) – User profile identifier
feedId (number, required) – The ID of the feed used to generate recommendations
quantity (number, optional) – The number of recommended products to return. Defaults to 5
fields (string[], optional) – A list of product attributes to include in the response (e.g., ["title", "image_url", "price"])
productId (string, optional) - The unique identifier of the product
Returns
A Promise that resolves to an array of recommended products.
This method provides full flexibility in fetching and displaying personalized product recommendations based on predefined feed settings.

SDK provides additional methods for product events#

Product Add#

The productAdd method emits an event when a product is added to the cart.

Declaration#

Parameters
profileId (string, required) – User profile identifier
productId (string, required) - The unique identifier of the product being added to the cart
quantity (number, optional) – The number of units added to the cart
Returns
A Promise<void> that resolves once the event is emitted.

Example#

This logs the addition of a product to the shopping cart, triggering an "Added to cart" event.

Product Ordered#

The productOrdered method emits an event when a list of products is ordered, ensuring all products have valid details.

Declaration#

Parameters
profileId (string, required) – User profile identifier
products (array, required) - Array of products
Returns
A Promise<void> that resolves once the event is emitted.

Example#

This triggers an order event for multiple products.

Product View#

The productView method emits an event when a product is viewed by the user.

Declaration#

Parameters
profileId (string, required) – User profile identifier
productId (string, required) - The unique identifier of the product being viewed
Returns
A Promise<void> that resolves once the event is emitted.

Example#

This triggers an event when a product is viewed by the user.
Modified at 2025-12-03 09:48:07
Previous
iOS SDK
Next
Track data
Built with