How to Fix SilverStripe Events Not Firing | OpsBlu Docs

How to Fix SilverStripe Events Not Firing

Fix GA4, GTM, and pixel events not firing on SilverStripe — Page.ss template head inclusion, SiteConfig tracking ID setup, and template cache flush...

Common issues and solutions for tracking problems on SilverStripe sites.

Common Causes

  1. Template not included - GA4/GTM not in Page.ss
  2. SiteConfig empty - Tracking ID not set
  3. Cache issues - Template cache not flushed
  4. JavaScript errors - Blocking tracking scripts

Diagnostic Steps

Check Tracking ID in CMS

  1. Log in to CMS
  2. Settings > Analytics
  3. Verify tracking IDs are set
  4. Save if needed

Clear Cache

sake dev/build flush=1

Check Page Source

  1. Visit your site
  2. View page source
  3. Search for gtag, fbq, or dataLayer
  4. 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)

Next Steps


Additional Resources