GA cookies tracking
If this plugin is used, the tracker will look for Google Analytics cookies (Universal Analytics and GA4, specifically the __utma
, __utmb
, __utmc
, __utmv
, __utmz
, and _ga
cookies) and combine their values into event context entities that get sent with every event.
GA cookies information is automatically tracked once configured.
Install pluginβ
- JavaScript (tag)
- Browser (npm)
Tracker Distribution | Included |
---|---|
sp.js | β |
sp.lite.js | β |
Download:
Download from GitHub Releases (Recommended) | Github Releases (plugins.umd.zip) |
Available on jsDelivr | jsDelivr (latest) |
Available on unpkg | unpkg (latest) |
Note: The links to the CDNs above point to the current latest version. You should pin to a specific version when integrating this plugin on your website if you are using a third party CDN in production.
npm install @snowplow/browser-plugin-ga-cookies@3
yarn add @snowplow/browser-plugin-ga-cookies@3
pnpm add @snowplow/browser-plugin-ga-cookies@3
Initializationβ
pre-v3.17.0
- JavaScript (tag)
- Browser (npm)
window.snowplow('addPlugin',
"https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-ga-cookies@3/dist/index.umd.min.js",
["snowplowGaCookies", "GaCookiesPlugin"]
);
import { newTracker, trackPageView } from '@snowplow/browser-tracker';
import { GaCookiesPlugin } from '@snowplow/browser-plugin-ga-cookies';
newTracker('sp1', '{{collector_url}}', {
appId: 'my-app-id',
plugins: [ GaCookiesPlugin() ],
});
- JavaScript (tag)
- Browser (npm)
window.snowplow('addPlugin',
"https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-ga-cookies@3/dist/index.umd.min.js",
["snowplowGaCookies", "GaCookiesPlugin"],
[pluginOptions]
);
import { newTracker, trackPageView } from '@snowplow/browser-tracker';
import { GaCookiesPlugin } from '@snowplow/browser-plugin-ga-cookies';
newTracker('sp1', '{{collector_url}}', {
appId: 'my-app-id',
plugins: [ GaCookiesPlugin(pluginOptions) ],
});
The pluginOptions
parameter allows to configure the plugin. Its type is:
interface GACookiesPluginOptions {
ua?: boolean;
ga4?: boolean;
ga4MeasurementId?: string | string[];
cookiePrefix?: string | string[];
}
Name | Default | Description |
---|---|---|
ua | true | Send Universal Analytics specific cookie values. |
ga4 | false | Send Google Analytics 4 specific cookie values. |
ga4MeasurementId | "" | Measurement id(s) to search the Google Analytics 4 session cookie. Can be a single measurement id as a string or an array of measurement id strings. The cookie has the form of <cookie_prefix>_ga_<container-id> where <container-id> is the data stream container id and <cookie_prefix> is the optional cookie_prefix option of the gtag.js tracker. |
cookiePrefix | [] | Cookie prefix set on the Google Analytics 4 cookies using the cookie_prefix option of the gtag.js tracker. |
Context entitiesβ
pre-v3.17.0
Adding this plugin will automatically capture the following context:
Context iglu:com.google.analytics/cookies/jsonschema/1-0-0
Example
{
"_ga": "GA1.2.739498691.16151511088"
}
Adding this plugin will automatically capture the following contexts:
For Universal Analytics cookies:
iglu:com.google.analytics/cookies/jsonschema/1-0-0
, e.g.{
"_ga": "GA1.2.3.4"
}For GA4 cookies:
iglu:com.google.ga4/cookies/jsonschema/1-0-0
{
"_ga": "G-1234",
"cookie_prefix": "prefix",
"session_cookies": [
{
"measurement_id": "G-1234",
"session_cookie": "567"
}
]
}