JavaScript SDK

Track visitor behavior on your website with a lightweight JavaScript snippet.

Quick Start

Add this snippet to your site's <head> tag:

<script>
  !function(){var e=window.emk=function(){e.q.push(arguments)};e.q=[];
  var s=document.createElement("script");s.async=true;
  s.src="https://cdp-api.sidcorp.co/emk.js?s=YOUR_SITE_ID";
  document.head.appendChild(s)}();
</script>

The ?s= parameter initializes the SDK automatically and starts tracking page views — no extra call is needed. You can queue emk('identify', …) / emk('track', …) calls immediately; they run once the script finishes loading.

emk('config')

Set optional global context that is attached to every tracked event. Initialization itself happens automatically from the ?s= parameter on the script URL, so config is optional — use it mainly for e-commerce integrations.

ParameterTypeRequiredDescription
platformstringOptionalPlatform name, used as the event source (e.g. magento2, woocommerce)
shopstringOptionalStore domain, attached to events as _shop
emk('config', { platform: 'magento2', shop: 'mystore.com' });

If you load emk.js without the ?s= parameter, call emk('init', 'YOUR_SITE_ID') once to set your workspace ID and start tracking.

emk('identify')

Identify a visitor by email. Links all subsequent events to this contact. Creates the contact if it doesn't exist.

ParameterTypeRequiredDescription
emailstringRequiredContact email address
propertiesobjectOptionalAdditional properties (first_name, last_name, phone, etc.)
emk('identify', '[email protected]', {
  first_name: 'Jane',
  last_name: 'Doe',
  phone: '+1234567890'
});

emk('setCustomer')

Identify the logged-in customer by email — typically rendered server-side by your e-commerce platform (Shopify, WooCommerce, Magento). Takes a single email string and silently skips if the same email is already identified. For richer profile data (name, phone, …) use identify instead.

ParameterTypeRequiredDescription
emailstringRequiredCustomer email address
emk('setCustomer', '[email protected]');

emk('track')

Track a custom event for the current identified contact.

ParameterTypeRequiredDescription
eventNamestringRequiredEvent name (e.g. viewed_product, added_to_cart)
propertiesobjectOptionalEvent properties
emk('track', 'viewed_product', {
  product_id: 'SKU-123',
  product_name: 'Blue T-Shirt',
  price: 29.99,
  currency: 'USD'
});

Standard Events

These event names are recognized by the platform — each can trigger automation flows and be used as a segment condition. Aliases are accepted interchangeably and normalized to the canonical name.

Event NameDescriptionAliases
viewed_productA shopper viewed a product pageproduct_viewed
collection_viewedA shopper viewed a collection or categorycategory_viewed
search_submittedA shopper ran a searchsearched, search
added_to_cartA shopper added an item to the cartproduct_added_to_cart
removed_from_cartA shopper removed an item from the cartproduct_removed_from_cart
cart_viewedA shopper viewed the cart—
started_checkoutA shopper began checkoutcheckout_started
checkout_completedA shopper completed checkout—
active_on_siteA shopper is active on the site—
product_clickedA shopper clicked a product (e.g. in a list)—
form_submittedA visitor submitted a form—

You can also send any custom event name — it becomes selectable as a flow trigger and segment condition automatically. Purchase and order events (Placed Order, Ordered Product, Refunded Order, …) are ingested from your store integration's webhooks rather than via emk('track').

REST Endpoints

You can also use the tracking endpoints directly without the JavaScript SDK:

POST/collect/identify

Identify a contact by email.

curl -X POST https://cdp-api.sidcorp.co/collect/identify \
  -H "Content-Type: application/json" \
  -d '{
    "site_id": "YOUR_SITE_ID",
    "email": "[email protected]",
    "properties": { "first_name": "Jane" }
  }'

POST/collect/event

Track a custom event.

curl -X POST https://cdp-api.sidcorp.co/collect/event \
  -H "Content-Type: application/json" \
  -d '{
    "site_id": "YOUR_SITE_ID",
    "contact_id": "CONTACT_ID",
    "event_name": "viewed_product",
    "properties": { "product_id": "SKU-123" }
  }'