Skip to content

Some Python libraries I've made in cursor to help debug Google Analytics/Tag Manager

License

Notifications You must be signed in to change notification settings

jackgolding/GTM-GA-Checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google Tag Manager & Google Analytics Checker

A Python tool to check multiple websites for the presence of Google Tag Manager (GTM) and Google Analytics (GA) tracking codes.

Features

  • 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

Installation

  1. Clone the repository:
git clone <repository-url>
cd gtm-ga-checker
  1. Install dependencies:
pip install requests beautifulsoup4
  1. For Brotli compression support (optional but recommended):
pip install brotli

Usage

1. Setup Configuration

Copy the example configuration file:

cp config.example.json config.json

Edit config.json with your target URLs:

{
  "urls": [
    "https://example.com/",
    "https://example.org/",
    "https://your-site.com/"
  ]
}

2. Run the Checker

python gtm_ga_checker.py

3. View Results

The 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
--------------------------------------------------------------------------------

What It Detects

Google Tag Manager (GTM)

  • GTM script tags (googletagmanager.com/gtm.js)
  • GTM container IDs (GTM-XXXXXXX format)
  • Inline GTM initialization code
  • Noscript fallback tags

Google Analytics (GA)

  • 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)

Technical Details

Compression Handling

The tool properly handles various compression methods:

  • Brotli (br) - Modern compression used by many CDNs
  • Gzip (gzip) - Standard compression
  • Deflate (deflate) - Legacy compression

Bot Protection Bypass

  • Realistic browser headers
  • Retry mechanism with exponential backoff
  • Session management
  • User-Agent rotation

Error Handling

  • Network timeout handling
  • HTTP error status codes
  • Compression decompression failures
  • Malformed HTML content

Output Format

Console Output

Formatted table showing:

  • URL being checked
  • GTM detection status and details
  • GA detection status and details
  • Any errors encountered

JSON Export (results.json)

[
  {
    "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
  }
]

Use Cases

  • 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

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Support

For issues and questions, please open an issue on GitHub.

About

Some Python libraries I've made in cursor to help debug Google Analytics/Tag Manager

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages