# Add ENUM One website tracking to this site

You are working in the codebase of the website "<your website>" (<your domain>). Install ENUM One tracking so visits, traffic sources, ad clicks, calls, WhatsApp clicks and form submissions reach the team's CRM. Make the smallest change that works, follow the project's conventions, and don't change how the site looks or behaves.

## The snippet
Replace ws_YOUR_SITE_KEY with the site key from ENUM One (Connectors → Website), or copy the tailored prompt from the website's page there.
```html
<script>window.enumOne=window.enumOne||function(){(enumOne.q=enumOne.q||[]).push(arguments)}</script>
<script defer src="https://enum-one.vercel.app/t.js" data-site="ws_YOUR_SITE_KEY"></script>
```

The first line queues calls made before the script loads. The second loads the script with `defer`. Both belong in the <head> of every page.

## Where the tag goes
Find how this site renders its HTML <head>, then add the snippet once so it loads on every page:
- **Next.js (App Router):** in the root `app/layout.tsx`, use `next/script`: an inline `<Script id="enum-one-queue" strategy="beforeInteractive">` for the first line and `<Script src="…/t.js" strategy="afterInteractive" data-site="…" />` for the second. Keep every data-* attribute.
- **Next.js (Pages Router):** `pages/_document.tsx` inside `<Head>`, or `next/script` in `pages/_app.tsx`.
- **React / Vite / Vue / Svelte / Astro (single page apps included):** `index.html` or the root layout's head. Page changes through the History API are tracked automatically; don't add manual pageview calls.
- **Plain HTML / PHP / server templates:** the shared header include, or every page's `<head>`.
- **WordPress:** a `wp_head` hook in the child theme's `functions.php`, or a header-scripts plugin. Don't edit the parent theme.
- **Webflow / Framer / Wix / Squarespace / Shopify:** the site-wide "custom code in head" setting (Shopify: `theme.liquid` head).
- **Google Tag Manager:** a Custom HTML tag on All Pages with both lines. Direct install is preferred when you control the code.

## Forms
- Forms are captured automatically on submit: email, phone and name fields create or update the contact in ENUM One. Nothing else is read; passwords, hidden and payment fields are always skipped.
- Use real input types so fields are recognised: `type="email"`, `type="tel"`, and `name`/`autocomplete` values such as `name`, `given-name`, `family-name`, `email`, `tel`.
- Keep the native `submit` event. If a form is sent with fetch/AJAX and `preventDefault()`, that is fine as long as the form element still dispatches `submit`. If a custom component never fires `submit` (e.g. a button with an onClick that posts JSON), call `enumOne('identify', { email, phone, name })` and `enumOne('track', 'form_submit', { form: '<form id>' })` right after a successful send.
- Add `data-enum-ignore` to any form (or field) that must never be read, such as login, checkout or anything sensitive.

## Name the important buttons and sections
Calls, WhatsApp and email links (`tel:`, `mailto:`, `wa.me`), links to other sites, file downloads and form starts are tracked with no extra code.
- Add `data-enum-cta="Short name"` to the main calls to action (e.g. `data-enum-cta="Book a demo (hero)"`). Use stable, human names; they appear in reports.
- Add `data-enum-section="Pricing"` to major page sections if their headings change often. Otherwise the nearest section's aria-label or heading is used.
- Don't add click handlers or extra events for things that are tracked already.

## Identify signed-in visitors
After sign-up or log-in, and when a logged-in session starts, call:
```js
enumOne('identify', { email: user.email, phone: user.phone, name: user.fullName });
```
Send only these fields (plus small, non-sensitive traits such as `{ plan: 'team' }` as extra keys). Never send passwords, tokens, payment or health data.

## Consent
This website doesn't wait for consent. If the site has a cookie banner that must gate analytics, ask the site owner to turn on "Wait for Consent" in ENUM One, copy the new snippet, and call `enumOne('consent', true)` from the banner.

## Custom events (only for real business moments)
```js
enumOne('track', 'demo_requested', { plan: 'team', seats: 12 });
```
- Names: lowercase `snake_case`, verb in the past tense, at most 64 characters (`quote_requested`, `trial_started`).
- Properties: flat JSON with stable types (a key that is a number stays a number). Under 4 KB per event.
- Don't send personal data in event properties; use identify for that.

## Don't
- Don't put ENUM One API keys (`ek_…`) in browser code. The site key in the snippet (`ws_…`) is public and is the only key the browser needs.
- Don't load the script twice, self-host a copy, or change its URL.
- Don't track on staging or localhost unless the domain is added to the website in ENUM One.

## Check that it works
1. Run the site and open it on a domain this website accepts (`<your domain>` or a subdomain).
2. In the browser's Network tab, look for a `POST` to `/api/track` answered with **204** on page load.
3. Click a phone or WhatsApp link and a `data-enum-cta` button, start and send a test form with a test email address: each sends a request.
4. In ENUM One, the website's page shows "Receiving events", and the test visitor appears under Visitors within a minute.
Report back which files you changed and the result of each check.

## Reference

### Browser API (after the snippet)
| Call | What it does |
|---|---|
| `enumOne('track', name, properties?)` | A custom event. Name: lowercase snake_case, up to 64 characters. Properties: flat JSON, under 4 KB. |
| `enumOne('identify', { email, phone, name, ...traits })` | Says who the visitor is. Links them to the contact with the same email or phone, or creates a lead. |
| `enumOne('consent', true \| false)` | Gives or withdraws consent when the website waits for it. |
| `enumOne('page')` | Records a pageview by hand. Rarely needed: History API navigation is tracked already. |

### Snippet attributes
| Attribute | Meaning |
|---|---|
| `data-site` | The website's public site key (`ws_…`). Required. |
| `data-consent="required"` | Store and send nothing until `enumOne('consent', true)`. |
| `data-forms="off"` | Don't read forms. |
| `data-datalayer="on"` | Also push events to Google Tag Manager's `dataLayer` as `enum_<event>`. |

### HTML attributes
| Attribute | Meaning |
|---|---|
| `data-enum-cta="Name"` | Clicks on this element are recorded as `cta_click` with this label. |
| `data-enum-section="Name"` | Names the page section for clicks and form starts inside it. |
| `data-enum-ignore` | Never read this form or field, and don't track clicks inside it. |

### Events sent without code
| Event | When |
|---|---|
| `pageview` | Page load and every History API navigation. |
| `page_leave` | Leaving a page: engaged seconds, total seconds, scroll depth. |
| `contact_click` | Click on a `tel:`, `mailto:`, `sms:` or WhatsApp link (`type`: call, email, sms, whatsapp). A conversion by default. |
| `cta_click` | Click on a `data-enum-cta` element. |
| `outbound_click` | Click on a link to another domain. |
| `file_download` | Click on a link to a file (PDF, documents, spreadsheets, archives, media). |
| `form_start` | First input in a form. |
| `form_submit` | A form is sent (plus `identify` when it has an email, phone or name). A conversion by default. |

URL parameters kept with the visit: `utm_source`, `utm_medium`, `utm_campaign`, `utm_term`, `utm_content`, `utm_id`; ad click ids (`gclid`, `gbraid`, `wbraid`, `fbclid`, `msclkid`, `ttclid`, `li_fat_id` and more); Google Ads parameters (`gad_source`, `gad_campaignid`, `campaignid`, `adgroupid`, `keyword`, `matchtype`, `network`, `placement`, `creative`, `device`).

Human guide: https://enum-one.vercel.app/docs/website-tracking · REST API: https://enum-one.vercel.app/docs/api
