Cmsmadesimple Analytics Integrations: Setup Guide | OpsBlu Docs

Cmsmadesimple Analytics Integrations: Setup Guide

Integrate GA4, GTM, and Meta Pixel with CMS Made Simple using Smarty templates, User Defined Tags, and the Global Content Blocks module.

CMS Made Simple (CMSMS) is a PHP-based content management system that uses Smarty templating and a module-based architecture. Analytics integration uses CMSMS's template system, User Defined Tags (UDTs), or the Global Content Blocks module to inject tracking scripts into page output.

Integration Architecture

CMSMS provides three integration paths for analytics scripts:

  1. Smarty Templates -- Edit your site's layout template at Design > Templates to add scripts to the <head> or <body> sections. CMSMS uses Smarty 3 syntax.
  2. User Defined Tags (UDTs) -- Create reusable PHP/Smarty code blocks at Extensions > User Defined Tags that can be called from any template with {UDTName}.
  3. Global Content Blocks (GCBs) -- Create content blocks at Content > Global Content Blocks and include them in templates with {global_content name='tracking'}.

Available Integrations

Analytics Platforms

Google Analytics 4

  • Layout template injection (direct gtag.js)
  • GTM-based GA4 via template (recommended)
  • UDT for admin-configurable tracking ID

Tag Management

Google Tag Manager

  • Layout template <head> injection
  • UDT for reusable GTM snippet
  • Global Content Block for non-developer management

Marketing Pixels

Meta Pixel

  • Via GTM container (recommended)
  • Layout template head injection

Template Integration

Edit your primary layout template at Design > Templates. CMSMS templates use Smarty syntax with CMSMS-specific tags:

{* Main Layout Template *}
<!DOCTYPE html>
<html lang="{cms_lang}">
<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);{literal}}{/literal})(window,document,'script','dataLayer','GTM-XXXX');</script>

  <script>
  window.dataLayer = window.dataLayer || [];
  window.dataLayer.push({
    'pageTitle': '{title|escape:javascript}',
    'pageAlias': '{page_alias}',
    'pageId': '{page_id}',
    'templateName': '{template_name}',
    'siteLanguage': '{cms_lang}'
  });
  </script>

  {metadata}
  {cms_stylesheet}
</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>

  {content}
</body>
</html>

Note the {literal}{/literal} wrapper around the closing brace in the GTM snippet -- Smarty interprets bare } as a template tag delimiter.

User Defined Tag Approach

Create a UDT at Extensions > User Defined Tags called tracking_datalayer:

// UDT: tracking_datalayer
$gCms = cmsms();
$page = $gCms->GetContentOperations()->LoadContentFromAlias($gCms->GetContentOperations()->GetCurrentPageAlias());

$data = [
  'pageType' => $page ? $page->Type() : 'unknown',
  'menuText' => $page ? $page->MenuText() : '',
  'hierarchy' => $page ? $page->Hierarchy() : '',
  'hasChildren' => $page ? ($page->ChildCount() > 0 ? 'yes' : 'no') : 'no',
];

echo '<script>window.dataLayer=window.dataLayer||[];window.dataLayer.push(' . json_encode($data) . ');</script>';

Call it in any template with {tracking_datalayer}.

Platform Limitations

Smarty delimiter conflicts. JavaScript objects use { and } which conflict with Smarty's template delimiters. You must wrap JavaScript blocks containing braces in {literal}{/literal} tags or use Smarty's {ldelim} / {rdelim} tags. This is the most common source of tracking script errors in CMSMS.

No admin-facing script injection. There is no "Custom Header Scripts" field in the admin panel. Content editors must edit templates directly or use Global Content Blocks to modify tracking code.

Module ecosystem is aging. CMSMS's module repository (cmsmadesimple.org/forge) has limited activity. There is no maintained GA4 or GTM module. Manual template integration is the standard approach.

Template caching. CMSMS caches compiled Smarty templates. After template edits via the admin UI, the cache is automatically cleared. But if editing template files directly on the filesystem, you must clear the tmp/templates_c/ directory manually.

No ecommerce. CMSMS does not include ecommerce functionality. The CGEcommerceModule is deprecated. Ecommerce tracking is not applicable for standard CMSMS installations.

Performance Considerations

  • Lightweight baseline. CMSMS generates relatively lean HTML. The impact of adding GTM + GA4 is proportionally larger compared to heavier platforms.
  • Smarty compilation. Templates compile to PHP on first load. Complex data layer logic in Smarty templates has negligible runtime cost after compilation.
  • Database queries. UDTs that load page data via LoadContentFromAlias() execute additional database queries. For high-traffic sites, cache UDT output or move data layer values to simple Smarty variables already available in the template scope.
  1. Add GTM to layout template -- Use {literal} wrappers for JavaScript braces
  2. Create data layer UDT -- Reusable across all templates
  3. Configure GA4 via GTM -- Map CMSMS page hierarchy to GA4 content groups
  4. Add Meta Pixel via GTM -- Standard content engagement tracking

Next Steps

For general integration concepts, see the integrations overview.