#GTMTips: URL Source in the URL Variable

You can use the URL Source setting in your URL variables to make your Google Tag Manager URL variables even more flexible.

One of the less-known features of Google Tag Manager, a hidden gem if you will, is the URL Source setting in the URL Variable type. It lets you parse any URL String for its components.

Tip 38: Parse URL strings with the URL Source setting

The setting itself is easy to find. Just edit an existing URL Variable, or create a new one. Then, scroll down to the More Settings divider, expand it, and you’ll see the URL Source drop-down list.

This list will list all the Variables in your container, Built-In Variables included, and you can pick the one you want to parse. Note that the Variable you choose needs to return a properly formatted URL string for parsing to work. A properly formatted URL has at least the protocol (e.g. http:// or https://) and hostname (e.g. domain.com).

Won’t work:
simoahava.com
www.simoahava.com
www.simoahava.com/some-page

Will work:
http://careers.simoahava.com
https://makemoney.simoahava.com/about-us/

The URL Source setting establishes a URL String that is then parsed according to the Component Type setting you chose. In the image above, I’m using the Referrer Built-In Variable, which returns the referrer URL of the page in question, and I’m parsing it just for its path. In other words, this particular URL Variable will return the path of the previous page.

If the referrer is https://www.simoahava.com/about-simo-ahava/, the Variable will return /about-simo-ahava/.

Quite a useful feature, and often overlooked.