Manage and inject tracking scripts (Google Analytics, Google Ads, Facebook Pixel, custom code) into site pages, with optional PrivacyWire consent integration and robots.txt/llms.txt file management.
- Google Analytics (GA4) — inject gtag.js with Measurement ID
- Google Ads — inject gtag.js with Ads conversion ID
- Facebook Pixel — inject Pixel tracking code with noscript fallback
- Custom code — free-form textareas for any third-party scripts (head and/or body)
- PrivacyWire integration — when enabled, scripts are injected with
data-categoryattributes andtype="text/plain"so they only load after user consent - robots.txt & llms.txt — edit and auto-generate both files from the admin; content is written to the site root on save
- Per-service controls — enable/disable, position (head or body), and consent category for each service independently
- ID validation — regex validation for GA (
G-), Ads (AW-), and Pixel (numeric) IDs before injection - Admin-only exclusion — scripts are never injected on admin or form-builder templates
site/modules/TrackingScripts/
├── TrackingScripts.info.php ← module metadata
├── TrackingScripts.module.php ← main module (hooks, script injection)
├── TrackingScriptsConfig.php ← module configuration (ModuleConfig)
├── ProcessTrackingScriptsConfig.info.php ← Process module metadata
└── ProcessTrackingScriptsConfig.module ← admin UI for non-superusers
-
Copy the
TrackingScriptsfolder into/site/modules/ -
In the admin go to Modules → Refresh, then install TrackingScripts
-
Optionally install ProcessTrackingScriptsConfig — this adds a Setup → Tracking Scripts page that allows non-superuser roles to edit the configuration. Assign the
tracking-scripts-configpermission to any role that needs access.
Go to Modules → Configure → TrackingScripts (superuser) or Setup → Tracking Scripts (any user with permission).
| Field | Description |
|---|---|
| Enable | Activate/deactivate injection |
| Measurement ID | GA4 ID, e.g. G-XXXXXXXXXX |
| Position | Inject in <head> or before </body> |
| PrivacyWire Category | Consent category (default: Statistics) |
| Field | Description |
|---|---|
| Enable | Activate/deactivate injection |
| Ads ID | e.g. AW-XXXXXXXXX |
| Position | Inject in <head> or before </body> |
| PrivacyWire Category | Consent category (default: Marketing) |
| Field | Description |
|---|---|
| Enable | Activate/deactivate injection |
| Pixel ID | Numeric ID, e.g. 123456789012345 |
| Position | Inject in <head> or before </body> |
| PrivacyWire Category | Consent category (default: Marketing) |
Two free-form textareas for any additional third-party code:
- Custom Code — Head: injected before
</head> - Custom Code — Body: injected before
</body>
When enabled, all tracking scripts are rendered with PrivacyWire-compatible attributes:
<script type="text/plain" data-type="text/javascript" data-category="statistics" class="require-consent" src="..."></script>This ensures scripts only execute after the user gives consent for the corresponding cookie category. Requires the PrivacyWire module to be installed and active.
Edit the content of both files directly from the admin. On save, the files are written to (or removed from) the site root:
/robots.txt— search engine crawler directives/llms.txt— LLM/AI bot directives
If a textarea is left empty, the corresponding file is deleted from the site root.
The module hooks into Page::render (priority 100) to inject scripts via str_replace on </head> and </body>. This means:
- No template modifications required
- Works on all front-end pages automatically
- Runs before PrivacyWire (priority 101), so consent attributes are in place when PrivacyWire processes the page
The robots.txt and llms.txt files are written via a hook on Modules::saveConfig, triggered whenever the module configuration is saved from either the module config screen or the Process admin page.
A Process module that mirrors the full TrackingScripts configuration under Setup → Tracking Scripts.
Allows non-superuser roles to manage tracking scripts without access to the Modules admin.
The module registers the permission tracking-scripts-config. To grant access:
- Go to Access → Roles
- Edit the desired role
- Check tracking-scripts-config
- Save
- Reads and writes the same configuration data as TrackingScripts via
$modules->getConfig()/$modules->saveConfig() - Changes from either location (Modules → Configure or Setup → Tracking Scripts) are reflected in both
- Saving triggers the same
Modules::saveConfighook, so robots.txt/llms.txt files are written automatically
- ProcessWire 3.0.110+
- PHP 7.2+
- PrivacyWire (optional, for consent integration)
Licensed under the MIT License.