lerni/silverstripe-tracking

Tracking Module for Silverstripe: Analytics, Tag Manager & Clarity

Installs: 48

Dependents: 0

Suggesters: 1

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:silverstripe-vendormodule

5.x-dev 2025-07-02 09:42 UTC

This package is auto-updated.

Last update: 2025-07-04 08:10:14 UTC


README

A Silverstripe module for Google Analytics, Google Tag Manager, Microsoft Clarity and Bing site verification. Features Consent Mode v2 support for privacy-compliant tracking, managed through Silverstripe's admin interface.

Requirements

  • silverstripe/cms ^5
  • silverstripe/siteconfig ^5

Suggested

  • lerni/klaro-cookie-consent

Installation

Composer is the recommended way to install Silverstripe modules.

composer require lerni/silverstripe-tracking

Run dev/build

This module allows XML files to be uploaded for Bing site verification.

Configuration

Setup

  1. Go to Settings > Tracking in the CMS admin
  2. Add your tracking IDs:
    • Google Tag Manager: GTM-XXXXXXX
    • Google Analytics v4: G-XXXXXXXXXX (one per line for multiple properties)
    • Microsoft Clarity: Your Clarity project ID

Consent Mode v2 Setup

  1. Enable Consent Mode: Check "Enable Consent Mode v2" in Settings > Tracking
  2. Cookie Consent Integration: Install lerni/klaro-cookie-consent for consent management
  3. Setup callback events: onAccept & onDecline for each service as needed

Additional Configuration

Kraftausdruck\Extensions\PageTrackingExtension:
  # Include logged-in members in tracking (default: false)
  track_members: true
  # Enable preconnect links for improved performance (default: false)
  # Enabling preconnect may leak user IP addresses to Google/Microsoft even before consent is given, as DNS lookups and TCP connections are established early. Consider this when implementing strict privacy requirements.
  preconnect: true

How Consent Mode Works

Without Cookie Consent Manager

When no consent management is active, the module automatically sets conservative consent defaults:

gtag('consent', 'default', {
    'ad_storage': 'denied',
    'analytics_storage': 'denied', 
    'ad_user_data': 'denied',
    'ad_personalization': 'denied'
});

With Klaro Cookie Consent

When integrated with the Klaro module, consent is dynamically updated based on user choices:

// User accepts Analytics service
gtag('consent', 'update', {'analytics_storage': 'granted'});

// User accepts Advertising service  
gtag('consent', 'update', {
    'ad_storage': 'granted',
    'ad_user_data': 'granted', 
    'ad_personalization': 'granted'
});

Multiple GA4 Properties

Add multiple Google Analytics 4 properties (one per line):

G-XXXXXXXXXX
G-YYYYYYYYYY
G-ZZZZZZZZZZ

Custom Configuration

The module automatically includes enhanced security settings when Consent Mode is enabled:

gtag('config', 'GA_MEASUREMENT_ID', {
    'anonymize_ip': true,
    'cookie_flags': 'secure;samesite=lax'
});

Important Notes

  • Live Mode Only: Tracking codes are only shown in live mode (not in development)
  • Member Tracking: By default, logged-in members are excluded from tracking.
  • Cookie Consent: Use lerni/klaro-cookie-consent for GDPR-compliance

Debug Mode

Enable debug mode to see consent state in browser console:

// In browser console
dataLayer.forEach(item => {
    if (item[0] === 'consent') console.log(item);
});

Resources