Guide 107 · Container · GA4 + Tag Manager
Create a URL variable: pull one part of the page address out of the URL
A page address carries more than an address: the hostname says which site, the path says which section, the query string carries the order number, the fragment says which part of the page. A URL variable pulls one part out so a trigger or a tag can use it on its own. Google's variable page lists the eight parts you can choose from: Full URL, Protocol, Hostname, Port, Path, Filename Extension, Query, and Fragment. The worked example takes the address https://www.example.com/shop/checkout?order=1042#summary and pulls four parts out of it.
After step 4, Preview mode shows four variables with four values for the worked address: hostname www.example.com, path /shop/checkout, query order=1042 and fragment summary — each one usable on its own in a trigger filter.
Download the container fragment: the URL variable fragment (JSON) (export format version 2, 2312 bytes, MD5 6a9267f8ffb3d04b6137f1550747136a). It holds the four URL variables from the worked example — hostname, path, query and fragment — plus a GA4 event tag that fires on the checkout path. The file is a hand-built import template, validated structurally — it was not exported from a live container.
What you need
- A page address with the part you need in it. The worked example is
https://www.example.com/shop/checkout?order=1042#summary. If the value is not in the URL, a URL variable cannot find it — that is a data layer variable's job. - The list of the eight URL components. Full URL, Protocol, Hostname, Port, Path, Filename Extension, Query, and Fragment. Pick the one that holds the value, not the whole address.
- Edit access to the container. Creating a variable is a container edit.
The trace
- Go to Variables and click New under User-Defined Variables. The Variables page has two sections; user-defined variables are the lower one.
- Click Variable Configuration and choose URL. URL is listed under Navigation. Pick it and the configuration shows a component selector and a URL source. The source defaults to the current page's URL, taken from
document.location. - Choose Path and name the variable
URL - Page Path. The path is the section of the site: for the worked address it is/shop/checkout. A trigger that filters on this variable can limit a tag to the checkout section without listing every checkout page. - Repeat for the other three parts in the worked example. Create
URL - Hostnameforwww.example.com,URL - Queryfororder=1042, andURL - Fragmentforsummary. That is 4 variables from 1 address — 8 components exist, and the worked example uses 4 of them. Each one is a separate variable with its own name.
Dead ends
DEAD END — THE QUERY STRING IS NOT THE ORDER NUMBER. The Query component returns the whole query string — order=1042 — not just the value 1042. A trigger that compares the query against 1042 never matches. Compare against the full string, or use a regex table to pull the number out.
DEAD END — A URL VARIABLE FOR A VALUE THAT IS NOT IN THE URL. A URL variable reads the address the browser is on. A value that lives in the page — a price, a form field, a cookie — is invisible to it. The variable returns the address part you asked for, or empty, and nothing else.
DEAD END — FORGETTING THE FRAGMENT IS CLIENT-SIDE ONLY. The fragment after the # never reaches the server, so server logs never show it. A URL variable is one of the few ways to measure it — and a tag that sends the full URL to a third party sends the fragment along with it.
End state
Four URL variables — hostname, path, query and fragment — each returning one part of the worked address. A trigger can now fire on a section, an order number or a page fragment without matching the whole address.
Sources
- Tag Manager Help — User-defined variable types for web — URL variable type, the eight components Full URL, Protocol, Hostname, Port, Path, Filename Extension, Query and Fragment, the source defaulting to the current page URL, Variables then New then Variable Configuration
Checked 11 November 2026. The click paths above are the ones in Google's help pages, opened 11 November 2026. No step in this guide was run inside a live Analytics property or a live Tag Manager container, because both need a Google sign-in and this site does not sign in as anyone. The container file was validated structurally instead: export format version 2, every tag's firing trigger resolves, every variable the tags reference exists in the file, and the tag types are the documented ones. Google moves menu items without warning; if a path on this page no longer matches, the linked help page is the current map. The container fragment for this guide is 2312 bytes (2.26 KB, 1.13% of the reported 200 KB container size limit), MD5 6a9267f8ffb3d04b6137f1550747136a, and passed 21 structural checks.