# Install the Snippet

> Install the Edesy call tracking script - one async tag with your pool key, allowed domains, what it swaps (data-edesy-ct, tel links, text), consent mode, the EdesyCT JavaScript API and what it stores.

Source: https://edesy.in/docs/call-tracking/getting-started/install-the-snippet

The call tracking snippet is one script tag. It loads from Edesy, asks for a tracking number for the visitor, and swaps your website's number for it. It is about 3 KB gzipped and has no dependencies.

## The tag

Paste this into the `<head>` of every page. Copy the exact tag from your pool's **Install** tab; the `data-key` is your pool's public key.

```html
<script async src="https://voice-api.edesy.in/v1/public/ct/edesy-ct.js" data-key="ctk_XXXXXXXXXXXXXXXXXXXXXXXX"></script>
```

| Attribute | Meaning |
|---|---|
| `data-key` | Pool public key, starting `ctk_`. Required. It is not a secret |
| `data-consent="required"` | Do nothing until `window.EdesyCT.consent()` is called |

The script works with tag managers and single-page apps. Content added later (route changes, modals) is swapped too.

## Allowed domains

The pool only answers requests from the domains you listed, checked against the browser's `Origin` or `Referer`.

- `example.com` matches `example.com` and `www.example.com`.
- `*.example.com` matches `example.com` and every subdomain.
- Matching is on whole labels, so `example.com` never matches `evilexample.com`.
- A pool can list up to 50 domains.

If a page is on a domain that is not listed, the script leaves your normal number in place.

## What gets swapped

The script replaces each of the pool's website numbers (up to 10) with the visitor's tracking number:

1. **Elements marked `data-edesy-ct`**, the most reliable option. The text becomes the formatted number, and an `<a>` also gets `href="tel:+91..."`.
   ```html
   <a data-edesy-ct href="tel:+912240001234">+91 22 4000 1234</a>
   ```
2. **`tel:` links** whose number matches one of your website numbers, in any format.
3. **Text** containing one of your numbers, written as `+91 22 4000 1234`, `022-4000-1234`, `(022) 40001234`, `02240001234` and similar. Your site's separators are kept.

Scripts, styles, form fields and editable regions are never touched. If a number is split across elements or written in an unusual way, mark it with `data-edesy-ct`.

## When the page keeps its own number

The script never shows a broken or empty number. Your normal number stays when:

- the script cannot load, or storage is blocked
- the pool is paused, or the domain is not allowed
- every number is in use and the pool shows the normal number
- the pool is set to paid traffic only and the visit has no click ID or paid `utm_medium`
- the visitor looks like a bot (crawlers, ad reviewers, uptime monitors, scripts)

## Consent mode

If you need consent before setting storage, add `data-consent="required"` and call `window.EdesyCT.consent()` from your consent banner when the visitor agrees.

## JavaScript API

```js
window.EdesyCT.consent();          // start, when data-consent="required"
window.EdesyCT.getNumber();        // { number: "+912240009999", display: "+91 22 4000 9999" } or null
await window.EdesyCT.ready;        // resolves to the same, or null; never rejects
document.addEventListener('edesy-ct:ready', (e) => render(e.detail.display));
```

`edesy-ct:ready` fires after each successful swap, including when the number changes after a lost lease.

## What the script stores

| Key | Where | Content |
|---|---|---|
| `edesy_ct_vid` | localStorage | Visitor ID, 90 days rolling |
| `edesy_ct_ft` | localStorage | First touch: campaign parameters, landing URL, time, 90 days |
| `edesy_ct_lt` | localStorage | Last touch, reused for 30 minutes on pages without parameters |
| `edesy_ct_cfg` | sessionStorage | Pool configuration, 5 minutes |
| `edesy_ct_s` | sessionStorage | Current session and number, until the lease ends |

Landing pages and referrers are stored with only the attribution parameters (`utm_*`, `gclid`, `gbraid`, `wbraid`, `fbclid`, `msclkid`); other query parameters, such as form fields, are dropped. Visitor IP addresses are kept only as a network prefix.

## Keeping the number while the page is open

While the tab is visible the script renews the visitor's lease every 60 seconds, so a long visit keeps the same number. A returning visitor whose lease is still live gets the same number back. See [Number Pools](https://edesy.in/docs/call-tracking/pools/number-pools).

## FAQ

**Does the script slow my site down?**
It loads with `async`, is about 3 KB gzipped and runs after the page. If it fails, nothing on the page changes.

**Can I install it with Google Tag Manager?**
Yes, as a custom HTML tag on all pages. Make sure the page's domain is in the pool's allowed domains.

**Do I need to change my website's markup?**
Usually not: `tel:` links and written numbers are found automatically. Add `data-edesy-ct` only where a number is split or unusually formatted.
