Lesson 12 of 15
1St-Party Cookie Variable
① Connect your GTM container
Paste your container ID to load it into this page. It only ever runs here.
Advanced: use a specific environment
Cookies are how sites remember things between page loads: a logged-in flag, an A/B bucket, a campaign source. When you need one of those values in a tag, GTM has a purpose-built variable for reading them, the 1st-Party Cookie variable.
You give it the cookie's name and it returns that cookie's value, no JavaScript required. It only reads cookies set on your own domain (first-party), which is exactly the kind your site controls.
Goal
Build a 1st-Party Cookie variable that reads the ht_demo cookie.
Build it in GTM
Set the demo cookie
Click the button below to writeht_demo=42for this origin. The variable has nothing to read until the cookie exists.Create the 1st-Party Cookie variable
Go to Variables → New and choose 1st-Party Cookie.Point it at ht_demo
Set Cookie Name toht_demo, the cookie's name, not its value. Leave URI-decode cookie at its default. Name itCookie - ht_demoand Save.Use it where you need it
No tag is required for this lesson, the variable is the deliverable. On the real site you would send{{Cookie - ht_demo}}as a GA4 parameter or user property.
Debug in Tag Assistant
Copy this lesson's live URL and paste it into GTM Preview, that is the page Tag Assistant connects to. It has the clickable elements, so this page stays clean for reading.
- In your GTM, click Preview.
- Paste the live URL above and click Connect.
- Interact with the live page and watch your tag fire in Tag Assistant.
What you should expect to see
{{Cookie - ht_demo}} resolves to 42 in Tag Assistant's Variables tab. Before the cookie is set it returns undefined.Verify your container
Built it? Export your container, Admin → Export Container, choose your workspace, then drop the JSON here to check it against this lesson.
Drop your container .json here
or browse · checked in your browser, nothing is uploaded