From db33d9631ab33f0a6228427b59e75c9354755b93 Mon Sep 17 00:00:00 2001 From: Elbert Alias <77259+AliasIO@users.noreply.github.com> Date: Sun, 6 Nov 2022 11:52:14 +1100 Subject: [PATCH] Add GA4 cookie detection --- src/drivers/npm/driver.js | 22 ++++++++++++++++++++-- src/drivers/webextension/js/driver.js | 22 ++++++++++++++++++++-- src/technologies/g.json | 5 +++-- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/drivers/npm/driver.js b/src/drivers/npm/driver.js index 6a2653e39..f6fe4650c 100644 --- a/src/drivers/npm/driver.js +++ b/src/drivers/npm/driver.js @@ -693,6 +693,15 @@ class Site { }), {} ) + + // Change Google Analytics 4 cookie from _ga_XXXXXXXXXX to _ga_* + Object.keys(cookies).forEach((name) => { + if (/_ga_[A-Z0-9]+/.test(name)) { + cookies['_ga_*'] = cookies[name] + + delete cookies[name] + } + }) } catch (error) { error.message += ` (${url})` @@ -1196,10 +1205,19 @@ class Site { this.detections = this.detections .concat(detections) .filter( - ({ technology: { name }, pattern: { regex } }, index, detections) => + ( + { technology: { name }, pattern: { regex }, version }, + index, + detections + ) => detections.findIndex( - ({ technology: { name: _name }, pattern: { regex: _regex } }) => + ({ + technology: { name: _name }, + pattern: { regex: _regex }, + version: _version, + }) => name === _name && + version === _version && (!regex || regex.toString() === _regex.toString()) ) === index ) diff --git a/src/drivers/webextension/js/driver.js b/src/drivers/webextension/js/driver.js index 017909260..e7499e7e1 100644 --- a/src/drivers/webextension/js/driver.js +++ b/src/drivers/webextension/js/driver.js @@ -498,6 +498,15 @@ const Driver = { ({ name, value }) => (items.cookies[name.toLowerCase()] = [value]) ) + // Change Google Analytics 4 cookie from _ga_XXXXXXXXXX to _ga_* + Object.keys(items.cookies).forEach((name) => { + if (/_ga_[A-Z0-9]+/.test(name)) { + items.cookies['_ga_*'] = items.cookies[name] + + delete items.cookies[name] + } + }) + const technologies = getRequiredTechnologies(requires, categoryRequires) await Driver.onDetect( @@ -568,10 +577,19 @@ const Driver = { .concat(detections) .filter(({ technology }) => technology) .filter( - ({ technology: { name }, pattern: { regex } }, index, detections) => + ( + { technology: { name }, pattern: { regex }, version }, + index, + detections + ) => detections.findIndex( - ({ technology: { name: _name }, pattern: { regex: _regex } }) => + ({ + technology: { name: _name }, + pattern: { regex: _regex }, + version: _version, + }) => name === _name && + version === _version && (!regex || regex.toString() === _regex.toString()) ) === index ) diff --git a/src/technologies/g.json b/src/technologies/g.json index 5a1e9b14d..9be4fe53f 100644 --- a/src/technologies/g.json +++ b/src/technologies/g.json @@ -1402,7 +1402,8 @@ "cookies": { "__utma": "", "_ga": "", - "_gat": "" + "_ga_*": "\\;version:GA4", + "_gat": "\\;version:UA" }, "description": "Google Analytics is a free web analytics service that tracks and reports website traffic.", "dom": "amp-analytics[type*=googleanalytics]", @@ -2306,4 +2307,4 @@ "implies": "Python", "website": "http://gunicorn.org" } -} \ No newline at end of file +}