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
- Before consent. The tracker sets no cookies and never reads or probes them. Its ids live in memory for this page only. AnalyticFast derives a visitor id from a hash of the visitor's address and browser with a salt that changes every UTC day. The address is not stored, and yesterday's salt is deleted. Visitors are counted, a returning visitor on the same day is the same visitor, and pages less than 30 minutes apart join one session. A purchase on the same day is still credited to its source, because
attribution()returns the recorded ids for checkout metadata. - When the visitor accepts. The tracker keeps the visitor AnalyticFast already recorded and stores those ids in the
ml_vidandml_sidcookies. Nothing is lost, and from then on the visitor is recognised across days, so purchases days later are credited to the visit that brought them. - When the visitor declines or withdraws.
consent(false)deletes the cookies and goes back to the in-memory mode.
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.