Add Google Analytics to a Next.js app

Google Analytics is one of the most popular analytics tools around.

This nstaller will guide you through the process of adding Google Analytics to your Next.js app.

Get your Google Analytics tracking code

Visit Google Analytics and get your tracking code.

=> {"do": "Form", "with": [
  {
    "name": "gaCode",
    "label": "Google Analytics Tracking Code",
    "placeholder": "G-JPZVFNGZQG",
    "required": true
  }
] }

Create an entry in your .env file

=> {"do": "AddToDotEnv", "with": ["NEXT_PUBLIC_GOOGLE_ANALYTICS", "gaCode"] }

Inject the tracking code

Add the Google Analytics code to a custom Document.

TODO: AddToDoc

Google Analytics helpers

Add Google Analytics helpers.

TODO: AddFile

Log pageviews

Plug into your app navigation to make sure page views are counted

TODO: Add code