links with utm parameters. How to shorten with GTM?

42 Views Asked by At

This is what I want to do: websiteurl.com?utm_source=click&utm_medium=here

I wanted it to instead be: websiteurl.com?clickhere

so that whenever I append ?clickhere to a url, it will always point to utm_source=click&utm_medium=here

Hope that's clear.

I've been searching for this and all I can find are tutorials for when it's still GA3 with the old options in GTM configurations? Anyone who can help me with this?

1

There are 1 best solutions below

0
On

Yeah, pretty much any advanced gtm search is doomed to be flooded with unrelated basic articles.

What you're looking for is GTM's ability to override dl (the document location) dimension of your call.

Make a CJS variable, and in it check for your query parameters. If they exist, then build a proper url containing your injected utm params and return it. If they don't exist, then just return the current href.

Then you open your pageview rule, and set the dimension document_location to your CJS var value. Test profusely before publishing. Test with many other query params, test with the hash and query params.

Gotta be careful when overriding the dl. Check out your dp while testing. Decide whether it needs overriding too, but that shouldn't be mandatory since GA parses dl for the utms.