Event Tracking
Use allegro.track() to record events. The SDK handles session creation, device
identification, and page metadata collection automatically.
Basic Usage
window.allegro.push(function (allegro) {
allegro.track('page_view');
});
allegro.track(eventName, data?)
Track an event. Returns a promise that resolves with { event_id: string }.
The SDK automatically:
- Creates a session if one doesn't exist
- Includes device ID, session ID, and CSRF token
- Collects page metadata from the DOM (title, content type, publisher, etc.)
- Attaches the logged-in customer ID if available
With event data
allegro.track('article_read', {
content_id: 'article-456',
content_type: 'premium',
publisher: 'Daily News',
});
With custom data
allegro.track('purchase', {
data: {
product_id: 'sku-789',
price: 9.99,
currency: 'USD',
},
});
Available fields
| Field | Type | Description |
|---|---|---|
url | string | Page URL (auto-collected by default) |
referer | string | Referring URL |
page_title | string | Page title |
content_type | string | Content type (e.g. article, video) |
content_id | string | Content identifier |
publisher | string | Publisher name |
object_type | string | Object type |
object_id | string | Object identifier |
context | string | Context or category |
conversion_pv_id | string | Conversion page view ID |
url_in_click | string | Clicked URL |
data | Record<string, unknown> | Arbitrary custom data |
For more information, see Page Metadata.
Session & Device Management
The SDK manages two cookies:
| Cookie | Lifetime | Purpose |
|---|---|---|
allegro_device_id | 10 years | Persistent device identifier (UUID v4) |
allegro_session_id | 30 minutes | Session identifier, extended on activity |
Sessions are created automatically on the first track() or member.login()
call. Each track() call extends the session timeout.