The first-party cookie variable in Google Tag Manager is a variable type that lets you read the value of a cookie set by your own site’s domain, a first-party cookie, and make it available inside the tags and triggers configured in the container. In practice, it retrieves information stored in the user’s browser directly from the visited site, without needing additional custom code.

This variable type is especially useful for managing consent, user identifiers, language preferences or session values. Since first-party cookies belong to the domain the user is visiting, they are generally considered more reliable and less subject to restrictions than third-party cookies, although they are still subject to privacy regulations and browser settings.

A first-party cookie is a small text file stored in the user’s browser by the domain they are currently visiting. When the user browses a site, that site’s server can send the browser an instruction to save a cookie with a specific name and value. On subsequent visits, the browser automatically sends that cookie back to the same domain, allowing the site to recognize the user or retrieve the saved information.

The main distinction is the cookie’s origin: if the cookie is set by the domain shown in the address bar, it is a first-party cookie; if it is set by a different domain, it is a third-party cookie. This difference has important implications for privacy, browser policies and the functioning of analytics and advertising platforms.

In Google Tag Manager, the first-party cookie variable is configured by entering the name of the cookie you want to read. When the variable is called, the container looks for that cookie in the user’s browser and returns its value. If the cookie does not exist or is not accessible, the variable returns an empty or undefined value, depending on the configuration.

This variable can be used in both tags and triggers. For example, a trigger can fire only if a certain cookie has a specific value, while a tag can send the cookie’s content to an analytics platform as a parameter. This way you can build conditional logic without writing additional code.

Why third-party cookies behave differently

Third-party cookies are set by domains other than the one visited and are often used for advertising tracking or cross-site analytics. First-party cookies, on the other hand, belong to the site itself and are generally more accepted by users and browsers. As a result, a variable that reads a first-party cookie tends to work more reliably than one that depends on third-party cookies.

Scenarios where you need to read it

The first-party cookie variable is suitable for several operational scenarios. One of the most common is consent management: many consent management systems set a first-party cookie indicating which tracking categories the user has accepted. Google Tag Manager can read that cookie and fire or block tags accordingly.

Another frequent scenario is retrieving user or session identifiers generated by the site. If the site sets a cookie with a unique identifier, the variable can read it and pass it to analytics or personalization tools. Language, currency or layout preferences can also be read through this variable to adapt tag behavior.

Simplicity, consistency and maintenance

The first advantage is simplicity: you don’t need to write custom code to read a cookie, because the variable does it automatically. The second is consistency: all tags and triggers in the container can access the same value, reducing the risk of errors. The third is maintainability: if the cookie name changes, you only need to update the variable in one place.

Setting up the variable without errors

To configure the variable, you need to know the exact cookie name, which is case-sensitive. Once the cookie is created on the site, you add a new first-party cookie variable in the container and enter the name. It is good practice to document the cookie’s name and purpose to make future maintenance easier.

Another good practice is to always test the variable’s behavior in preview mode, checking that the value read matches the one actually present in the browser. Also, it is advisable to provide a fallback value for cases where the cookie is not available, preventing tags from behaving unexpectedly.

What it cannot read and what to watch out for

The variable only reads cookies accessible from the current domain and cannot read cookies marked as HttpOnly, because these are not visible to client-side code. Also, if the user deletes cookies or browses in incognito mode, the variable may not return any value. Finally, cookie usage must always comply with current privacy and consent regulations.

Variable type What it reads Data source Typical use
First-party cookie A cookie from the current domain User’s browser Consent, identifiers, preferences
Third-party cookie A cookie from an external domain User’s browser Cross-site tracking
Custom JavaScript Any calculated value Code in the container Complex logic and calculations
URL variable Address components Current page Campaign parameters and paths
Structured data variable Values from structured data Current page E-commerce and content

Creating the variable, step by step

  1. Access your Google Tag Manager container and open the variables section.
  2. Select the option to create a new user-defined variable.
  3. Choose the first-party cookie variable type.
  4. Enter the exact name of the cookie you want to read.
  5. Give the variable a descriptive name so you can recognize it easily.
  6. Save the variable and check the value in preview mode.
  7. Call the variable in the tags or triggers that need it.
  8. Publish the container after verifying everything works correctly.

Frequently asked questions

What is the difference between a first-party and a third-party cookie?

A first-party cookie is set by the domain the user is visiting, while a third-party cookie comes from a different domain. This difference affects browser restrictions and privacy regulations.

Can the first-party cookie variable read HttpOnly cookies?

No, cookies marked as HttpOnly are not accessible to client-side code and therefore cannot be read by this variable. Accessing them would require server-side intervention.

What happens if the cookie does not exist?

If the cookie is not present in the browser, the variable returns an empty or undefined value. It is advisable to provide a fallback value in the tags that use it.

Can I use the variable in Google Tag Manager triggers?

Yes, the variable can be used in both tags and triggers. This way you can fire or block tags based on the cookie value read.

Is the cookie name case-sensitive?

Yes, the cookie name is case-sensitive. You must therefore enter it exactly as it was set by the site.

Does the variable work in incognito mode?

In incognito mode, cookies are handled separately and often do not persist between sessions. As a result, the variable may not return the expected value or may return an empty value.

Facing this issue?Is the first-party cookie variable in GTM not configured correctly, so Google Ads conversions are not tracked?Without proper setup, you lose valuable conversion data and cannot optimize campaigns. With my service, I configure the first-party cookie variable in GTM for accurate tracking and advanced conversions.Discover the Conversion Tracking service