Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 9 additions & 45 deletions GTM_SETUP.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,12 @@
# Google Tag Manager Setup
# Google Tag Manager

This project uses environment variables to inject the Google Tag Manager ID at build time, so your GTM ID is never committed to the repository.
getchunks uses the **shared Search Influence GTM container `GTM-4G43`** — the same
container as AI Website Grader and Ontologizer.

## How It Works

1. The HTML file contains placeholder `GTM-XXXXXXX` values
2. A build script (`scripts/build.js`) replaces these placeholders with the actual GTM ID from the `GTM_ID` environment variable
3. The build script runs automatically on Vercel deployments via the `buildCommand` in `vercel.json`

## Setting Up Your GTM ID

**Important**: This project uses `GTM_ID` (NOT `NEXT_PUBLIC_GTM_ID`). The build script runs server-side, so it doesn't need the Next.js `NEXT_PUBLIC_` prefix.

### For Vercel Deployments

1. Go to your Vercel project settings
2. Navigate to **Settings** → **Environment Variables**
3. Add a new environment variable:
- **Name**: `GTM_ID` (no prefix needed - this is NOT a Next.js project)
- **Value**: Your actual GTM ID (e.g., `GTM-4G43`)
- **Environment**: Production, Preview, and Development (as needed)
4. Redeploy your project

The build script will automatically inject your GTM ID during the build process.

### For Local Development

Set the environment variable before running the build:

```bash
export GTM_ID=GTM-4G43
npm run build
```

Or run it inline:

```bash
GTM_ID=GTM-4G43 npm run build
```

## Important Notes

- **Never commit your real GTM ID** to the repository
- The placeholder `GTM-XXXXXXX` is safe to commit
- The build script will use `GTM-XXXXXXX` as a fallback if `GTM_ID` is not set
- Make sure to set the `GTM_ID` environment variable in your Vercel project settings
The ID is hardcoded in [public/index.html](public/index.html) (script tag in `<head>`
plus the `<noscript>` iframe). There is no build-time injection; the old
`scripts/build.js` + `GTM_ID` env var mechanism was removed in v3.1 because it
mutated the source file in place, and GTM container IDs are public in page
source anyway.

To change the container, edit both occurrences of the ID in `public/index.html`.
Loading
Loading