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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| platform | string | Optional | Platform name, used as the event source (e.g. magento2, woocommerce) |
| shop | string | Optional | Store 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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Required | Contact email address | |
| properties | object | Optional | Additional 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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Required | Customer email address |
emk('setCustomer', '[email protected]');emk('track')
Track a custom event for the current identified contact.
| Parameter | Type | Required | Description |
|---|---|---|---|
| eventName | string | Required | Event name (e.g. viewed_product, added_to_cart) |
| properties | object | Optional | Event 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 Name | Description | Aliases |
|---|---|---|
| viewed_product | A shopper viewed a product page | product_viewed |
| collection_viewed | A shopper viewed a collection or category | category_viewed |
| search_submitted | A shopper ran a search | searched, search |
| added_to_cart | A shopper added an item to the cart | product_added_to_cart |
| removed_from_cart | A shopper removed an item from the cart | product_removed_from_cart |
| cart_viewed | A shopper viewed the cart | — |
| started_checkout | A shopper began checkout | checkout_started |
| checkout_completed | A shopper completed checkout | — |
| active_on_site | A shopper is active on the site | — |
| product_clicked | A shopper clicked a product (e.g. in a list) | — |
| form_submitted | A 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" }
}'