# How tracking works

Tracking answers one question: which post, ad or link did this lead come from, and did it become a sale. You choose between a few first-party pieces, and all of them feed the same event log.

A lead is tied to a visit only through something that can be shown: its own session, a signed click reference, a tracked link the sender named, or a campaign reference the sender stated. Nothing is guessed, and no device is recognized by its traits.

## The pieces

| Piece | What it does | Address |
|---|---|---|
| [Site script](https://heymysocial.com/docs/tracking/script) | Sends page views, the first touch of a form, and leads from the browser | `https://heymysocial.com/sdk/v1.js?k=hms_pk_…` |
| [Tracked links](https://heymysocial.com/docs/tracking/links) | Count a click and forward the visitor with campaign parameters and a signed reference | `https://heymysocial.com/t/{code}` |
| [Events API](https://heymysocial.com/docs/tracking/server-events) | Your server reports leads, status changes, sales and refunds with an API key | `https://heymysocial.com/api/v1/events` |
| [Signed webhook](https://heymysocial.com/docs/webhooks/tracking) | The same events, signed with one site's signing secret instead of a key | `https://heymysocial.com/hooks/hms_pk_…` |
| [Hosted landing pages](https://heymysocial.com/docs/tracking/landing-page-forms) | A simple page with a form, for an offer your own website has no page for | `https://heymysocial.com/p/{workspace}/{page}` |

Leads and sales can also arrive [as files](https://heymysocial.com/docs/files). Rows from a file go through the same door as every other event.

## Tracking sites

A tracking site is a website, or a form backend, that sends events. In the app it lives under **Funnels**, on the tab **Websites and forms**. **Add a website** asks for a name, a domain and a consent mode, and needs the right to manage integrations. An assistant can do the same with [manage_tracking_sites](https://heymysocial.com/docs/assistant/tools/manage-tracking-sites).

Each site has:

- **A public key.** It starts with `hms_pk_`, identifies the site in the script address and the webhook address, and is not a secret.
- **A signing secret.** It starts with `hms_whsec_`, signs server-to-server requests, is shown once when the site is created or the secret is rotated, and is stored encrypted. Rotating it makes the old one stop working at once.
- **Allowed origins.** Only pages on these origins may send from the browser. A new site allows `https://` plus its domain, with and without `www.`. An origin is a scheme and a host, optionally a port, without a path or a wildcard; `http://` is accepted only for `localhost` and `127.0.0.1`.
- **A consent mode.** `required` (the default) or `optional`. See [consent modes](https://heymysocial.com/docs/tracking/consent).
- **A status.** A paused site receives nothing: the script goes quiet, and the collection and webhook addresses answer not found.

## What becomes of an event

Every piece hands its events to the same ingestor, which does four things in order:

1. **Validates** the event. One that cannot be read is listed under **Items to review** and is not stored as an event.
2. **Recognizes a repeat.** The same source and `event_id`, or the same source, type and `external_id`, is the same event. It is answered as a duplicate with the first result and changes nothing.
3. **Stores** it in an append-only log with the time you gave it. A correction is a new event that names the one it corrects.
4. **Applies** it to the records people work with: sessions and touchpoints, leads, opportunities and sales.

Contact details and form answers go to the contact and the lead. They never enter the event log.

An event that names a lead nobody has sent yet is kept, listed under **Items to review** as an unknown lead, and applied when that lead arrives.

The [event types](https://heymysocial.com/docs/reference/event-types) are fixed, and [attribution](https://heymysocial.com/docs/reference/attribution) is worked out from the touchpoints these events leave behind.

## What is kept about a visitor

- **A session**, only where consent allows it: a random key the script made, the consent state, the first path visited (without its query string), the referring host, and first and last seen.
- **Touchpoints**: channel, source, medium and the campaign parameters of a visit or a click. A provider click id (`fbclid`, `gclid`) is kept only with granted consent, and only as a SHA-256 hash.
- **Nothing about the device.** The script reads no user agent, screen, font or canvas. No cookie is set by the script, the redirect or a hosted landing page. The redirect stores no address and no browser details.

The sender's address is used to count requests against the rate limit. It is not saved with a session, a touchpoint or an event.

## Testing without creating anything

- Open any page of your site with `?hms_test=1`. The script sends a test event that shows up in the site's diagnostics and creates no lead.
- Press **Send a test event** on the site's page. It proves the pipeline, not the installation.
- Add `"test": true` to an event sent by API or webhook. It is stored and creates nothing. One sent through the webhook also appears in the list on the site's page.

Only a test that came from outside, through the site's script or its webhook, marks the site as **Installation tested**. Test events do not count toward the plan's tracked events.

## Limits

Event collection, tracked links, the webhook and the events API share one limit of 600 requests a minute, counted per sender address, and separately for each site key or link code. The API has its own limit per key as well.

<div class="table-scroll"><table><thead><tr><th>What</th><th>Limit</th><th>Counted per</th></tr></thead><tbody><tr><th scope="row">REST API</th><td>120 requests a minute</td><td>API key</td></tr><tr><th scope="row">Event ingestion and webhooks</th><td>600 requests a minute</td><td>Tracking site and sender address</td></tr><tr><th scope="row">Assistant connector</th><td>90 requests a minute</td><td>Signed-in person</td></tr><tr><th scope="row">Public forms</th><td>10 requests a minute</td><td>Visitor address</td></tr></tbody></table></div>

Accepted events count toward the plan's tracked events for the month. Going over the allowance never blocks an event: the app shows a notice and the events keep arriving.

## Where to go next

- [The site script](https://heymysocial.com/docs/tracking/script): the snippet, the three functions and what is sent.
- [Consent modes](https://heymysocial.com/docs/tracking/consent): what happens before, with and without consent.
- [Tracked links](https://heymysocial.com/docs/tracking/links): parameters, the click reference and what is not counted.
- [Events from your server](https://heymysocial.com/docs/tracking/server-events): the event body, the API and the signed webhook.
- [Landing page forms](https://heymysocial.com/docs/tracking/landing-page-forms): the hosted form and how it protects itself.
- [Install and test tracking](https://heymysocial.com/guides/install-and-test-tracking): the same thing as a task, step by step.
