# Connecting analytics

> Google Analytics 4 and Yandex Metrika on a static site by ID, and Livops' built-in traffic analytics.

Source: https://livops.dev/en/docs/analytics-connect

You can connect Google Analytics 4 and Yandex Metrika to a static site without writing code: you enter only the ID, and we put the tag on your pages. Reports stay in Google and Yandex.

## Where to get the ID

- **Google Analytics 4** — at [analytics.google.com](https://analytics.google.com), create a property and a **Web** data stream. The **Measurement ID** on the stream's page starts with `G-`, for example `G-AB12CD34EF`.
- **Yandex Metrika** — at [metrika.yandex.ru](https://metrika.yandex.ru), create a counter. You need its **number**, digits only, for example `98765432`.

## Where to enter it in the cabinet

The project's **Settings** page has an **Analytics** card. Both fields are optional: fill in one or both and click **Save**. Clearing a field turns that counter off.

- The card is shown for **static sites only**.
- A GA4 ID must look like `G-XXXXXXXXXX` and a Metrika counter must be digits only; anything else is rejected.

## How it works

- Only the IDs are stored. We build the official tag ourselves and add it to every HTML page before `</head>` — none of your markup is inserted into the page.
- Changes take effect as soon as you save; no redeploy is needed.
- A page with no `</head>` in its first 256 KB is served unchanged.
- **Preview environments have no counters**, so previews don't skew your stats.

## If your site sets its own CSP

If the site sets its own `Content-Security-Policy` header in `_headers`, allow the counters' addresses, or the browser will block them:

- Google Analytics: `https://www.googletagmanager.com` (`script-src`) and `https://*.google-analytics.com` (`connect-src`, `img-src`);
- Yandex Metrika: `https://mc.yandex.ru` (`script-src`, `connect-src`, `img-src`).

The tag also adds an inline `<script>`, so `script-src` needs `'unsafe-inline'`.

## Livops' built-in traffic analytics

Even without a counter, the project's **Traffic** tab has [traffic analytics](https://livops.dev/en/docs/analytics) — no script and no cookies. **A free team sees only the number of unique visitors over the last 7 days** and its daily chart. The full view — pages, referrers, countries, devices, filters and more — is **on a paid plan**.
