> ## Documentation Index
> Fetch the complete documentation index at: https://docs.datalyr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Install web tracking

> Add Datalyr to every page and send your first page view.

The web snippet is the fastest way to track a website. It records page views and campaign context without requiring custom event code.

## Before you start

You need permission to publish the site and your Datalyr workspace ID. In Datalyr, open **Settings → Install**. New workspaces also show the same snippet on the dashboard until the first event arrives.

## Install the snippet

<Steps>
  <Step title="Copy your snippet">
    Open **Settings → Install** and copy the snippet shown for your workspace. The workspace ID is already filled in.
  </Step>

  <Step title="Paste it in the head">
    Add it inside the `<head>` of every page, before the closing `</head>` tag. Put it in the shared site template when possible.
  </Step>

  <Step title="Publish the site">
    A local or draft change cannot send production visits. Deploy or publish it before testing.
  </Step>

  <Step title="Visit the published page">
    Use a private window so the test starts with a clean visitor and session.
  </Step>
</Steps>

```html theme={null}
<!-- DATALYR — paste in <head> -->
<script defer src="https://track.datalyr.com/dl.js" data-workspace-id="YOUR_WORKSPACE_ID"></script>
```

Use the exact workspace ID shown in Datalyr. Do not reuse an ID from another workspace.

## What starts automatically

The snippet records page views, sessions, anonymous visitors, URLs, referrers, UTM parameters, supported ad click IDs, and browser context. It also tracks route changes in single-page applications.

Automatic tracking does not know who a visitor is or which product action matters to you. Add [`identify`](/sdk-reference/web#identify-a-user) after sign-in and custom events for actions such as signup, lead submission, or checkout.

## Install with npm

Use the package when your application owns its JavaScript lifecycle.

```bash theme={null}
npm install @datalyr/web
```

```ts theme={null}
import datalyr from '@datalyr/web'

datalyr.init({ workspaceId: 'YOUR_WORKSPACE_ID' })
await datalyr.ready()
```

Choose the snippet or npm package. Never initialize both on the same page.

## Common framework placement

| Platform          | Where to install                                              |
| ----------------- | ------------------------------------------------------------- |
| Next.js           | Root layout or a client-side analytics component loaded once  |
| React or Vue SPA  | Application entry point, initialized once                     |
| WordPress         | Site-wide header through the theme or a header-injection tool |
| Webflow or Framer | Global custom code in the site head                           |
| Custom HTML       | Shared `<head>` template on every page                        |

Do not place the snippet only on the confirmation page. Datalyr needs the landing visit to connect campaign context to the later conversion.

## Verify the install

Open **Events** and look for a recent `pageview` with the URL you visited. If it is missing, confirm the published HTML contains `dl.js`, the workspace ID is correct, and an ad blocker or consent setting did not block analytics.

<Warning>
  Seeing `dl.js` in page source only proves the tag was published. The setup is complete only when the event appears in Datalyr.
</Warning>

Next, [run the full verification checklist](/getting-started/verify-your-setup).
