Cherry Seed

How do I implement coded UTM protection on WordPress?

utm wordpress server-side coded-urls init-hook attribution

Quick Answer

Capture and decode the campaign parameters server-side, in an early WordPress hook, before any redirect or browser script runs. The pattern is to read the incoming query string, whether standard utm_* values or your own short coded tokens, on the init or template_redirect hook, decode the tokens back to real source, medium, and campaign, and store the result in the session and on the order at checkout. Because this fires before WooCommerce, your theme, or any pixel executes, the attribution is already secured even if a blocker later kills the tracking script.

Full Answer

There are two implementation routes. The first is a plugin built for server-side capture: it hooks WordPress early, reads and persists campaign data automatically, and decodes coded tokens if you use them, so you write no custom code. The second is a small amount of code in a custom plugin or functions.php, which is the right choice when you want full control over the token map and storage.

The custom approach has a fixed shape. Hook a function to an early action such as init or template_redirect so it runs before output and before redirects. In that function, read the relevant query parameters from the request, and if you use encoding, expand each short token against your lookup map into the real utm_source, utm_medium, and utm_campaign. Persist those values to the PHP session or a first-party cookie immediately, then copy them onto the WooCommerce order when checkout completes so attribution travels with the sale.

The reason timing matters this much is that everything hostile to tracking, ad blockers, ITP cookie caps, and link-tracking parameter stripping, acts on the browser after the page begins loading. Reading the parameters in an early server hook beats all of it, because the data is captured and stored before any of those mechanisms get a turn. From there your server-side events carry clean, standard UTM values to GA4 and ad platforms, and the public link can stay short and coded without your reports ever noticing the difference.

Sources

Programmatic Access

GET https://seresa.io/wp-json/cherry-tree-by-seresa/v1/seeds/770

Cite This Answer

Cherry Tree by Seresa - https://seresa.io/seed/utm-attribution/protect-utm-s7