Skip to main content

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​

FieldTypeDescription
urlstringPage URL (auto-collected by default)
refererstringReferring URL
page_titlestringPage title
content_typestringContent type (e.g. article, video)
content_idstringContent identifier
publisherstringPublisher name
object_typestringObject type
object_idstringObject identifier
contextstringContext or category
conversion_pv_idstringConversion page view ID
url_in_clickstringClicked URL
dataRecord<string, unknown>Arbitrary custom data

For more information, see Page Metadata.

Triggering workflows​

Every event you track can start a workflow, move a run that is waiting for it, or end a run as the workflow's exit event. Operators pick the event by name in the workflow editor, so a custom event your site sends appears there once it has been recorded, and can be typed in before that.

To be usable in a workflow, an event name must:

  • Use only letters, numbers, _, and -, in one or more parts separated by dots: purchase, newsletter-signup, donation.received. Names with spaces or other characters can be tracked but can't be picked in a workflow.
  • Not be page_view, page_ping, or journey_activity. They fire on every page load, so workflows ignore them.

A workflow run belongs to a member, so an event only reaches workflows when the visitor is signed in on the device that sends it. Events from anonymous visitors are ignored.

The event's data object is what workflows see as the event's data. Operators test its fields in conditions and insert them into workflow emails as {% event.<field> %}, with dots for nested fields:

window.allegro.push(function (allegro) {
allegro.track('cart_updated', {
data: {
cart: { items: 3, total: 42.5 },
plan: 'pro',
},
});
});

Here a workflow email can use {% event.plan %} and {% event.cart.total %}. Allegro adds the page path, host name, UTM parameters, and property slug to the data when they're known. Other top-level fields, such as content_id, are recorded for analytics but aren't part of the data workflows see. Keep the field names stable, since operators build conditions and emails against them.

Session & Device Management​

The SDK manages two cookies:

CookieLifetimePurpose
allegro_device_id10 yearsPersistent device identifier (UUID v4)
allegro_session_id30 minutesSession identifier, extended on activity

Sessions are created automatically on the first track() or member.login() call. Each track() call extends the session timeout.