Integration

JavaScript API

Browser snippet reference for the ci.js library.

How It Works

The ci.js library provides a simple, function-based API for tracking events. It:

  • Loads asynchronously to avoid blocking page rendering
  • Queues commands until fully loaded, then replays them
  • Automatically generates session IDs for grouping
  • Adds timestamps and environment info to events
  • Handles retries on transient failures (coming soon)

API Methods

ci('init', config)

Initialize the Commerce Index client with your brand credentials.

Parameters

brandIdstring
Required
Your assigned brand identifier
apiKeystringOptional API key for server-side validation
debugbooleanEnable console logging for debugging

Example

ci('init', {
  brandId: 'brand_xyz',
  debug: true  // Enable for development
});
ci('trackView', payload)

Track a product page view. Call this when a user loads a PDP.

Parameters

productIdstring
Required
Your internal product identifier
productSkustringProduct SKU or variant ID
productTitlestringProduct title for debugging
productUrlstringFull URL of the product page

Example

ci('trackView', {
  productId: 'prod_123',
  productSku: 'SKU-123-RED-M',
  productTitle: 'Red Performance Legging',
  productUrl: window.location.href
});
ci('trackPurchase', payload)

Track a completed purchase. Call this on the order confirmation page.

Parameters

orderIdstring
Required
Your internal order identifier
currencystring
Required
ISO 4217 currency code (USD, EUR, etc.)
itemsarray
Required
Array of purchased items
totalValuenumberTotal order value for analytics

Example

ci('trackPurchase', {
  orderId: 'order_789',
  currency: 'USD',
  totalValue: 129.97,
  items: [
    {
      productId: 'prod_123',
      productSku: 'SKU-123-RED-M',
      productTitle: 'Red Performance Legging',
      quantity: 2,
      value: 39.99
    },
    {
      productId: 'prod_456',
      productSku: 'SKU-456-BLACK',
      productTitle: 'Black Sports Bra',
      quantity: 1,
      value: 49.99
    }
  ]
});

Item Schema (for trackPurchase)

productIdstring
Required
Must match product_id from view events
productSkustringSKU or variant identifier
productTitlestringProduct title
quantitynumberNumber purchased (default: 1)
valuenumberUnit price for analytics

Current Version: ci.js v1.0.0

Check ci.version in console to verify loaded version.