This page describes how gtag.js uses Google Analytics cookies to measure user interactions on websites.
Overview
As a user navigates between web pages, you can use the gtag.js tagging library to record information about the page the user has seen (for example, the page's URL) in Google Analytics. The gtag.js tagging library uses HTTP Cookies to "remember" the user's previous interactions with the web pages.
Cookie usage
gtag.js uses the _ga
and _gid
cookies to distinguish unique users,
and uses the _gat
cookie to throttle the request rate:
Cookie name | Default expiration time | Can be set? | Description |
---|---|---|---|
_ga |
2 years | Yes | Used to distinguish users. |
_gid |
24 hours | No | Used to distinguish users. |
_gat |
1 minutes | No | Used to throttle request rate. If Google Analytics is deployed via Google
Tag Manager, this cookie will be named
_dc_gtm_<property-id> . |
AMP_TOKEN |
30 seconds to 1 year | No | Contains a token that can be used to retrieve a Client ID from AMP Client ID service. Other possible values indicate opt-out, inflight request or an error retrieving a Client ID from AMP Client ID service. |
_gac_<property-id> |
90 days | No | Contains campaign related information for the user. If you have linked your Google Analytics and AdWords accounts, AdWords website conversion tags will read this cookie unless you opt-out. Learn more. |
To overwrite the default expiration time of the _ga
cookie, provide a
different value for the cookie_expires
parameter in your config:
gtag('config', 'GA_TRACKING_ID', {
'cookie_expires': 31536000 // one year (in seconds)
});