Unlock Dynamic UTMs: The Shortlink Manager Module Just Got Smarter

October 29, 2025

When I first built the Shortlink Manager module for Drupal, the core mission was simple: eliminate the attribution chaos caused by unmanaged external links. I achieved consistency with the UtmSet configuration entity, ensuring every shortlink started reporting from the right source and medium.

But static values are just the starting line.

As I began using the module across my own site content — spanning blog posts, service pages, and View pages — I realized the setup was still missing the "auto" in "automation". Every time I created a shortlink for a new piece of content, I was manually copying the node title or the term name just to populate utm_content parameter to the shortlink settings. This led to two headaches:

  • Repetitive Labor: Constant copying and pasting.
  • Dirty Data: Inconsistent casing, trailing hyphens, and special characters polluting my analytics reports.

That realization led to the newest, most impactful feature addition to date; dynamic UTM automation. To achieve this extreme flexibility, I add support for tokens! Yes, it was that simple! This doesn't just help manage shortlinks better, it makes them smarter.

Static vs. Smart Tracking

Before this update, every UtmSet used fixed text. A marketing campaign for my services pages might look like this:

utm_source=bluesky
utm_medium=social
utm_campaign=services_page

This forced me to either accept generic reporting (everything under services_page) or duplicate my UtmSet configurations hundreds of times. This neither scales well at all and isn't any better than my previous spreadsheet method.

Dynamic UTM Automation with Tokens

The Shortlink Manager now supports Drupal Tokens across all UTM fields. This allows my UTM parameters to automatically inherit context from the destination entity, for example, the node, the taxonomy term, or even the user accessing the link.

Example: A Self-Configuring UTMSet

Here is a configuration that proves the power of this update:

id: term_service_linkedin
label: 'Term: Service: LinkedIn'
utm_source: linkedin
utm_medium: social
utm_campaign: 'services_page'
utm_content: '[term:name]_service'

If this shortlink points to the "Web Development" term, the generated URL will automatically include:

utm_campaign=services_page
utm_content=web_development_service

Notice the casing and the underscores? That leads to the second, and arguably most important, part of this feature.

The Secret Sauce: The Data Sanitization Pipeline

Token replacement is powerful, but it's raw. A token like [ node:title ] might resolve to: "Custom Drupal Development".

If I used that raw string, my analytics report would be a total mess.

To solve this, I built a dedicated sanitization pipeline that runs immediately after the token is resolved and before the parameter is added to the URL. This guarantees your data is clean, consistent, and easy to analyze.

The pipeline executes three critical steps:

  • Mass Replacement: All non-URL-safe characters (spaces, parentheses, dashes, etc.) are replaced with a single underscore ("_").
  • Underscore Reduction: Consecutive underscores (e.g., "__") are condensed into a single underscore.
  • Lowercasing and Trimming: The entire string is converted to lowercase, and any leading/trailing underscores are removed.
     

Using the previous two examples, here is what the UTM Parameters would look like with the sanitization:

Raw Token Output After Sanitization Pipeline
"Custom Module Development" "custom_module_development"
"Web Development_Service" "web_development_service"

This attention to detail ensures your tracking data is perfect, allowing you to slice and dice information in Google Analytics without worrying about inconsistent character sets or casing.

Note: I also applied token support to the Destination Override field, ensuring that even custom redirects can be dynamic.

Real-World Use Cases: Automated Attribution

This update is a game-changer for automating your attribution strategy:

  •  Content-Specific Campaigns: Use [ node:title ] or [ node:uuid ] in utm_content for unparalleled granularity without any manual effort.
  • Time-Sensitive Tracking: Use [ current-date:custom:Ymd ] to ensure campaign codes are instantly updated for time-based reporting.
  • Multichannel Tracking: Create one UTMSet per platform (e.g., "LinkedIn", "Mastodon", "Bluesky") and let the tokens fill in the content details automatically.

These simple patterns allow every campaign link to tell its own rich, accurate, and completely automated story.

Final Thoughts

This update makes the Shortlink Manager module smarter and far more adaptable. For me, it was a complex integration—especially getting the token context right across entities and resolving tokens that were already present in a destination URL (a tricky one I solved during testing!)—but the payoff is huge.

It’s time to retire the copy-and-paste routine.
 

I'm incredibly excited about the possibilities this feature unlocks. How do you plan to use dynamic tokens to clean up your own analytics? Let me know in the comments!

If you are currently using the module, I encourage you to update today and test out the new dynamic token features in your UtmSets. You can get the latest release via Composer: composer update drupal/shortlink_manager.

If you haven't yet brought UTM tracking into Drupal, now is the ideal time to adopt this configuration-driven, automation-focused solution. Complete details on installing the module and the source code are available in the Shortlink Manager GitHub Repository.

Dream It. Build It. Now, Automate It.

Author

Ron Ferguson

0 Comments

Login or Register to post comments.