How to replace Google Analytics 4, step by step
Four steps from GA4 to self-hosted Pug: stand up the server, run the Web SDK beside the Google tag, rebuild the reports you use, then identify users and remove the tag. After the steps, what GA4’s free tier costs you.
Four steps from GA4 to Pug
Nothing switches overnight: both tools run side by side until Pug covers what you rely on.
- 1
Stand up a self-hosted Pug server
Run Pug on your own infrastructure: the pug Go binary on PostgreSQL, ClickHouse, NATS and Dragonfly, which pug start runs as a single process on a small node. It is free under AGPL-3.0, with no plans or limits, and the setup guide below walks through it. Pug Cloud skips this step.
- 2
Add the Web SDK beside the Google tag
Install @pug-sh/browser, call init() with your project id and public key, and leave gtag.js in place. Autocapture starts at once (page_view, click, scroll, form_start, form_submit, rage_click and dead_click), so both tools count the same visits while you compare them.
- 3
Rebuild the reports you use
List the GA4 reports your team opens, then recreate each one as a Trends, Funnels or Retention insight over raw events. A GA4 key event becomes an ordinary event used as a funnel step, and a gtag event becomes a track() call with the same name and parameters.
- 4
Identify users, then remove the tag
Call identify(userId, traits) where you set user_id and user properties for GA4, and reset() where you clear user_id on sign-out. In the Web SDK’s default cookieless mode identify() does nothing until the visitor consents. Once your dashboards cover what you relied on, delete the Google tag.
What GA4’s “free” costs
You don’t own the data
GA4 processes your visitors’ events on Google’s infrastructure. The reports are yours; the raw data and the relationship with the user are not.
Sampling hides detail
GA4 explorations sample past 10M events a query. To get full events back you export to BigQuery, where a standard property exports 1M events a day, and exports past the BigQuery sandbox limits are billed.
Privacy & GDPR overhead
Sending EU visitor data to a US ad company brings consent-banner and data-transfer questions that self-hosting avoids.
Checked November 21, 2026 by Praveen Kumar, who builds Pug. Sources: GA4 limits, BigQuery export, user ID.
Free options worth knowing
There’s no single right tool. Pug is the product-analytics pick; for pure website traffic, lighter web-analytics tools may fit better. A shortlist of free, self-hostable options:
- Pug: open-source product analytics (funnels, retention, profiles), self-hosted with every feature
- Plausible CE or Umami: lightweight, privacy-first website traffic analytics
- Matomo: a full self-hosted web-analytics platform and GA replacement
How do I migrate from Google Analytics?
Run the new tool beside GA4, rebuild the handful of reports you use, identify your users to unify profiles, then remove the Google tag. The four steps above cover each one for Pug.
Is there a free Google Analytics replacement?
Yes. Several open-source tools self-host for free. Pug is a free, self-hostable product-analytics replacement; Plausible CE, Umami, and Matomo are strong web-analytics options. Free here means no licence fee: you provide the infrastructure.
Isn’t GA4 already free?
GA4 is free to use, but the cost shows up as lost data ownership, sampling on larger explorations, BigQuery bills for raw data past the sandbox limits, and GDPR overhead. A self-hosted replacement keeps the data and removes those trade-offs.
Will I lose my historical GA data?
Pug has no GA4 importer, so it counts from the day you install it. Keep GA running during the overlap so you keep a reference while your new dashboards fill in; to bring a BigQuery export across, the Node SDK’s track() takes a timestamp option.
Is Pug a full GA replacement?
For product analytics, yes, and your data stays yours. For Google Ads attribution and the wider Google ecosystem, GA4 still has the integration edge, so some teams keep GA for ads only.
Run Pug beside GA, then switch.
Add the SDK next to your GA tag, and cut over once the reports you rely on are rebuilt in Pug. Pug Cloud is free up to 100k events a month.
Questions? Email hello@pug.sh