In order for Google Analytics to determine that two distinct hits belong to thesame user, a unique identifier, associated with that particular user, must besent with each hit.
The analytics.js library accomplishes this via theClient ID field, a unique, randomly generated string thatgets stored in the browsers cookies, so subsequent visits to the same site canbe associated with the same user.
By default, analytics.js uses a single, first-party cookie named
_ga
to store the Client ID, but the cookie's name, domain,and expiration time can all be customized. Other cookies created by analytics.jsinclude _gid
, AMP_TOKEN
and_gac_<property-id>
. These cookies store other randomlygenerated ids and campaign information about the user.Using cookies allows analytics.js to identify unique users across browsingsessions, but it cannot identify unique users across different browsers ordevices. If your site has its own authentication system, you can use theUser ID feature, in addition to the Client ID, to moreaccurately identify a user across all the devices they use to access your site.
Icon plus 1 3 download free. How to export Cookies. Multilogin browser profiles support only cookies in JSON or Netscape format. If you are planning to export cookies from your browser then you can use one of the following extensions: Firefox - Export Cookies by Rotem Dan (Netscape), Cookie-Editor by Moustachauve (JSON). Origin of the name. The term 'cookie' was coined by web-browser programmer Lou Montulli.It was derived from the term 'magic cookie', which is a packet of data a program receives and sends back unchanged, used by Unix programmers. The header fields are transmitted after the request line (in case of a request HTTP message) or the response line (in case of a response HTTP message), which is the first line of a message. The http.cookies module defines classes for abstracting the concept of cookies, an HTTP state management mechanism. It supports both simple string-only cookies, and provides an abstraction for having any serializable data-type as cookie value. The module formerly strictly applied the parsing rules described in the RFC 2109 and RFC 2068. Cookie Clicker is mainly supported by ads. Consider unblocking our site or checking out our Patreon!
This guide explains how to customize the cookie settings as well as how to setthe user ID field to more accurately measure user activity across sessions.
Note: you can refer to theCookie Usage guide for moreinformation on how analytics.js uses cookies. Configuring cookie field settings
The following table shows the default cookie field values used by analytics.js:
Field Name | Value Type | Default value |
---|---|---|
cookieName | text | _ga |
cookieDomain | text | The result of the following JavaScript expression:document.location.hostname |
cookieExpires | integer | 63072000 (two years, in seconds) |
cookieUpdate | boolean | true |
cookieFlags | text |
To modify any of these values, you can specify them in the
fieldObject
youpass the create
command. Forexample:The most common cookie field to set is
Caution: The cookieDomain
, as such, the create
command accepts the cookieDomain
field as an optional third parameter forconvenience:cookieDomain
must be an ancestor of the current domain, otherwisethe cookie will not get set. For example, if your domain isone.two.three.root.com
, you may configure the cookie to be set on root.com
,but not someotherdomain.com
. Setting an incorrect cookie domain will result inno hits being sent to Google Analytics.Automatic Cookie Domain Configuration
The recommended Google Analytics tag sets the string
'auto'
for thecookieDomain
field:Specifying
'auto'
as the cookieDomain
enables automatic cookie domainconfiguration, which tells analytics.js to automatically determine the bestcookie domain to use.Automatic cookie domain configuration sets the
When using automatic cookie domain configuration, useractivity will be measured across subdomains without any extra configuration._ga
cookie on the highest leveldomain it can. For example, if your website address is blog.example.co.uk
,analytics.js will set the cookie domain to .example.co.uk
. In addition, ifanalytics.js detects that you're running a server locally (e.g. localhost
) itautomatically sets the cookieDomain
to 'none'
.Cookie Expiration
Every time a hit is sent to Google Analytics, the cookie expiration time isupdated to be the current time plus the value of the
cookieExpires
field. Thismeans that if you use the default cookieExpires
time of two years, and a uservisits your site every month, their cookie will never expire.If you set the
Caution: If you set the cookie to expire too quickly, you will inflate your usercount and decrease the quality of your measurement.cookieExpires
time to 0
(zero) seconds, the cookie turns intoasession based cookieand expires once the current browser session ends:Cookie update
When
cookieUpdate
is set to true
(the default value), analytics.js willupdate cookies on each page load. This will update the cookie expiration to beset relative to the most recent visit to the site. For example, if cookieexpiration is set to one week, and a user visits using the same browser everyfive days, the cookie expiration will be updated on each visit and so willeffectively never expire.When set to
false
, cookies are not updated on each page load. This has theeffect of cookie expiration being relative to the first time a user visited thesite.Cookie flags
Appends additional flags to the cookie when set. Flags must be separated bysemicolons.
Caution: Setting samesite
to None
and omitting the Secure
flag or servingthe site via HTTP
, will negatively impact measurement.Getting the Client ID from the cookie
You should not directly access the cookie analytics.js sets, as the cookieformat might change in the future. Instead, developers should use the
readyCallback
to waituntil analytics.js is loaded, and then get the clientId
value stored on thetracker.Disabling Cookies
In some cases you might want to use your own storage mechanism (such as
localStorage
or aService Worker)to persist the Client ID across sessions without using cookies. You can disableanalytics.js from setting cookies by setting the storage
field to 'none'
.If you're storing the
clientId
field yourself, you'll need to make sure to setthe cliendId
field when you create the tracker.To disable the
_gac_<property-id>
cookies, set thestoreGac
field to false
in the create
command:Using localStorage to store the Client ID
The following code sample shows how you could modify the JavaScript tag to use
Caution: Unlike cookies, localStorage
to store the Client ID rather than cookies:localStorage
is bound by thesame-origin policy . Ifparts of your site are on different subdomains, or if some pages use http
andothers pages use https
, you cannot use localStorage
to measure user activitybetween those pages. For this reason, cookies continues to be the officiallyrecommended way to store the Client ID.User ID
User ID enables the analysis of groups of sessions, across devices, using aunique, persistent, and non-personally identifiable ID string representing auser. To learn why you should implement the User ID, seeBenefits of using the User ID feature.
To implement the User ID with analytics.js:
Web Cookies Format
- Provide your own unique, persistent, and non-personally identifiable stringID to represent each signed-in user. This ID is most often provided by anauthentication system.
- Set the User ID on the tracker:
Cookie File Format
Caution: TheUSER_ID
value should be a unique, persistent, and non-personallyidentifiable string identifier that represents a user or signed-in accountacross devices.Handling authentication after pageload
What Is A Cookie
When buildingSingle Page Applications or otherdynamic websites that handle user sign-in after the initial page load, theprocess of setting the user ID value on the tracker can't happen at creationtime.
In such cases, you can use the
set
command to set the value onthe tracker as soon as it's known.Cookie Format
When using this approach, hits sent before the
userId
field is set will notcontain user ID values. However, through a process known asSession Unification,Google Analytics is able to associate these hits with the correct user atprocessing time.