Documentation

Cookie banners and consent guide

Most visitors never answer a cookie banner. If the tracker waits for "Accept" before it loads, those visitors are never counted, and that is often most of your traffic. Instead, load the tracker on every page and tell it where consent stands. It counts everyone, and only visitors who accept get cookies.

Script tag

Add data-consent to the snippet. Use pending until the visitor accepts, and granted on page loads where you already know they accepted:

<script defer data-website-id="YOUR_SITE_ID" data-consent="pending" src="https://YOUR_ANALYTICS_HOST/js/script.js"></script>

Then call the tracker from your banner:

// Visitor accepts analytics cookies
window.analyticfast?.('consent', true);
// Visitor declines, or withdraws consent later
window.analyticfast?.('consent', false);

npm package

import { init, consent } from 'analyticfast';
init({ siteId: 'YOUR_SITE_ID', host: 'https://YOUR_ANALYTICS_HOST', consent: alreadyAccepted ? 'granted' : 'pending' });
// In the banner handlers:
consent(true);  // accepted
consent(false); // declined or withdrawn

Calls made before the script loads are queued and replayed in order.

What happens in each state

Without data-consent, the tracker uses cookies from the first pageview, as it always has. If the browser blocks cookies, it counts the visit the same way as before consent.

Your obligations

Before consent the tracker stores nothing on the visitor's device. The one exception is reading the ml_ignore key in localStorage, which only ever exists on browsers where you opted yourself out with ?ml_ignore=true. Whether you may count visitors this way without consent depends on the laws that apply to you and your visitors. Check with your own advisers. Keep afxEnabled or data-disabled (see Plain script) for pages you must not track at all.

Questions, answered.

How do I use cookie banners and consent with AnalyticFast?

Follow the Cookie banners and consent instructions on this page using your own website’s Site ID and configuration. Verify a real event before relying on the reports.

Where can I get setup help?

Contact support@analyticfast.com with the website domain and a redacted description. Do not send API tokens, signing secrets or personal customer data.