JavaScript

The Lumen JavaScript SDK allows you to seamlessly identify and track user attributes and events on your client. Plus other perks.

Setup your Lumen Account

To begin, you'll need to set up your Lumen account and obtain an API key. Here's how:

  1. Navigate to Settings: Log in to your Lumen Dashboard, and from the main menu, go to "Settings."

  2. API Key Tab: In the Settings section, select the "API Key" tab to access and copy your unique API key.

Installation

Once you have your API key, you can install the Lumen SDK using either npm or yarn. It's compatible with various environments, including the browser, Node.js, and React Native. Here are the installation commands:

Using npm:

npm install lumen-js

Or using yarn:

yarn add lumen-js

Initialization

To use the SDK, you have to initialize the SDK with your public key. Any request that doesn't include a valid API key will return an error.

You can generate an API key from your Dashboard at any time.

import Lumen from 'lumen-js'

const lumenClient = Lumen({
    publicKey: "<- your-api-key ->"
})

Identify a user

Before tracking events, you need to identify users with a unique identifier. If the identifier doesn't exist, a new customer record is created. If it does exist, the customer record is updated with the provided data.

Here's how to identify a user:

lumenClient.identify("identifier", {
    email: "email",
    first_name: "john",
    last_name: "doe",
})

You can also add custom attributes when identifying a user. Custom attributes are additional pieces of information that provide context or specific details about the user

lumenClient.identify("identifier", {
    email: "email",
    first_name: "john",
    last_name: "doe",
    attributes: {
        "age": 20,
        "hasCompletedVerification": false,
    }
})

Ideally, you should call the identify function when a user creates a new account. To update an existing user's records, simply call identify and add or change any properties you want. Existing properties are overwritten, and new ones are added to the user's record.

To ensure your data is in sync with our record, make sure you update your user's records when they change so as to prevent stale data.

You can manage your user records on the dashboard.

Track an event

Once you've identified users, you can start capturing their actions, such as "Product Clicked" or "Product Viewed," along with any custom properties. Here's how to track an event:

Basic Event Tracking:

lumenClient.track("identifier", "Clicked 'Add To Cart'");

Event Tracking with Custom Properties:

const customProperties = {
    sku: "skksosownw", 
    category: "electronics",
};

lumenClient.track("identifier", "Clicked 'Add To Cart'", customProperties);

By following these steps, you'll be able to set up and use the Lumen SDK effectively to track user events and analyze user behavior in your application. If you have any questions or need further assistance, please refer to our comprehensive documentation or reach out to our support team.

Last updated