A Python tool to check multiple websites for the presence of Google Tag Manager (GTM) and Google Analytics (GA) tracking codes.
- ✅ GTM Detection: Finds Google Tag Manager containers and their IDs
- ✅ GA Detection: Detects Google Analytics tracking codes (Universal Analytics and GA4)
- ✅ Bulk Processing: Check multiple websites from a configuration file
- ✅ Robust Error Handling: Handles network issues, compression, and bot protection
- ✅ Multiple Output Formats: Console table and JSON export
- ✅ Compression Support: Properly handles Brotli, Gzip, and other compression
- Clone the repository:
git clone <repository-url>
cd gtm-ga-checker- Install dependencies:
pip install requests beautifulsoup4- For Brotli compression support (optional but recommended):
pip install brotliCopy the example configuration file:
cp config.example.json config.jsonEdit config.json with your target URLs:
{
"urls": [
"https://example.com/",
"https://example.org/",
"https://your-site.com/"
]
}python gtm_ga_checker.pyThe script will display results in a formatted table and export to results.json:
====================================================================================================
GOOGLE TAG MANAGER & GOOGLE ANALYTICS CHECK RESULTS
====================================================================================================
URL: https://example.com/
✅ GTM Script: gtm.js
✅ GTM Measurement ID: ABC12345
✅ GTM Full URL: https://www.googletagmanager.com/gtm.js?id=ABC12345
✅ GA Script: gtag.js
✅ GA Measurement ID: G-XXXXXXXXXX
✅ GA Full URL: https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX
--------------------------------------------------------------------------------
- GTM script tags (
googletagmanager.com/gtm.js) - GTM container IDs (GTM-XXXXXXX format)
- Inline GTM initialization code
- Noscript fallback tags
- Universal Analytics (
google-analytics.com/analytics.js) - GA4 (
googletagmanager.com/gtag/js) - Inline gtag() and ga() function calls
- Measurement IDs (UA-XXXXXX-X and G-XXXXXXXXXX formats)
The tool properly handles various compression methods:
- Brotli (
br) - Modern compression used by many CDNs - Gzip (
gzip) - Standard compression - Deflate (
deflate) - Legacy compression
- Realistic browser headers
- Retry mechanism with exponential backoff
- Session management
- User-Agent rotation
- Network timeout handling
- HTTP error status codes
- Compression decompression failures
- Malformed HTML content
Formatted table showing:
- URL being checked
- GTM detection status and details
- GA detection status and details
- Any errors encountered
[
{
"url": "https://example.com/",
"gtm": {
"script": "gtm.js",
"measurement_id": "ABC12345",
"full_url": "https://www.googletagmanager.com/gtm.js?id=ABC12345"
},
"ga": {
"script": "gtag.js",
"measurement_id": "G-XXXXXXXXXX",
"full_url": "https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"
},
"error": null
}
]- SEO Audits: Verify tracking code implementation
- Marketing Analytics: Ensure proper GTM/GA setup
- Compliance Checks: Validate privacy and analytics compliance
- Migration Validation: Confirm tracking code migrations
- Competitive Analysis: Analyze competitor tracking setups
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
For issues and questions, please open an issue on GitHub.