Skip to main content
info@drupalodyssey.com
Wednesday, August 20, 2025
Contact

Main navigation

  • Home
  • Blog
    • all
    • Development
    • Community
    • Management
    • DevOps
    Photo by Negative Space: https://www.pexels.com/photo/blue-and-green-pie-chart-97080/
    How to Automate UTM Parameters with a Drupal Module
    Aug 17, 2025
    Photo by Negative Space: https://www.pexels.com/photo/blue-and-green-pie-chart-97080/
    How to Automate UTM Parameters with a Drupal Module
    Aug 17, 2025
    Photo by Ivan Samkov: https://www.pexels.com/photo/text-4491829/
    Building a Custom Drupal Shortlink Manager: An SEO and Marketing Journey
    Aug 13, 2025
    Photo by  Anastasia  Shuraeva: https://www.pexels.com/photo/a-bearded-man-reading-a-burning-newspaper-7539726
    Bulletproof Your Drupal Data With Automated Nightly Backups
    Jul 30, 2025
    Photo by Tara Winstead: https://www.pexels.com/photo/white-ipad-on-white-paper-8386713/
    Is Your Content Calendar Working You to Death? Schedule It Away in Drupal!
    Jul 26, 2025
    Contractor happy with blueprints.
    Streamlining Drupal Deployments Using Drush and GitHub Actions CI/CD
    Jul 22, 2025
    Reduce, Reuse, Recycle
    Streamlined Content: Effortless PDF Display & Management in Drupal
    Jul 21, 2025
    Aluminum Cans Passing Through the Assembly Line by cottonbro studio on Pexels
    Automate and Simplify Your Drupal Workflow with Bash Scripts for Shared Hosting
    Jul 19, 2024
    Binoculars resting on newspapers.
    Evaluating Search and Replace Scanner: The Ultimate Tool for Drupal Bulk Content Edits?
    Jun 29, 2024
    People looking at a computer screen
    S3 File System Module Not Working with Media Entity Download Module? Here's the Fix
    Jun 18, 2024
    Mechanic hands working on an engine.
    Setting Up the Etsy OAuth2 Client For Use With The Etsy Shop Integration Module
    May 10, 2024
    Fashion designer sketching new garments.
    Crafting Your Online Store: Drupal's Role in Your Etsy Success
    May 09, 2024
    Socket toolbox
    Beginner's Guide: Getting Started With Drush for Efficient Drupal Development
    May 08, 2024
    Stargazing over mountians.
    Drupal-Powered Stargazing: A Module for NASA's Astronomy Picture of the Day
    Sep 15, 2023
    Computer screen with code.
    Learn How To Script Drupal Installations Using Drush
    Dec 08, 2014
    Scuba diver with Drupal mask.
    Scuba: Drupal Style
    Oct 16, 2014
    Woman frustrated with laptop.
    5 Reasons Your CMS Sucks
    Jul 24, 2013
    Two young men having a discussion in front of a computer.
    Deployment Module XSRF Patch Committed
    Jul 05, 2013
    Two young men having a discussion in front of a computer.
    Deployment Module XSRF Patch Committed
    Jul 05, 2013
    Application settings.
    Using PHP To Disable Internet Explorer Compatibility Mode
    Jun 04, 2013
  • Resources
  • About
  • SPACER
  • SPACER
  • SPACER
  • SPACER
  • SPACER
Search
Development

How to Automate UTM Parameters with a Drupal Module

August 17, 2025

Drupal Odyssey is supported by it's readers. When you purchase products or services using the links on this site, we may earn a small commission at no additional cost to you. Learn more

What if every click on your link told you where it came from, how it was used, and what campaign it belonged to? That's the magic of UTM parameters, and in this post, I'll show you how I built a system to make managing them a breeze.

If you've been following my journey, you know the frustration of juggling spreadsheets to manually create trackable URLs. I knew my shortlink manager needed to do more than just shorten links; it had to empower me with data. My solution was creating UTM Sets – a feature that transforms simple links into powerful tracking tools.

What are UTMs, and Why Should You Care?

First things first: what exactly is a UTM parameter? In simple terms, it's a little snippet of text added to the end of a URL. Think of it as a digital fingerprint for your link. These parameters tell Google Analytics and other tracking platforms specific details about who clicked your link and how they found it. For a deeper dive into UTM parameters, I highly recommend visiting Analytics Mainia (https://www.analyticsmania.com/post/utm-parameters-in-google-analytics-4/).

There are five main types of UTM parameters:

  • utm_source: The source of your traffic (e.g., facebook, newsletter).
  • utm_medium: The marketing medium (e.g., social, email).
  • utm_campaign: The specific campaign (e.g., fall_promo, new_product_launch).
  • utm_term: Keywords for a paid ad.
  • utm_content: Used to differentiate similar content or ads.

The result is a URL that looks a little more verbose, but provides a wealth of information:

https://example.com/go/sui49_nm?utm_source=facebook&utm_medium=social&utm_campaign=fall_promo

The Why: From Tedious to Terrific

So, why go through the trouble? Because understanding your traffic is the difference between guessing and knowing. UTMs help you:

  • Measure ROI: Pinpoint exactly which campaigns, platforms, and ads are bringing in the most valuable traffic.
  • Optimize Content: Understand which of your social media posts or email subject lines are performing best.
  • Make Smarter Decisions: Allocate your resources to the marketing efforts that are actually working.

Before my module, for me, this meant opening a spreadsheet every single time I needed a new link – a manual, error-prone process. I knew there had to be a better way.

The Implementation: Introducing the UtmSet

My solution was to build the Utm Set as a reusable configuration entity within Drupal. This technical decision was a game-changer. In Drupal, content entities are for day-to-day, user-generated information, like a blog post, an e-commerce product, or a user profile. In contrast, configuration entities are for site-wide settings and reusable structures, like a content type or, in my case, a UTM Set. This distinction is what allows me to create and reuse tracking templates across all my content.

For the developers in the audience, this is what the entity annotation looks like which is how I told Drupal to store and export the individual UTM parameters:

/**
 * Defines the UTM Set config entity.
 *
 * @ConfigEntityType(
 *   id = "utm_set",
 *   label = @Translation("UTM Set"),
 *   label_collection = @Translation("UTM Sets"),
 *   label_singular = @Translation("utm set"),
 *   label_plural = @Translation("utm sets"),
 *   label_count = @PluralTranslation(
 *     singular = "@count UTM set",
 *     plural = "@count UTM sets",
 *   ),
 *   handlers = {
 *     "list_builder" = "Drupal\shortlink_manager\UtmSetListBuilder",
 *     "form" = {
 *       "add" = "Drupal\shortlink_manager\Form\UtmSetForm",
 *       "edit" = "Drupal\shortlink_manager\Form\UtmSetForm",
 *       "delete" = "Drupal\Core\Entity\EntityDeleteForm",
 *     },
 *   },
 *   config_prefix = "utm_set",
 *   admin_permission = "administer utm_set",
 *   links = {
 *     "collection" = "/admin/structure/utm-set",
 *     "add-form" = "/admin/structure/utm-set/add",
 *     "edit-form" = "/admin/structure/utm-set/{utm_set}",
 *     "delete-form" = "/admin/structure/utm-set/{utm_set}/delete",
 *   },
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "label",
 *     "uuid" = "uuid",
 *   },
 *   config_export = {
 *     "id",
 *     "label",
 *     "description",
 *     "utm_source",
 *     "utm_medium",
 *     "utm_campaign",
 *     "utm_term",
 *     "utm_content",
 *     "status",
 *   },
 * )
 */

Instead of manually typing out utm_source=facebook and utm_medium=social for every single link that I post on Facebook or other social media platforms, I can now create a UtmSet once and reuse it across multiple shortlinks.

For example, you could create a UtmSet named "Facebook Promo" with utm_source set to facebook, utm_medium to social, and utm_campaign to fall_promo. Then, you can simply apply this set to any new shortlink you create for that specific campaign.

This approach not only saves an incredible amount of time but also ensures consistency across your data. No more typos in your UTM parameters!

The User Experience: Simple and Powerful

From a user's perspective, the process is incredibly simple. You navigate to the UtmSet configuration area, create a new set with your desired parameters, and save it. When you create a new shortlink, a simple dropdown menu allows you to select and apply any of your pre-configured UTM Sets. Just like that, your shortlink is not only clean and simple, but also packed with valuable tracking information.

 

Potential Limitations

While this setup works perfectly for what I need, I can see where this might be limited for other use cases with only utm_source, utm_medium, utm_campaign, utm_term, and utm_content. A lot of times, marketers pass a whole range of custom UTM parameters and the way I built it does not allow for that. Since I identified that limitation, my brain has been needling on how to resolve that so it's more expandable and useful to everyone. Surely, as with other configurations, there is a way to integrate third-party settings so that any other tracking parameters can be added at any time.

UTM Set UTM parameters.

What's Next?

The UtmSet feature is one of the things I'm most proud of, and it makes my module so much more than just a simple link shortener. It turns my links into a powerful data collection tool.

Next time, I'll get to the heart of the matter: the Shortlink content entity itself. I'll show you how I tied everything together to create the final, working product that makes the whole process quick and seamless.

Author

Ron Ferguson

 

Next Blog

0 Comments

Login or Register to post comments.

Categories

Categories

  • Development
    (9)
  • Community
    (9)
  • Management
    (7)
  • DevOps
    (5)

Trending Blog

Trending Blog

Photo by Ivan Samkov: https://www.pexels.com/photo/text-4491829/
Building a Custom Drupal Shortlink Manager: An SEO and Marketing Journey
13 Aug, 2025
Photo by Negative Space: https://www.pexels.com/photo/blue-and-green-pie-chart-97080/
How to Automate UTM Parameters with a Drupal Module
17 Aug, 2025
Contractor happy with blueprints.
Streamlining Drupal Deployments Using Drush and GitHub Actions CI/CD
22 Jul, 2025
Woman frustrated with laptop.
5 Reasons Your CMS Sucks
24 Jul, 2013
Mechanic hands working on an engine.
Setting Up the Etsy OAuth2 Client For Use With The Etsy Shop Integration Module
10 May, 2024

Tags

Tags

  • Drupal 10
  • Drupal 9
  • Drupal 8
  • Drupal 11
  • Drupal
  • Drupal 7
  • Drush
  • MySQL

Ad - Sidebar (300 x 250 AD)

Ad - Sidebar (300 x 600 AD)

Newsletter

Subscribe my Newsletter for new blog & tips Let’s stay updated!

Categories

  • Development
  • Community
  • Management

Useful Links

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Disclaimer
  • Cookies

Must Read

Photo by Tara Winstead: https://www.pexels.com/photo/white-ipad-on-white-paper-8386713/
Is Your Content Calendar Working You to Death? Schedule It Away in Drupal!
26 Jul, 2025
Aluminum Cans Passing Through the Assembly Line by cottonbro studio on Pexels
Automate and Simplify Your Drupal Workflow with Bash Scripts for Shared Hosting
19 Jul, 2024
Binoculars resting on newspapers.
Evaluating Search and Replace Scanner: The Ultimate Tool for Drupal Bulk Content Edits?
29 Jun, 2024
Mechanic hands working on an engine.
Setting Up the Etsy OAuth2 Client For Use With The Etsy Shop Integration Module
10 May, 2024

© 2025 All Rights Reserved.

Proud supporter of active military, veterans and first responders.