Skip to content

Delaying Yandex Metrika until consent

Key idea:

The standard Metrika snippet runs on page load and immediately writes the _ym_uid identifier — before any consent. The fix: move the ym(…, "init", …) call out of global code and into the consent banner's accept callback. For visitors who reject the banner the counter never initialises. No data is lost for the "before consent" period — Metrika simply starts the session at initialisation time.

Check your site →

Why the standard snippet is a problem

The snippet from the Metrika dashboard sits in <head> and executes before the page renders: the _ym_uid and _ym_d cookies are written and the first request to mc.yandex.ru leaves before the visitor has seen the banner. That is precisely what any privacy audit records: an identifier shared before consent.

Initialising from the banner callback

The universal pattern — wrap initialisation in a function and call it from your CMP's consent handler (Cookiebot, CookieYes, a home-grown banner — makes no difference):

function initMetrika() {\n  if (window._metrikaInited) return;\n  window._metrikaInited = true;\n  (function(m,e,t,r,i,k,a){ /* standard tag.js loader */ })\n    (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");\n  ym(XXXXXX, "init", { clickmap:true, trackLinks:true, accurateTrackBounce:true });\n}\n\n// call from your banner:\nconsentBanner.on("accept", initMetrika);\n\n// returning visitor who already consented:\nif (getCookie("analytics_consent") === "1") initMetrika();

The key details: a double-init guard; a repeat call on every page for visitors with stored consent; and no call at all when the visitor pressed Reject.

GTM Consent Mode

If tags are managed through Google Tag Manager, Consent Mode achieves the same: the Metrika tag fires on a consent event (a trigger on the custom consent_analytics_granted event your banner pushes to the dataLayer). Same logic — the tag does not fire until consent exists.

Verifying it worked

Open the site in incognito: before pressing Accept there must be no _ym_uid in Application → Cookies and no requests to mc.yandex.ru in Network. After Accept, both appear. The compliance scanner checks exactly this automatically across several pages and shows the before/after consent contrast in its report.

Related

Cookies Before ConsentWhat is written without permission
Consent BannerIs there an equal Reject option
PII FormsConsent and policy at the form
Projections152-FZ and GDPR grades

Why teams trust us

A–F
grade + 152-FZ/GDPR
3
browser sessions per page
PDF
integrity-signed report
Free
scan without signup

How it works

1

Enter your site URL

2

The scanner opens pages in a browser

3

Get a grade and a fix list

Why check your site for privacy compliance?

Regulators fine sites for processing personal data without consent — and a site starts processing earlier than it seems: analytics, pixels and widgets write cookies the moment the page loads. The scanner shows the auditor's view: what leaves for third parties before consent, whether the banner works, and whether forms collect data correctly.

Real Browser

Three sessions per page: no action, banner accepted, banner rejected.

Trackers and Jurisdiction

Service catalogue: who receives visitor data and in which country.

Policy at Collection Point

The policy link and consent element are checked next to the form, not in the footer.

Signed PDF

Report with an HMAC integrity stamp — hand it to your lawyer or contractor.

Who uses this

Business

preparing for an audit

Lawyers

technical facts for an opinion

Web Studios

client site handover

DevOps

consent regression monitoring

Common Mistakes

Loading analytics before consentA counter in writes cookies before any banner. This is exactly what an audit records.
Banner without a Reject buttonConsent is voluntary only when refusing is as easy as agreeing.
Policy only in the footerThe visitor must see who receives their data at the moment of submission — next to the form itself.
Checking once and forgettingA new widget or tag manager quietly adds trackers. Only a re-check catches the regression.

Best Practices

Delay trackers until consentInitialise analytics from the CMP accept callback, not on page load.
Offer an equal RejectAccept and Reject buttons — same size, same level.
Consent checkbox at every formUnchecked by default, with the processing policy linked right there.
Turn on monitoringA standing watch alerts you when the grade drops — before an auditor notices.

Monitor compliance automatically

Scheduled re-checks with an alert when pre-consent trackers appear on your site.

Sign up free

Learn more

Frequently Asked Questions

Will I lose statistics?

Partially: visits from people who reject the banner will not reach Metrika. That is what consent means. Rejection rates are usually 5–15% — the rest of your statistics remain intact.

What about goals and e-commerce events?

Every ym(…, "reachGoal", …) call must check whether the counter is initialised. A simple queue works well: buffer events in an array before init and replay them after.

Do I need the same for other counters and pixels?

Yes. One rule for every counter and pixel: initialise only from the accept callback. Each of them writes its own visitor identifier.

Try the live tool that powered this guide

Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.