|
| 1 | +# Google Tag Manager Setup Instructions |
| 2 | + |
| 3 | +## Overview |
| 4 | +This project has been migrated from direct Google Analytics 4 implementation to Google Tag Manager (GTM) for better tracking flexibility and easier management of marketing tools. |
| 5 | + |
| 6 | +## Setup Steps |
| 7 | + |
| 8 | +### 1. Create GTM Container |
| 9 | +1. Go to [Google Tag Manager](https://tagmanager.google.com/) |
| 10 | +2. Create a new account/container for your website |
| 11 | +3. Note your GTM Container ID (format: GTM-XXXXXXX) |
| 12 | + |
| 13 | +### 2. Configure Environment Variable |
| 14 | + |
| 15 | +#### **For GitHub Pages Deployment (Recommended):** |
| 16 | +1. Go to your GitHub repository |
| 17 | +2. Navigate to **Settings** → **Secrets and variables** → **Actions** |
| 18 | +3. Click **New repository secret** |
| 19 | +4. Name: `PUBLIC_GTM_ID` |
| 20 | +5. Value: `GTM-XXXXXXX` (your actual GTM container ID) |
| 21 | + |
| 22 | +The GitHub Actions workflow has been updated to use this secret during build. |
| 23 | + |
| 24 | +#### **For local development (.env.local):** |
| 25 | +``` |
| 26 | +PUBLIC_GTM_ID=GTM-XXXXXXX |
| 27 | +``` |
| 28 | + |
| 29 | +#### **Alternative: Hardcode GTM ID** |
| 30 | +If you prefer simplicity, replace `GTM-XXXXXXX` directly in the GTM components with your actual GTM ID. |
| 31 | + |
| 32 | +### 3. Configure GA4 in GTM |
| 33 | +1. In your GTM container, create a new **Google Analytics: GA4 Configuration** tag |
| 34 | +2. Use your existing Measurement ID: `G-Z2X2PB0P4E` |
| 35 | +3. Set the trigger to **All Pages** |
| 36 | +4. Publish the container |
| 37 | + |
| 38 | +### 4. Optional: Add Additional Tracking |
| 39 | +With GTM, you can now easily add: |
| 40 | +- Facebook Pixel |
| 41 | +- LinkedIn Insight Tag |
| 42 | +- Conversion tracking |
| 43 | +- Custom events |
| 44 | +- And more... |
| 45 | + |
| 46 | +## Files Modified |
| 47 | +- `src/components/analytics/GTM.astro` - GTM head script |
| 48 | +- `src/components/analytics/GTMBody.astro` - GTM body script (noscript fallback) |
| 49 | +- `src/layouts/BaseLayout.astro` - Updated to use GTM instead of direct GA4 |
| 50 | + |
| 51 | +## Files to Remove (Optional) |
| 52 | +After confirming GTM works correctly: |
| 53 | +- `src/components/analytics/Google.astro` |
| 54 | +- `src/components/analytics/google.js` |
| 55 | + |
| 56 | +## Testing |
| 57 | +1. Install GTM container ID |
| 58 | +2. Use [Google Tag Assistant](https://tagassistant.google.com/) to verify GTM is firing |
| 59 | +3. Check GA4 real-time reports to confirm data is flowing |
| 60 | + |
| 61 | +## Benefits of GTM |
| 62 | +- **Centralized Management**: All tracking codes in one place |
| 63 | +- **No Code Deployments**: Add new tracking without code changes |
| 64 | +- **Advanced Tracking**: Easy setup of conversion tracking, custom events |
| 65 | +- **Team Collaboration**: Marketing team can manage tags independently |
| 66 | +- **Version Control**: GTM has built-in version control and rollback |
| 67 | +- **Testing**: Preview and debug mode before publishing changes |
0 commit comments