Skip to main content
This page provides detailed documentation for all configuration options available when initializing the ConstructorIO client.

ConstructorClientOptions

The main options object passed to the ConstructorIO constructor.
interface ConstructorClientOptions {
  apiKey: string;
  version?: string;
  serviceUrl?: string;
  quizzesServiceUrl?: string;
  agentServiceUrl?: string;
  mediaServiceUrl?: string;
  assistantServiceUrl?: string;
  sessionId?: number;
  clientId?: string;
  userId?: string;
  segments?: string[];
  testCells?: Record<string, string>;
  idOptions?: IdOptions;
  fetch?: any;
  trackingSendDelay?: number;
  sendTrackingEvents?: boolean;
  sendReferrerWithTrackingEvents?: boolean;
  eventDispatcher?: EventDispatcherOptions;
  beaconMode?: boolean;
  networkParameters?: NetworkParameters;
  humanityCheckLocation?: 'session' | 'local';
}

Required Options

apiKey
string
required
Your Constructor.io API key for authentication. This is the only required parameter.
const constructorio = new ConstructorIO({
  apiKey: 'key_1234567890abcdef'
});

Service URLs

serviceUrl
string
default:"https://ac.cnstrc.com"
The base API URL endpoint for the main Constructor.io service. Use this to point to a custom endpoint or proxy.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  serviceUrl: 'https://custom.cnstrc.com'
});
quizzesServiceUrl
string
default:"https://quizzes.cnstrc.com"
API URL endpoint for the Quizzes service.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  quizzesServiceUrl: 'https://custom-quizzes.cnstrc.com'
});
agentServiceUrl
string
default:"https://agent.cnstrc.com"
API URL endpoint for the AI Shopping Agent service.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  agentServiceUrl: 'https://custom-agent.cnstrc.com'
});
mediaServiceUrl
string
default:"https://media-cnstrc.com"
API URL endpoint for the Media service.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  mediaServiceUrl: 'https://custom-media.cnstrc.com'
});
assistantServiceUrl
string
default:"https://assistant.cnstrc.com"
Deprecated: Use agentServiceUrl instead. This parameter will be removed in a future version.
API URL endpoint for the AI Shopping Assistant service (legacy).

User Identification

clientId
string
A unique identifier for the client/browser. In browser environments, this defaults to a value automatically generated by the constructorio-id module. In DOM-less environments (Node.js, etc.), this is required.
// DOM-less environment (Node.js)
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  clientId: 'client-abc123def456',
  sessionId: 12345678
});
sessionId
number
A unique identifier for the user session. In browser environments, this defaults to a value automatically generated by the constructorio-id module. In DOM-less environments (Node.js, etc.), this is required.
// DOM-less environment (Node.js)
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  clientId: 'client-abc123def456',
  sessionId: Date.now()
});
userId
string
A unique identifier for the logged-in user. This should be set when a user is authenticated and used for personalization and tracking.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  userId: 'user-789xyz'
});

Personalization & Testing

segments
string[]
An array of user segments for personalization and targeting. Segments allow you to customize results for different user groups.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  segments: ['premium', 'mobile', 'returning-customer']
});
testCells
Record<string, string>
An object mapping test names to variant names for A/B testing. This allows you to assign users to specific test variants.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  testCells: {
    'homepage-redesign': 'variant-b',
    'search-algorithm': 'control',
    'checkout-flow': 'variant-a'
  }
});

Tracking Configuration

sendTrackingEvents
boolean
default:false
Indicates whether tracking events should be automatically dispatched to Constructor.io. When enabled, user interactions are tracked automatically.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  sendTrackingEvents: true
});
trackingSendDelay
number
default:250
The amount of time (in milliseconds) to wait before sending tracking events. This batching helps reduce the number of requests.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  sendTrackingEvents: true,
  trackingSendDelay: 500 // Wait 500ms before sending
});
sendReferrerWithTrackingEvents
boolean
default:true
Indicates whether the referrer URL should be included with tracking events.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  sendTrackingEvents: true,
  sendReferrerWithTrackingEvents: false
});
beaconMode
boolean
default:true
Enable or disable beacon mode for tracking. When enabled, the Navigator.sendBeacon() API is used for sending tracking data, which is more reliable for events sent during page unload.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  beaconMode: true
});

Network Configuration

fetch
function
A custom fetch implementation. If supplied, this will be used for all HTTP requests instead of the default Fetch API. Useful for server-side rendering or custom request handling.
import nodeFetch from 'node-fetch';

const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  fetch: nodeFetch
});
networkParameters
NetworkParameters
Configuration for network requests.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  networkParameters: {
    timeout: 5000 // 5 second timeout
  }
});

Event Dispatcher Options

eventDispatcher
EventDispatcherOptions
Configuration for the event dispatcher system.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  eventDispatcher: {
    enabled: true,
    waitForBeacon: true
  }
});

Storage Configuration

humanityCheckLocation
'session' | 'local'
default:"session"
The storage location for the humanity check flag. Use 'session' for sessionStorage or 'local' for localStorage.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  humanityCheckLocation: 'local' // Use localStorage
});
idOptions
IdOptions
Configuration options for the constructorio-id module, which manages client and session identification. See IdOptions below for details.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  idOptions: {
    persist: true,
    cookie_domain: '.example.com',
    cookie_days_to_live: 365
  }
});

Advanced Options

version
string
Custom version string for the client. This is typically auto-generated and should not be manually set unless you have a specific use case.
const constructorio = new ConstructorIO({
  apiKey: 'YOUR_API_KEY',
  version: 'custom-client-v1.0.0'
});

IdOptions

Configuration options for the constructorio-id module, which manages client and session identification.
interface IdOptions {
  base_url?: string;
  ip_address?: string;
  user_agent?: string;
  timeout?: number;
  persist?: boolean;
  cookie_name_client_id?: string;
  cookie_name_session_id?: string;
  cookie_name_session_data?: string;
  local_name_client_id?: string;
  local_name_session_id?: string;
  local_name_session_data?: string;
  cookie_prefix_for_experiment?: string;
  cookie_domain?: string;
  cookie_days_to_live?: number;
  on_node?: boolean;
  session_is_new?: boolean;
  client_id_storage_location?: 'cookie' | 'local';
  session_id_storage_location?: 'cookie' | 'local';
}
persist
boolean
Whether to persist client and session IDs across browser sessions.
The domain for storing cookies. Use a leading dot for subdomains (e.g., .example.com).
idOptions: {
  cookie_domain: '.mystore.com'
}
Number of days before cookies expire.
idOptions: {
  cookie_days_to_live: 365
}
client_id_storage_location
'cookie' | 'local'
default:"cookie"
Storage location for the client ID. Can be either 'cookie' or 'local' (localStorage).
idOptions: {
  client_id_storage_location: 'local'
}
session_id_storage_location
'cookie' | 'local'
default:"local"
Storage location for the session ID. Can be either 'cookie' or 'local' (localStorage).
idOptions: {
  session_id_storage_location: 'cookie'
}
Custom name for the client ID cookie.
Custom name for the session ID cookie.
Custom name for the session data cookie.
local_name_client_id
string
Custom name for the client ID in localStorage.
local_name_session_id
string
Custom name for the session ID in localStorage.
local_name_session_data
string
Custom name for the session data in localStorage.
Prefix for experiment-related cookies.
base_url
string
Base URL for the ID service.
ip_address
string
IP address of the client (typically used in server-side environments).
user_agent
string
User agent string (typically used in server-side environments).
timeout
number
Timeout for ID service requests (in milliseconds).
on_node
boolean
Indicates if running in a Node.js environment.
session_is_new
boolean
Indicates if this is a new session.

EventDispatcherOptions

Configuration options for the event dispatcher.
interface EventDispatcherOptions {
  enabled?: boolean;
  waitForBeacon?: boolean;
}
enabled
boolean
default:true
Determines whether events should be dispatched.
eventDispatcher: {
  enabled: true
}
waitForBeacon
boolean
default:true
Whether to wait for beacon confirmation before dispatching events.
eventDispatcher: {
  enabled: true,
  waitForBeacon: false
}

NetworkParameters

Configuration for network requests.
interface NetworkParameters {
  timeout?: number;
  [key: string]: any;
}
timeout
number
Request timeout in milliseconds. This can be overridden within individual method calls.
networkParameters: {
  timeout: 5000 // 5 seconds
}

Complete Example

Here’s a comprehensive example using many of the available options:
import ConstructorIO from '@constructor-io/constructorio-client-javascript';

const constructorio = new ConstructorIO({
  // Required
  apiKey: 'key_1234567890abcdef',
  
  // User identification
  userId: 'user-abc123',
  
  // Personalization
  segments: ['premium', 'mobile', 'returning-customer'],
  testCells: {
    'homepage-redesign': 'variant-b',
    'search-algorithm': 'control'
  },
  
  // Tracking
  sendTrackingEvents: true,
  trackingSendDelay: 500,
  sendReferrerWithTrackingEvents: true,
  beaconMode: true,
  
  // Network
  networkParameters: {
    timeout: 5000
  },
  
  // Event dispatcher
  eventDispatcher: {
    enabled: true,
    waitForBeacon: true
  },
  
  // ID management
  idOptions: {
    persist: true,
    cookie_domain: '.mystore.com',
    cookie_days_to_live: 365,
    client_id_storage_location: 'local',
    session_id_storage_location: 'local'
  },
  
  // Storage
  humanityCheckLocation: 'local'
});

DOM-less Environment Example

For server-side rendering or Node.js environments:
import ConstructorIO from '@constructor-io/constructorio-client-javascript';
import nodeFetch from 'node-fetch';

const constructorio = new ConstructorIO({
  // Required
  apiKey: 'key_1234567890abcdef',
  
  // Required in DOM-less environments
  clientId: 'client-abc123def456',
  sessionId: Date.now(),
  
  // User identification
  userId: 'user-789xyz',
  
  // Custom fetch implementation
  fetch: nodeFetch,
  
  // Network configuration
  networkParameters: {
    timeout: 5000
  },
  
  // Personalization
  segments: ['server-side', 'premium'],
  testCells: {
    'search-v2': 'enabled'
  }
});

Build docs developers (and LLMs) love