Hiveku already includes privacy-friendly visitor analytics — see Track Site Analytics. Use Google Analytics when you need GA-specific integrations (Google Ads conversions, advanced audiences, BigQuery export) or when your team is already on GA.
Get Your Measurement ID
Before installing, grab your GA4 Measurement ID from analytics.google.com:- Admin > Property > Data streams
- Click your web stream
- Copy the Measurement ID — it looks like
G-XXXXXXXXXX
Three Ways to Install
- AI Chat (Easiest)
- Manual Snippet
- Next.js (@next/third-parties)
Ask the AI in your project:The AI picks the right file for your stack (Next.js root layout, static site
<head>, etc.), adds the snippet, and deploys when you confirm.Using an Env Var
Whichever path you choose, it’s a good idea to read the Measurement ID from an environment variable rather than hardcoding it. This way, production uses one GA property and staging uses another (or none):Cookie Consent & Privacy
GA4 uses cookies to track users across sessions. Depending on your visitors’ location, you may need a consent banner before loading GA:- EU (GDPR) — explicit opt-in required
- California (CCPA) — opt-out required, at minimum
- Other regions — varies, check local law
The consent API
Hiveku’s consent banner exposes exactly these globals on your site:Gating the GA snippet
The consent runtime is loaded asynchronously, so reading the global once at page load usually runs before consent resolves and you get a false negative. Check the global once — the inline bootstrap sets it synchronously for visitors who already have a stored decision — then listen for the event to cover everyone else:You only need this hand-written gate when you paste the GA snippet into your own code. If you register GA4 as a tracker in Site Enhancements instead, the consent banner injects the tag for you once the Analytics category is granted, and sets Google Consent Mode v2 defaults before any Google tag can run.
Google Tag Manager
If you prefer Tag Manager, the install flow is identical — swap thegtag.js snippet for your GTM container snippet:
Verify It’s Working
1
Deploy your changes
Any of the three install paths above requires a deploy.
2
Open the Realtime report in GA4
analytics.google.com > your property > Reports > Realtime.
3
Visit your site in a new tab
Load any page. Within ~30 seconds, you should see your session appear in the Realtime report.
4
Check the script loaded
Open DevTools > Network > filter for
gtag — you should see gtag/js?id=G-XXXXXXXXXX returning 200.Troubleshooting
No data showing after 24 hours
No data showing after 24 hours
Check three things: (1) Measurement ID format is
G- followed by 10 characters — older UA-prefixed IDs are discontinued; (2) the gtag/js script loads successfully in DevTools Network — if it 404s, the ID is wrong; (3) the snippet is in the rendered HTML, not just the source — a client-rendered React app may need special placement.Works in dev but not production
Works in dev but not production
Check your env var —
NEXT_PUBLIC_GA_ID has to be set in the production environment, not just locally. Vars without the NEXT_PUBLIC_ prefix aren’t exposed to the browser.Ad blockers blocking tracking
Ad blockers blocking tracking
Expected for a non-trivial slice of users. Mitigations include server-side Measurement Protocol for important events (conversions) and using Google Tag Manager’s server-side container. Don’t try to defeat ad blockers for general pageviews — you’ll erode user trust.
Duplicate events in reports
Duplicate events in reports
The GA snippet was added twice — commonly in both the root layout and a page template. Search your codebase for
G- and remove duplicates.Realtime works but reports are empty after hours
Realtime works but reports are empty after hours
GA4 processes data in batches — full reports can lag 24–48 hours after first install. Realtime is the best quick-check for “is it working.”
What’s Next?
Track Site Analytics
Use Hiveku’s built-in privacy-friendly analytics
Environment Variables
Store your Measurement ID per environment