Add GA4 cookie detection

main
Elbert Alias 2 years ago
parent 26420341de
commit db33d9631a

@ -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) { } catch (error) {
error.message += ` (${url})` error.message += ` (${url})`
@ -1196,10 +1205,19 @@ class Site {
this.detections = this.detections this.detections = this.detections
.concat(detections) .concat(detections)
.filter( .filter(
({ technology: { name }, pattern: { regex } }, index, detections) => (
{ technology: { name }, pattern: { regex }, version },
index,
detections
) =>
detections.findIndex( detections.findIndex(
({ technology: { name: _name }, pattern: { regex: _regex } }) => ({
technology: { name: _name },
pattern: { regex: _regex },
version: _version,
}) =>
name === _name && name === _name &&
version === _version &&
(!regex || regex.toString() === _regex.toString()) (!regex || regex.toString() === _regex.toString())
) === index ) === index
) )

@ -498,6 +498,15 @@ const Driver = {
({ name, value }) => (items.cookies[name.toLowerCase()] = [value]) ({ 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) const technologies = getRequiredTechnologies(requires, categoryRequires)
await Driver.onDetect( await Driver.onDetect(
@ -568,10 +577,19 @@ const Driver = {
.concat(detections) .concat(detections)
.filter(({ technology }) => technology) .filter(({ technology }) => technology)
.filter( .filter(
({ technology: { name }, pattern: { regex } }, index, detections) => (
{ technology: { name }, pattern: { regex }, version },
index,
detections
) =>
detections.findIndex( detections.findIndex(
({ technology: { name: _name }, pattern: { regex: _regex } }) => ({
technology: { name: _name },
pattern: { regex: _regex },
version: _version,
}) =>
name === _name && name === _name &&
version === _version &&
(!regex || regex.toString() === _regex.toString()) (!regex || regex.toString() === _regex.toString())
) === index ) === index
) )

@ -1402,7 +1402,8 @@
"cookies": { "cookies": {
"__utma": "", "__utma": "",
"_ga": "", "_ga": "",
"_gat": "" "_ga_*": "\\;version:GA4",
"_gat": "\\;version:UA"
}, },
"description": "Google Analytics is a free web analytics service that tracks and reports website traffic.", "description": "Google Analytics is a free web analytics service that tracks and reports website traffic.",
"dom": "amp-analytics[type*=googleanalytics]", "dom": "amp-analytics[type*=googleanalytics]",