docs: Create google analytics doc
Motivation
This PR creates a Google Analytics doc showing how to add Google's Global Site Tag (gtag.js) to a Nextra website.
Issue
Closes #2128
⚠️ No Changeset found
Latest commit: 75532d998c8a7fead469c32631d41e6ba5e7dd34
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| nextra | ❌ Failed (Inspect) | Sep 25, 2023 10:18pm | ||
| nextra-v2 | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Sep 25, 2023 10:18pm |
@oluwatobiss is attempting to deploy a commit to the Vercel Team on Vercel.
A member of the Team first needs to authorize it.
All done.
Thank you for writing this. Works great.
Here's some unsolicited comments changing everything to typescript since the rest of the project is ts.
Thank you, @basedMcghee, for your helpful suggestions. Having TypeScript examples makes sense. However, we don't need to replace the JavaScript. Instead, we can document the two options so that users who do not wish to use TypeScript can still follow along with the JavaScript examples.
I've tried these changes and get a syntax error:
1 │ export const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GA_ID
2 │ export const pageview = (url: string) => {
· ─
3 │ window.gtag('config', GA_TRACKING_ID, {
4 │ page_path: url
5 │ })
╰────
Caused by:
Syntax Error
Import trace for requested module:
./lib/gtag.js
automatically enabled Fast Refresh for 3 custom loaders
⨯ ./lib/gtag.js
Error:
This guide is specifically designed to work with Vercel, but it doesn't work under different conditions.
lib/gtag.js is inlined during build-time, not at runtime, so this would only work if the image is build on the server. In many cases this is not true. Image is often build on CI (for multiple environments) where the env var is not available, which it won't be because you don't want to build different images for different environments.