Google tags set and read cookies to identify unique users across browsing sessions. Cookies are small files saved on peoples' computers to help store preferences and other information that's used on web pages that they visit.
Google uses cookies in various ways. Remarketing and Google Analytics both use cookies to help do things like run your ads or measure your success. The conversion measurement features of Google Ads and Campaign Manager also use cookies. To help you measure sales and other conversions from your ad, a cookie is added to a person's computer when the person clicks an ad. Refer to the advertising and measurement cookie reference for a detailed list of cookies used by Google.
For most websites and apps, cookie storage should also be controlled by user consent. This page explains how to customize cookie settings with the Google tag and Google Tag Manager. Manage user privacy introduces the available options for managing user consent.
You can also manage cookie expiration and cookie update settings using the Analytics interface. To learn more, see Change default cookie settings.
Cookie domain configuration
By default, Google tags use automatic cookie domain configuration.
Cookies are set on the highest level of domain possible. For example, if your
website address is blog.example.com
, cookies are set on the example.com
domain. If it is detected that you're running a server locally (e.g.
localhost
), cookie_domain
is automatically set to 'none'
, and cookies will
use the full domain from the document location.
To make changes to the cookie domain configuration, follow these steps:
gtag.js
To turn off automatic cookie domain configuration, update the config
for
your tag to specify a value for the cookie_domain
parameter:
gtag('config', 'TAG_ID', {
'cookie_domain': 'blog.example.com'
});
Tag Manager
For Google Analytics tags:
- In Tag Manager, navigate to Fields to Set:
- For Google Analytics 4 Configuration tags, select Tag Configuration > Fields to Set.
- For Universal Analytics tags, use a Google Analytics settings variable and select Variable Configuration > More Settings > Fields to Set.
- When the Fields to Set section is expanded, click Add Row.
- For Field Name, enter the correct value:
- For Google Analytics 4 Configuration tags, enter
cookie_domain
. - For Universal Analytics Google Analytics settings variables, enter
cookieDomain
.
- For Google Analytics 4 Configuration tags, enter
- For Value, enter the domain value, e.g.
my.example.com
. - Save the tag and publish.
For Google Ads and Floodlight tags:
Domain settings can be modified from the Conversion Linker tag:
- In Tag Manager, open your existing Conversion Linker tag, or create one if the tag doesn't yet exist in your container.
- Under Linker Options, click Override cookie settings (advanced)
- In the Domain field, enter the highest level domain for which a cookie should be allowed to be set. You can also specify a specific path in the Path field. Only use these settings if you need to limit cookies to a lower-level subdomain or subdirectory.
Rename cookies
To avoid conflicts with other cookies, you may need to change the cookie name.
gtag.js
This configuration adds example
to the beginning of the cookie that it
sets (e.g. _ga
becomes example_ga
, or _gcl_au
becomes example_gcl_au
):
gtag('config', 'TAG_ID', {
cookie_prefix: 'example'
});
Tag Manager
For Google Analytics 4 Configuration tags:
- In Google Tag Manager, open a Google Analytics 4 Configuration tag and click Tag Configuration > Fields to Set.
- When the Fields to Set section is expanded, click Add Row.
- For Field Name, enter
cookie_prefix
. - For Value, enter the prefix value, e.g.
example
. - Save the tag and publish.
For Universal Analytics tags:
Universal Analytics tags in Tag Manager can replace the name of the
cookie with cookieName
via a Google Analytics settings variable.
- In Tag Manager, open a Google Analytics settings variable and select Variable Configuration > More Settings > Fields to Set.
- When the Fields to Set section is expanded, click Add Row.
- For Field Name, enter enter
cookieName
. - For Value, enter the name of the cookie, e.g.
myCookie
. - Save the tag and publish.
For Google Ads and Floodlight tags:
Name prefix settings can be modified from the Conversion Linker tag:
- In Tag Manager, open your existing Conversion Linker tag, or create one if the tag doesn't yet exist in your container.
- Under Linker Options, click Override cookie settings (advanced)
- In the Name prefix field, enter the desired name prefix. Any tags that use these cookies (e.g. Google Ads conversion tags) must also be configured to use the same prefix.
Cookie expiration
On each page load, the cookie expiration time is updated to be the current time
plus the cookie expiration value set by the Google tag. This means that if
cookie expiration is set to one week (604800
seconds), and a user
visits using the same browser within five days, the cookie will be available for
an additional week, and they will appear as the same visitor in your reports. If
that same user instead visited after the original cookie had expired, a new
cookie will be created, and their first and second visits will appear as coming
from distinct visitors in your reports.
If you set the cookie expiration value to 0
(zero) seconds, the cookie turns
into a session based cookie and expires once the current browser session ends.
gtag.js
gtag('config', 'TAG_ID', {
cookie_expires: 28 * 24 * 60 * 60 // 28 days, in seconds
});
Tag Manager
For Google Analytics tags:
- In Tag Manager, navigate to Fields to Set:
- For Google Analytics 4 Configuration tags, select Tag Configuration > Fields to Set.
- For Universal Analytics tags, use a Google Analytics settings variable and select Variable Configuration > More Settings > Fields to Set.
- When the Fields to Set section is expanded, click Add Row.
- For Field Name, enter the correct value:
- For Google Analytics 4 Configuration tags, enter
cookie_expires
. - For Universal Analytics Google Analytics settings variables, enter
cookieExpires
.
- For Google Analytics 4 Configuration tags, enter
- For Value, enter the number of seconds before the cookie will expire,
e.g. for 28 days, enter
2419200
. - Save the tag and publish.
Cookie update
When the cookie_update
flag is set to true
(the default value), Google tags
may update cookies on each page load, and may update the cookie expiration to
be set relative to the most recent visit to the site. For example, if cookie
expiration is set to one week, and a user visits using the same browser every
five days, the cookie expiration will be updated on each visit and so will
effectively never expire.
When set to false
, cookies are not updated on each page load. This has the
effect of cookie expiration being relative to the first time a user visited the
site.
gtag.js
gtag('config', 'TAG_ID', {
cookie_update: false
});
Tag Manager
For Google Analytics tags:
- In Tag Manager, navigate to Fields to Set:
- For Google Analytics 4 Configuration tags, select Tag Configuration > Fields to Set.
- For Universal Analytics tags, use a Google Analytics settings variable and select Variable Configuration > More Settings > Fields to Set.
- When the Fields to Set section is expanded, click Add Row.
- For Field Name, enter the correct value:
- For Google Analytics 4 Configuration tags, enter
cookie_update
. - For Universal Analytics Google Analytics settings variables, enter
cookieUpdate
.
- For Google Analytics 4 Configuration tags, enter
- For Value, enter a boolean value, e.g.
false
. - Save the tag and publish.