# Events, tags and search

> For the complete documentation index, see [llms.txt](https://analytics.writechoice.io/docs/llms.txt).

Record your own events with wca.track, mark versions and languages with tags, record any search box, identify signed-in readers, and leave your own visits out.

The script works with no code. These are the optional extras, all through the `wca` object the script adds to the page.

## Custom events

Besides pageviews, you can record events that matter to you, such as a download or a sign-up.

**With an HTML attribute.** Add `data-wca-event` to any clickable element. Extra `data-wca-event-*` attributes are stored as event data:

```html
<button data-wca-event="download" data-wca-event-file="guide.pdf">Download the guide</button>
```

**From JavaScript.** Call `wca.track` with the event name and, optionally, an object with data:

```js
wca.track('signup', { plan: 'pro' })
```

- Event names can have up to 50 characters and can't start with `=`, `+`, `-` or `@` (such an event is not sent, and the browser console says why).
- Events show up in the **Events** ranking of the [Overview](https://analytics.writechoice.io/docs/analytics/), and can be steps of [funnels and goals](https://analytics.writechoice.io/docs/analytics/behavior/).
- Don't put personal data (names, emails, account ids) in event names or event data.

## Tags

A tag marks every pageview and event of a page load. Use it to tell apart, inside one site, what your docs split by version, language or product, or two variants of a page, without creating a separate site for each. Add `data-tag` to the script tag:

```html
<script defer src="https://analytics.writechoice.io/s/YOUR_SITE_KEY.js" data-tag="v2"></script>
```

- In the portal, pick the tag in the **Filters** bar to see only its numbers, on every tab, or choose **Tag** as a dimension in **Breakdown** to compare tags side by side.
- A tag has up to 50 characters: lowercase letters, digits, `.`, `_` and `-`, and it can't start with `-`. Uppercase letters are lowercased (`pt-BR` becomes `pt-br`). A tag that breaks these rules is dropped, and the visit is still counted, without a tag.
- One tag per page load. For version and language together, combine them: `data-tag="v2.pt-br"`.
- On a single-page site where the reader switches version or language without a page reload, change the tag from your code:

  ```js
  wca.setTag('v3') // the following pageviews and events carry "v3"
  wca.setTag(null) // no tag from now on
  ```

  Call it before the navigation, or up to 300 ms after it, so the new page is already counted with the new tag.
- Never put personal data in a tag. It's the same for every reader of the page.

## Site search

The script records what readers type in your site search, so you can see the most frequent searches and, above all, the searches that found nothing.

**Recorded automatically**, with no code: the search box of WriteDocs sites, DocSearch (the Algolia search used by Docusaurus and many other docs sites) and Mintlify.

**Any other search box:** call `wca.search` from your search code. Call it as often as you like, for example on every keystroke: only the final search is recorded, after the reader stops typing for a second.

```js
// When the search runs, with the number of results shown:
wca.search(query, { results: resultCount })

// When the reader opens one of the results:
wca.search(query, { results: resultCount, clicked: true })
```

- Pass `results: 0` when nothing was found: that's what puts the search under **Searches with no results**.
- Emails, tokens and long numbers are replaced by `[email]`, `[token]` and `[number]` before a search leaves the browser, and again by the service. Texts are cut at 100 characters.
- `search` and `search_click` are reserved: `wca.track('search')` is ignored.

Searches show up in [Analytics → Search](https://analytics.writechoice.io/docs/analytics/search/), under **People**.

## Identify signed-in readers

If your readers sign in, you can tie their visits together across sessions and devices:

```js
wca.identify('8f3a2c91')
```

- Pass an **opaque id** from your own system (for example your internal user id, or a hash of it), up to 50 characters.
- **Never pass an email address or a name.** An id that looks like an email address is dropped by the service, and the visit is counted without it.
- `wca.identify` takes the id only. Any other argument is ignored.

## Leave your own visits out

Run this once in the browser console on your site. It applies to that browser only:

```js
wca.optOut()
```

To count your visits again: `wca.optIn()`. Both keep working the way they did before: `wca.optOut()` sets `wca.disabled` in the browser's storage (`localStorage.setItem('wca.disabled', '1')` does the same), and `wca.optIn()` removes it.

To offer the same to your readers, and to wait for a consent banner, see [Consent and opt-out](https://analytics.writechoice.io/docs/install/consent/).