ProcessWire is a PHP-based CMS and CMF (Content Management Framework) that uses a powerful API-driven architecture with selector-based content queries. Templates in ProcessWire are plain PHP files, giving developers full control over tracking script integration. ProcessWire's page-tree content model and field system provide rich data for analytics data layers.
Integration Architecture
ProcessWire provides three integration paths:
- PHP Templates -- Template files in
/site/templates/. ProcessWire uses plain PHP (no template engine), so you write standard PHP/HTML with ProcessWire API calls. The main layout file is typically_main.phpor_layout.phpusing ProcessWire's delayed output or markup regions. - Modules -- ProcessWire modules installed in
/site/modules/. The module directory at modules.processwire.com has some analytics modules, though manual template integration is more common. - ProcessWire API -- The
$page,$pages, and$configAPI objects are available in all templates, providing structured content data for the data layer.
Available Integrations
Analytics Platforms
Tag Management
- Main layout template head/body injection
- Module-based GTM for admin configuration
Marketing Pixels
- Via GTM container (recommended)
- PHP template head injection
Template Integration with Data Layer
ProcessWire's delayed output pattern uses _main.php as the wrapper template. Add GTM and a data layer using ProcessWire's API:
<?php // site/templates/_main.php ?>
<!DOCTYPE html>
<html lang="<?= $user->language ? $user->language->name : 'en' ?>">
<head>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;
j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;
f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-XXXX');</script>
<?php
$dataLayer = [
'pageTitle' => $page->title,
'pageTemplate' => $page->template->name,
'pageId' => $page->id,
'parentTitle' => $page->parent->title,
'depth' => $page->depth(),
'numChildren' => $page->numChildren(),
'createdDate' => date('Y-m-d', $page->created),
'modifiedDate' => date('Y-m-d', $page->modified),
'isLoggedIn' => $user->isLoggedin() ? true : false,
];
// Add custom fields if they exist
if ($page->hasField('category') && $page->category) {
$dataLayer['category'] = $page->category->title;
}
if ($page->hasField('tags') && $page->tags->count()) {
$dataLayer['tags'] = $page->tags->implode(',', 'title');
}
?>
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push(<?= json_encode($dataLayer) ?>);
</script>
<?= $page->region('head') ?>
</head>
<body>
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<?= $page->region('body') ?>
</body>
</html>
ProcessWire API Data for Analytics
ProcessWire's API provides rich page data accessible in any template:
| ProcessWire API | Data Layer Variable | Example |
|---|---|---|
$page->template->name |
pageTemplate |
blog-post, product |
$page->parent->title |
parentSection |
"Blog", "Products" |
$page->depth() |
depth |
2, 3 (tree depth) |
$page->created |
createdDate |
Unix timestamp |
$page->numChildren() |
numChildren |
5 (child pages) |
$page->tags->implode() |
tags |
"analytics,tracking" |
$user->isLoggedin() |
isLoggedIn |
true/false |
Platform Limitations
No admin script injection UI. ProcessWire does not have a built-in "Custom Scripts" field in the admin. All tracking code goes in PHP template files. Non-developers need developer assistance to modify tracking.
Template caching. ProcessWire's $config->templateCompile and ProCache module cache rendered output. Ensure tracking scripts are not cached with stale data layer values. ProCache users should verify that GTM and data layer scripts are included in cached output.
Module ecosystem is small. ProcessWire's module directory has fewer analytics-specific modules than WordPress. Most GA4/GTM implementations use direct template code.
Multi-language considerations. ProcessWire's multi-language support uses language-specific page names and URLs. Include the language in your data layer to segment analytics by locale.
Performance Considerations
- Lean core. ProcessWire generates lightweight HTML with minimal framework overhead. The relative impact of adding tracking scripts is higher than on heavier CMS platforms.
- API query efficiency. ProcessWire's selector engine (
$pages->find("template=blog-post, limit=10")) is optimized for performance. Data layer queries using$page->fieldare direct property access with minimal overhead. - ProCache optimization. If using ProcessWire's ProCache module for static file caching, tracking scripts baked into cached HTML load without any PHP processing, providing optimal performance.
Recommended Integration Priority
- Add GTM to
_main.php-- Single location covers all pages - Build API-driven data layer -- Use
$pageproperties and custom fields for rich analytics data - Configure GA4 via GTM -- Map ProcessWire templates to GA4 content groups
- Add Meta Pixel via GTM -- Standard engagement tracking
Next Steps
For general integration concepts, see the integrations overview.