Migrate to Netlify Today

Netlify announces the next evolution of Gatsby Cloud. Learn more

ContactSign Up
Community Plugin
View plugin on GitHub



A simple gatsby plugin to add posthog analytics to your site. Automatically tracks all the pageviews and clicks.


yarn add gatsby-plugin-posthog


npm install --save gatsby-plugin-posthog

How to use

// In your gatsby-config.js
module.exports = {
  plugins: [
      resolve: `gatsby-plugin-posthog`,
      options: {
        // Specify the API key for your Posthog Project (required)
        // Specify the app host if self-hosting (optional, default: https://app.posthog.com)
        apiHost: "YOUR_POSTHOG_APP_HOST_URL",
        // Puts tracking script in the head instead of the body (optional, default: true)
        head: true,
        // Enable posthog analytics tracking during development (optional, default: false)
        isEnabledDevMode: true
        // Pass custom variables to posthog.init() (optional)
        initOptions: {
          // ...
© 2023 Gatsby, Inc.