Forkcms Analytics Integrations: Setup Guide | OpsBlu Docs

Forkcms Analytics Integrations: Setup Guide

Integrate GA4, GTM, and Meta Pixel with Fork CMS using the built-in Analytics module, Twig templates, and custom modules.

Fork CMS is a Symfony-based open-source CMS with a built-in analytics module and a modular architecture. It uses Twig templates, a Doctrine ORM backend, and a module system for extending functionality. Notably, Fork CMS ships with a native Google Analytics integration, making it one of the few CMS platforms with analytics built into the core.

Integration Architecture

Fork CMS provides four integration paths:

  1. Built-in Analytics Module -- Fork CMS includes a Google Analytics module at Settings > Modules > Analytics. It connects to the GA API to display traffic data directly in the admin panel. However, it does not automatically inject GA tracking code into the frontend.
  2. Twig Templates -- Edit your theme's layout template at /src/Frontend/Themes/yourtheme/Core/Layout/Templates/. Fork uses Twig templating with theme-specific overrides.
  3. Header/Footer Settings -- Navigate to Settings > General > Scripts to add custom HTML/JavaScript to the site's <head> or before </body>. This is the simplest method for tracking scripts.
  4. Custom Modules -- Create Fork CMS modules that inject scripts via the header and footer template blocks.

Available Integrations

Analytics Platforms

Google Analytics 4

  • Settings > General > Scripts (paste gtag.js)
  • GTM-based GA4 via header script injection (recommended)
  • Built-in Analytics module (API data display only, not code injection)

Tag Management

Google Tag Manager

  • Settings > General > Scripts head/footer sections
  • Theme layout template injection

Marketing Pixels

Meta Pixel

  • Via GTM container (recommended)
  • Settings > General > Scripts head injection

Admin Script Injection (Simplest)

Navigate to Settings > General and scroll to the Scripts section. Fork CMS provides fields for:

  • Header scripts -- Injected before </head>
  • Footer scripts -- Injected before </body>

Add GTM in the Header scripts field:

<!-- 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>

Theme Template Data Layer

For a richer data layer, edit your theme's layout template to include Fork CMS template variables:

{# src/Frontend/Themes/yourtheme/Core/Layout/Templates/default.html.twig #}
<!DOCTYPE html>
<html lang="{{ LANGUAGE }}">
<head>
    <script>
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
        'pageTitle': '{{ page.title|e("js") }}',
        'pageId': '{{ page.id }}',
        'language': '{{ LANGUAGE }}',
        'moduleAction': '{{ MODULE_ACTION|default("none")|e("js") }}',
        'isLoggedIn': {{ isLoggedIn ? 'true' : 'false' }}
    });
    </script>
    {{ block('header_scripts') }}
</head>

Platform Limitations

Built-in Analytics module is display-only. The native Analytics module connects to the Google Analytics API to show traffic reports in the Fork CMS admin, but it does not inject tracking code into the frontend. You still need to add the GA4/GTM snippet manually via Settings or templates.

Symfony version constraints. Fork CMS uses an older Symfony version (3.x/4.x depending on Fork version). Not all modern Symfony bundles are compatible. Verify bundle Symfony version requirements before installing analytics bundles via Composer.

Limited theme ecosystem. Fork CMS has a small theme marketplace. Most themes are custom-built, meaning tracking code must be added on a per-project basis rather than relying on theme-level integrations.

Module development complexity. Creating a custom Fork CMS module for analytics requires understanding Fork's module structure (Backend/Frontend separation, installer classes, template paths). For most use cases, the admin Scripts field is sufficient.

No ecommerce core. Fork CMS does not include ecommerce functionality. The Commerce module is community-maintained and has limited adoption. Ecommerce tracking requires custom implementation.

Performance Considerations

  • Lean baseline. Fork CMS generates relatively lightweight HTML. The impact of adding tracking scripts is proportionally significant. Use a single GTM container rather than multiple direct script injections.
  • Template caching. Fork CMS caches compiled Twig templates. After theme template changes, clear the cache at Settings > Advanced > Clear cache or run php bin/console cache:clear.
  • Asset combination. Fork CMS combines and minifies frontend assets. Third-party tracking scripts bypass this optimization. Use GTM to control script loading order and priority.
  1. Add GTM via Settings > General > Scripts -- No template editing needed, accessible to non-developers
  2. Add data layer in theme template -- Fork CMS page variables for content tracking
  3. Configure GA4 via GTM -- Map Fork CMS page hierarchy to content groups
  4. Add Meta Pixel via GTM -- Standard content engagement tracking

Next Steps

For general integration concepts, see the integrations overview.