track()
The track() method records a custom event with a name and optional properties. Use it to capture user actions, conversions, and business events that matter to your analytics and marketing vendors.
Syntax
datafly.track(eventName, properties?)Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
eventName | string | Yes | The name of the event (e.g., 'purchase') |
properties | Record<string, unknown> | No | Key-value pairs describing the event |
Returns
void
Basic usage
datafly.track('sign_up', { method: 'email' });E-commerce example
datafly.track('purchase', {
transaction_id: 'ORD-12345',
value: 99.99,
currency: 'USD',
items: [
{ item_id: 'SKU-001', item_name: 'Running Shoes', price: 79.99, quantity: 1 },
{ item_id: 'SKU-042', item_name: 'Sport Socks', price: 9.99, quantity: 2 },
],
coupon: 'SUMMER20',
tax: 8.00,
shipping: 5.99,
});Standard e-commerce events
Datafly uses GA4-compatible event names. If you’re migrating from Google Tag Manager, your existing event names work as-is. Signal’s blueprints automatically map these to vendor-specific formats during server-side delivery.
| Event name | Description | Key properties |
|---|---|---|
view_item | User viewed a product detail page | item_id, item_name, price, currency |
view_item_list | User viewed a product listing or category page | item_list_id, item_list_name, items[] |
select_item | User clicked a product from a list | item_id, item_name, item_list_id |
add_to_cart | User added a product to cart | item_id, item_name, price, quantity |
remove_from_cart | User removed a product from cart | item_id, item_name, price, quantity |
view_cart | User viewed their shopping cart | items[], value, currency |
begin_checkout | User started the checkout flow | value, currency, items[], coupon |
add_shipping_info | User entered shipping details | value, currency, shipping_tier |
add_payment_info | User entered payment information | value, currency, payment_type |
purchase | User completed a purchase | transaction_id, value, currency, items[], tax, shipping |
refund | An order was refunded | transaction_id, value, items[] |
search | User searched for products | search_term |
The items[] array uses GA4-style field names (item_id, item_name, item_category, item_brand, price, quantity). Signal’s server-side blueprints automatically transform these to vendor-specific formats — for example, Meta CAPI’s contents[] with id/title fields.
Vendor mapping
When you use standard event names, Signal automatically maps them to vendor-specific events via blueprints:
| Signal event | GA4 event | Meta event | TikTok event |
|---|---|---|---|
view_item | view_item | ViewContent | ViewContent |
view_item_list | view_item_list | ViewContent | ViewContent |
select_item | select_item | ViewContent | ClickButton |
add_to_cart | add_to_cart | AddToCart | AddToCart |
begin_checkout | begin_checkout | InitiateCheckout | InitiateCheckout |
add_payment_info | add_payment_info | AddPaymentInfo | AddPaymentInfo |
purchase | purchase | Purchase | PlaceAnOrder |
search | search | Search | Search |
add_to_wishlist | add_to_wishlist | AddToWishlist | AddToWishlist |
sign_up | sign_up | CompleteRegistration | CompleteRegistration |
Other standard events
Engagement
| Event name | Description | Key properties |
|---|---|---|
view_promotion | User saw a promotional banner | promotion_id, promotion_name, creative_name |
select_promotion | User clicked a promotional banner | promotion_id, promotion_name, creative_name |
add_to_wishlist | User saved a product to their wishlist | item_id, item_name, value |
remove_from_wishlist | User removed a product from their wishlist | item_id, item_name |
share | User shared content | method, content_type, item_id |
Authentication & leads
| Event name | Description | Key properties |
|---|---|---|
sign_up | User completed registration | method |
login | User logged in | method |
generate_lead | A new lead was created | value, currency |
Custom events
You are not limited to standard event names. Track any event relevant to your business:
datafly.track('video_start', {
video_id: 'vid-789',
video_title: 'Product Demo',
video_duration: 120,
});
datafly.track('outbound_click', {
retailer_name: 'Amazon',
link_url: 'https://amazon.co.uk/dp/B001234',
click_type: 'product',
item_id: 'SKU-001',
});
datafly.track('copy_voucher_code', {
voucher_code: 'SAVE20',
retailer_name: 'Nike',
discount_type: 'percentage',
discount_value: '20',
});Custom events are delivered to vendors as custom/generic events and can be mapped to vendor-specific events using blueprint configuration.
Cross-platform deduplication with event_id
Pass an event_id property on conversion events to enable native deduplication against your existing vendor pixels (Meta Pixel, TikTok Pixel, Pinterest Tag, etc.). When the same event_id reaches a vendor via both their pixel and Signal’s server-side delivery, the vendor recognises them as the same event and counts it once.
datafly.track('purchase', {
event_id: order.id, // Same value as the Pixel's eventID parameter
transaction_id: order.id,
value: 99.99,
currency: 'GBP',
});On the corresponding pixel call, set the matching ID:
// Meta Pixel
fbq('track', 'Purchase', { value: 99.99, currency: 'GBP' }, { eventID: order.id });
// TikTok Pixel
ttq.track('PlaceAnOrder', { value: 99.99, currency: 'GBP', event_id: order.id });If you don’t pass event_id, Signal still sends a generated messageId to the vendor — but the vendor can’t match it to your pixel events, so cross-platform dedup won’t work. See Cross-Platform Deduplication for vendor-specific guidance.
The event_id property is promoted from properties to the top-level eventId envelope field before delivery. Customer’s event_id mappings in the integration blueprint take priority; the envelope value is used as a fallback.
Event payload
A track() call produces an event with type: "track":
{
"type": "track",
"event": "purchase",
"anonymousId": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
"userId": "user-123",
"properties": {
"transaction_id": "ORD-12345",
"value": 99.99,
"currency": "GBP",
"items": [
{ "item_id": "SKU-001", "item_name": "Running Shoes", "price": 79.99, "quantity": 1 }
]
},
"context": {
"page": {
"url": "https://example.com/checkout/confirmation",
"path": "/checkout/confirmation",
"referrer": "https://example.com/checkout/payment",
"title": "Order Confirmation",
"search": ""
},
"screen": { "width": 1920, "height": 1080 },
"locale": "en-GB",
"timezone": "Europe/London",
"userAgent": "Mozilla/5.0 ...",
"library": { "name": "@datafly/collector", "version": "0.1.0" }
},
"timestamp": "2026-02-25T14:22:00.000Z",
"messageId": "df-b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e"
}Batching
Events are not sent individually. Datafly.js batches up to 10 events per request and auto-flushes every 1 second. If 10 events accumulate before the flush interval, the batch is sent immediately.
Events are also flushed when the user navigates away from the page (via visibilitychange and pagehide listeners), using navigator.sendBeacon to ensure delivery survives page unload.
To force an immediate flush:
datafly.track('purchase', { transaction_id: 'ORD-12345', value: 99.99, currency: 'GBP' });
datafly.flush();Property naming conventions
Use consistent, snake_case property names across your events:
- Use
snake_casefor property names (transaction_id, notorderIdorTransactionId) - Use GA4 standard property names when they exist (see the e-commerce table above)
- Include
currencyas an ISO 4217 code whenever you send monetary values - Include
valuefor conversion events to enable revenue attribution - Use
items[]for product arrays withitem_id,item_name,price,quantity
Do not include personally identifiable information (PII) such as email addresses, phone numbers, or names in track() properties. Use the identify() method to associate PII with a user — Signal hashes PII server-side before delivering it to vendors.