Common issues and solutions for tracking problems on SilverStripe sites.
Common Causes
- Template not included - GA4/GTM not in Page.ss
- SiteConfig empty - Tracking ID not set
- Cache issues - Template cache not flushed
- JavaScript errors - Blocking tracking scripts
Diagnostic Steps
Check Tracking ID in CMS
- Log in to CMS
- Settings > Analytics
- Verify tracking IDs are set
- Save if needed
Clear Cache
sake dev/build flush=1
Check Page Source
- Visit your site
- View page source
- Search for
gtag,fbq, ordataLayer - Verify script is present
Check Browser Console
// For GA4
console.log(typeof gtag);
// For Meta Pixel
console.log(typeof fbq);
// For GTM
console.log(window.dataLayer);
Issue: Script Not Loading
Cause: Template Not Included
Check: Page.ss includes the analytics template
<!-- Must be in Page.ss -->
<% include GoogleAnalytics %>
<% include MetaPixel %>
<% include GoogleTagManager %>
Cause: Extension Not Applied
Check: Extension registered in config.yml
SilverStripe\SiteConfig\SiteConfig:
extensions:
- App\Extensions\SiteConfigExtension
Then run: sake dev/build
Issue: Events Not Tracking
Check Requirements Script
// In PageController
protected function init()
{
parent::init();
// Make sure this runs
Requirements::customScript(<<<JS
console.log('Init ran');
JS
);
}
Verify Script Position
Scripts should be in <head> or before </body>:
<head>
<% include GoogleAnalytics %>
</head>
Issue: Template Changes Not Showing
Clear Template Cache
sake dev/build flush=1
Or visit: yoursite.com/?flush=1
Disable Cache in Dev
File: .env
SS_ENVIRONMENT_TYPE="dev"
Issue: Forms Not Tracking
Check Form Handler
public function doSubmitContact($data, $form)
{
// Must include tracking script
Requirements::customScript(<<<JS
if (typeof gtag !== 'undefined') {
gtag('event', 'form_submission', {
'form_name': 'contact'
});
}
JS
);
return $this->redirectBack();
}
Issue: Different Behavior in Live vs Dev
Check Environment Detection
use SilverStripe\Control\Director;
// Only track in live
if (Director::isLive()) {
// Add tracking
}
Testing Checklist
- Tracking ID set in CMS
- Include template in Page.ss
- Extension registered and dev/build run
- Cache flushed
- No JavaScript errors in console
- Script visible in page source
- Tested in incognito mode (no ad blockers)