Skip to main content
Add one script to your website. It records page views and campaign context on every page, with no other code.

Before you start

You need permission to publish the site, and your workspace ID. Open Settings → Install to find the snippet. A new workspace also shows it on Overview until the first event arrives.

Install the snippet

Put the snippet on every page, not only the confirmation page. We connect a conversion to a campaign using the landing visit, so without that visit the conversion arrives with no campaign.
1

Copy your snippet

Open Settings → Install and copy the snippet. Your workspace ID is already in it.
2

Paste it in the head

Add it inside <head>, before the closing </head> tag. Use your shared template.
3

Publish the site

A draft or local change cannot send production visits.
4

Visit the published page

Use a private window. The test then starts with a new visitor and session.
Use the exact workspace ID that Datalyr shows. An ID from another workspace sends your data to that workspace.

Where to put it

Install with npm instead

Use the package when your application controls its own JavaScript lifecycle.
Choose the snippet or the package. Never load both on one page. Two instances issue two visitor_id values for one person and split the journey.

What you get without more code

The snippet sends a pageview event when the page loads, and again on every route change in a single-page application. Each event carries the URL, referrer, campaign parameters, ad click IDs, browser context, and session data. For the exact parameters captured, see Attribution in the Web SDK. Nothing else is automatic. The SDK does not track clicks, scrolls, form submits, or outbound links. There is no separate session event, because session data rides on every event. To record what matters to your business, add two things:
  • identify after sign-in, so visits become people;
  • track for signup, lead, or checkout actions.

Verify

  1. Open the published page in a private window.
  2. Open Events in Datalyr.
  3. Find a pageview with the URL you visited. It arrives within 30 seconds.
Finding dl.js in the page source proves only that the tag published. The install is complete when the event appears in Events.

When no event arrives

A wrong workspace ID returns a 4xx response, and the SDK drops the batch without retrying. Nothing appears in either workspace. Next, run the full verification checklist.