Custom Tealium Event Tracking in Drupal – Behind the Code
As a certified Drupal developer with 8+ years of experience, I’ve worked on many complex integrations. But one recent challenge stood out: implementing custom Tealium event tracking in Drupal in a flexible and scalable way.
This post is a deep dive into how we made it dynamic, configurable, and production-ready — a behind-the-scenes look for developers, architects, and digital marketers who live in the intersection of data and code.
🎯 The Problem
Most tracking scripts are added statically or via GTM. But we needed something more granular:
🧠 Our Approach
✅ Step 1: Create a Custom Drupal Module
We built a core module tealium_event, with a submodule gson_tealium_event for project-specific configs.
✅ Step 2: Add a YAML-Based Configuration System
We stored trigger conditions and event data in a YAML file like:
cta_download:
url_pattern: "/resources/*"
link_text_contains: "Download Now"
event_data:
event_name: "download_cta_click"
category: "CTA"
label: "Download Resource"
This config made the solution fully extensible — just update YAML, no code changes!
💻 Step 3: Inject JavaScript via Drupal Library
The JS file reads the YAML config (converted to JSON via drupalSettings) and:
Example:
Recommended by LinkedIn
if (link.textContent.includes(config.link_text_contains)) {
utag.link({
event_name: config.event_data.event_name,
category: config.event_data.category,
label: config.event_data.label
});
}
🔐 Step 4: Add an Admin Config Form
We added a Drupal config form under Configuration > Development > Tealium Events, allowing admins to:
🌐 Step 5: Restrict to Production via Environment Variable
We used environment-specific settings:
$config['tealium_event.settings']['enabled'] = getenv('TEALIUM_ENABLED') ?: FALSE;
This gave us control per environment (dev, stage, prod) without risking dirty data.
🚀 Results
✅ Fully dynamic Tealium tracking ✅ Configurable via YAML + UI ✅ Zero deployments for new event tags ✅ Clean separation between logic and data ✅ Marketing team happy, dev team happier 😊
🧩 Learnings
🗣️ Over to You
Have you implemented something similar? Would love to hear how you’re handling tracking in Drupal or other frameworks.
Let’s geek out on clean code + data + digital experience! Feel free to drop your thoughts or questions below 👇
#Drupal #Tealium #WebAnalytics #JavaScript #DrupalDeveloper #TagManagement #DigitalMarketing #WebDevelopment #OpenSource #Drupal10