How to Add PostHog to Your Website

PostHog installs with one JavaScript snippet in your page head. Copy it from your project, keep your project token in posthog.init, and set api_host to the US or EU cloud your project lives in. Autocapture then records pageviews and clicks; the first million events each month are free.

PostHog free monthly allowances, from its pricing page
ProductFree each month
Product analytics events1,000,000
Web session recordings5,000
Feature flag requests1,000,000
Survey responses1,500

Updated

PostHog bundles product analytics, session replay, feature flags, experiments and surveys in one tool. For a marketing site that is more than you need, but for a site that will grow into an app it saves adding three tools later.

Add PostHog on We.Inc, WordPress, Wix, Squarespace or plain HTML

We.Inc

  1. Open the builder menu ("...") and go to Add-ons.
  2. Pick PostHog and enter your project details.
  3. Turn it on and confirm the saved notice.
  4. Publish to start capturing on the live site.

WordPress

  1. Install a header code plugin from Plugins, Add Plugin.
  2. Paste the PostHog snippet into the site header area.
  3. Save, clear caches, and look for events in PostHog.

WordPress.com requires a paid plan before you can add plugins.

Wix

  1. Open Settings, then Custom Code.
  2. Click + Add Custom Code and paste the snippet.
  3. Apply it to All pages in the Head.

Only published Wix sites with a connected domain run custom code.

Squarespace

  1. Find Code Injection under Custom Code in the Pages panel.
  2. Paste the snippet into Header, then save.

Core, Plus and Advanced plans include Code Injection; lower plans do not.

Plain HTML

  1. Paste the snippet into <head>.
  2. Set api_host to your region's address.
  3. Deploy and check PostHog's activity feed.

Starting with capture off until consent

This is the init call inside the snippet with one option added. Call opt_in_capturing from your banner's accept button.

posthog.init('YOUR_PROJECT_TOKEN', {
  api_host: 'https://eu.i.posthog.com',
  opt_out_capturing_by_default: true,
});
// later, when the visitor accepts:
posthog.opt_in_capturing();

Sources

  • PostHog docs, JavaScript web library: https://posthog.com/docs/libraries/js (checked October 28, 2026, used for the PostHog steps)
  • PostHog pricing: https://posthog.com/pricing (checked October 28, 2026, used for the PostHog steps)
  • Wix Help Center, embedding custom code: https://support.wix.com/en/article/embedding-custom-code-on-your-site (checked October 28, 2026, used for the PostHog steps)
  • Squarespace Help Center, using code injection: https://support.squarespace.com/hc/en-us/articles/205815908-Using-code-injection (checked October 28, 2026, used for the PostHog steps)

US or EU cloud

Each PostHog project lives in one region. The snippet must point at it: https://us.i.posthog.com for US Cloud or https://eu.i.posthog.com for EU Cloud. Data for European customers is often kept in the EU project for simpler privacy paperwork.

A Content-Security-Policy that does not list PostHog's domains makes capture fail silently, so add them if your site sets one.

Consent

PostHog sets a cookie by default so it can follow a visitor across pages and subdomains. For visitors in the EU and UK, start with capture off and turn it on after consent; see /guides/how-to-add-cookie-banner-to-website.

How it works

  1. Create a PostHog project and note its region.
  2. Copy the web snippet with your project token.
  3. Paste it into the <head> of every page.
  4. Open the site and watch the Activity view for your own pageview.
  5. Call posthog.identify after login if your site has accounts.

Tips

  • Set opt_out_capturing_by_default to true, then call posthog.opt_in_capturing() when a visitor accepts cookies.
  • Session replay counts against a separate allowance from events, so filter recordings to key URLs if you are near the limit.
  • Running two PostHog instances on one page? Turn autocapture off on the second one.

Frequently asked questions

Is PostHog free for a small website?

Usually. The first 1 million analytics events and 5,000 web recordings a month are free; you pay only above those amounts.

Can PostHog run without cookies?

You can start every visitor opted out and only capture after consent. Check PostHog's persistence settings for cookieless options before relying on them.

Does PostHog replace Google Analytics?

For many sites, yes: it tracks pageviews, sources and conversions. It is built around individual user journeys rather than ad reporting, so Google Ads users often keep GA4 alongside.

Related: How to set up Google Analytics, How to add a cookie banner, Website heatmaps, How to add Plausible Analytics.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

Product

Who It's For

Features

Resources

Company

View Sitemap