Skip to main content
Complete reference for @datalyr/web, which sends events to https://ingest.datalyr.com. For a first install, start with Install web tracking.

Install

The script tag reads these attributes:
Never load the script tag and the npm package together. Two instances issue two visitor_id values for one person and split the journey.
init() throws when workspaceId is missing. Tracking methods called before init() warn and return.

What the SDK tracks without your code

Two triggers fire on their own: Nothing else is automatic: no clicks, scrolls, form submits, outbound links, or errors. There is no session-start event, because session data rides on every event. Call track() for everything else.

Events the SDK sends for you

These names are reserved. Never send one yourself.

Identity

Four identifiers ship on every event. They are not alternatives to each other. Use visitor_id in server-side and webhook work. Stripe, Whop, and Shopify all key off it. Use distinct_id when you reason about event-level identity.
The Events and Conversions tables label this column distinct id. For an unidentified visitor it shows the visitor_id. Search there to trace a visitor.
Call it after sign-in. Passing a different user_id runs reset() first, so two people on one browser do not merge.

Identity methods

reset and alias

Call reset() on logout. It clears user_id, traits, super properties, the captured email, the journey, and both touchpoints, then issues a new visitor_id and session. It leaves the Meta _fbc and _fbp cookies in place.
alias(userId, previousId?) accepts only the current anonymous ID as previousId. Any other value logs a warning and does nothing.
Do not call reset() on every page load. A new visitor_id breaks the link between the campaign visit and the later conversion.

Track an event

Page views

Use page() only with automatic tracking off, or for a second view on one URL.

Attribution

First touch and last touch persist for the attributionWindow, 90 days by default.

Click IDs captured

The SDK reads these 15 parameters from the URL. Matching is case-sensitive. These are normalized to a canonical name: A URL carrying several click IDs sends all of them. clickIdType takes the first match in the order above. Any click ID forces medium to cpc.

Campaign parameters captured

Each UTM is sent twice: under its full name and under its stripped alias, so utm_source and source.

Ad platform cookies read

Campaign parameters survive a marketing decline. The SDK writes _fbc and _fbp itself when a fbclid arrives and Meta has not set them. Both last 90 days.
setConsent() is safe to call before init(). The SDK stores the choice and applies it at initialization. privacyMode: 'strict' forces autoIdentify off and stops email prefill on Stripe links. The SDK honors Global Privacy Control by default, and ignores Do Not Track unless respectDoNotTrack is true.

Checkout metadata

Pass getStripeMetadata() into the Stripe object your server creates. See Stripe for each surface. Whop metadata is optional. Use getWhopCheckoutMetadata() only when your code creates the Whop checkout configuration. With stripePaymentLinks on, the SDK stamps: prefilled_email is skipped when prefilled_email or locked_prefilled_email is already present, or privacyMode is strict. The SDK re-stamps on click and watches the DOM for new links, debounced at 150 ms.
The SDK never decorates checkout.stripe.com URLs, because Stripe ignores these parameters on an already-created Checkout Session. It also cannot reach links opened with window.open(), links inside an iframe, or links in shadow DOM. Call getVisitorId() and pass the value yourself in those cases.

Super properties

Super properties attach to every later event. reset() clears them.

Complete method list

The default export and window.datalyr are one shared singleton. createDatalyrInstance() returns a second independent instance.

Configuration

Only workspaceId is required.
sessionTimeout and attributionWindow are milliseconds, not minutes or days. Setting sessionTimeout: 60 expires the session after 60 milliseconds.
Datalyr can set autoIdentify, autoIdentifyForms, autoIdentifyAPI, autoIdentifyShopify, shopifyCartAttributes, checkoutChampDomains, respectGlobalPrivacyControl, respectDoNotTrack, and privacyMode remotely. A value you pass to init() always wins over the remote value.

Limits

There is no per-event size limit. Only the transport limits above apply.

How failed requests behave

Storage

__dl_visitor_id is written on the root domain with SameSite=Lax, and Secure on HTTPS. A failed root-domain write falls back to a host-only cookie. State lives in localStorage under a dl_dl_ prefix, for example dl_dl_anonymous_id and dl_dl_offline_queue. Traits and the captured email are encrypted with AES-GCM.

Lifecycle

flush() sends everything queued. destroy() removes listeners and stops the SDK. Use it only when you tear the integration down for good.

Verify the install

  1. Open your published site in a private window.
  2. Open Events in Datalyr.
  3. Confirm a pageview arrives with your URL, within 30 seconds.
If nothing arrives, set debug: true, then call getErrors() and getNetworkStatus(). See No events.