Step 1: Create a Measurement Protocol API Secret
- Go to your Google Analytics 4 dashboard.
- Click Admin (the gear icon in the bottom left).
- Under Data collection and modification, click on Data Streams.
- Click on your website’s data stream.
- Scroll down to the Additional settings section and click on Measurement Protocol API secrets.
- Click Create and give it a nickname (like
GTM Secret). - GA4 will generate a long string of letters and numbers. Copy this Secret Value.
Step 2: Add the Secret Key to Google Tag Manager
Now you need to give GTM the “password” so GA4 accepts your real website traffic.
- Open Google Tag Manager.
- Go to your main GA4 Google Tag (the configuration tag that initializes GA4 on your site).
- Under Configuration Settings, you need to add a parameter:
- Configuration Parameter:
api_secret - Value: Paste the Secret Value you copied from GA4.
- Configuration Parameter:
- Publish your GTM container.
Once this is live, GA4 will check every incoming hit. If a spammer sends a hit directly to your GA4 measurement ID without that exact api_secret, GA4 will quietly drop it into the trash. Your real data stays clean, and the spammers are blocked.
