Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend): deny Google Consent Mode everywhere until Cookiebot's answer (hotfix) (#15096)

Krzysztof Czerwinski36756c8b656c
diff --git a/autogpt_platform/frontend/src/services/analytics/consent-mode.test.ts b/autogpt_platform/frontend/src/services/analytics/consent-mode.test.ts
index b71f7a9992..dc79ece533 100644
--- a/autogpt_platform/frontend/src/services/analytics/consent-mode.test.ts
+++ b/autogpt_platform/frontend/src/services/analytics/consent-mode.test.ts
@@ -7,7 +7,6 @@ import {
} from "@/tests/integrations/cookiebot";
import {
buildConsentDefaultsScript,
- CONSENT_DENIED_BY_DEFAULT_REGIONS,
followConsentForGoogleTag,
} from "./consent-mode";
@@ -46,41 +45,31 @@ function runDefaultsScript(): unknown[][] {
);
}
+const ALL_DENIED = {
+ ad_storage: "denied",
+ ad_user_data: "denied",
+ ad_personalization: "denied",
+ analytics_storage: "denied",
+ wait_for_update: 500,
+};
+
describe("buildConsentDefaultsScript", () => {
afterEach(() => {
delete (window as DataLayerWindow).dataLayer;
delete window.gtag;
});
- it("grants by default, denies in the EEA, UK and Switzerland, and passes click IDs through URLs", () => {
+ it("denies every signal for every visitor and passes click IDs through URLs", () => {
expect(runDefaultsScript()).toEqual([
- [
- "consent",
- "default",
- {
- ad_storage: "granted",
- ad_user_data: "granted",
- ad_personalization: "granted",
- analytics_storage: "granted",
- },
- ],
- [
- "consent",
- "default",
- {
- ad_storage: "denied",
- ad_user_data: "denied",
- ad_personalization: "denied",
- analytics_storage: "denied",
- region: CONSENT_DENIED_BY_DEFAULT_REGIONS,
- wait_for_update: 500,
- },
- ],
+ ["consent", "default", ALL_DENIED],
["set", "url_passthrough", true],
]);
- expect(CONSENT_DENIED_BY_DEFAULT_REGIONS).toEqual(
- expect.arrayContaining(["DE", "FR", "ES", "GB", "CH", "NO", "IS", "LI"]),
- );
+ });
+
+ it("sets no region-specific default", () => {
+ // The vendored gtag.js resolves every visitor to the location baked into
+ // it, so a region-specific default would apply to everyone.
+ expect(buildConsentDefaultsScript()).not.toContain("region");
});
it("only sets defaults; updates come from the visitor's answer", () => {
@@ -124,7 +113,46 @@ describe("followConsentForGoogleTag", () => {
unfollow();
});
- it("leaves the region defaults alone until the visitor answers", () => {
+ it("grants consent once the visitor allows it", () => {
+ runDefaultsScript();
+ configureCookiebot();
+ installCookiebot();
+
+ const unfollow = followConsentForGoogleTag();
+ expect(consentUpdates()).toEqual([]);
+
+ answerCookiebot({ statistics: true, marketing: true });
+
+ expect(dataLayerEntries()).toEqual([
+ ["consent", "default", ALL_DENIED],
+ ["set", "url_passthrough", true],
+ [
+ "consent",
+ "update",
+ {
+ analytics_storage: "granted",
+ ad_storage: "granted",
+ ad_user_data: "granted",
+ ad_personalization: "granted",
+ },
+ ],
+ ]);
+ unfollow();
+ });
+
+ it("keeps every signal denied when the visitor declines", () => {
+ runDefaultsScript();
+ configureCookiebot();
+ installCookiebot();
+
+ const unfollow = followConsentForGoogleTag();
+ answerCookiebot({});
+
+ expect(consentUpdates()).toEqual([update(false, false)]);
+ unfollow();
+ });
+
+ it("leaves the denied defaults alone until the visitor answers", () => {
configureCookiebot();
installCookiebot();
diff --git a/autogpt_platform/frontend/src/services/analytics/consent-mode.ts b/autogpt_platform/frontend/src/services/analytics/consent-mode.ts
index b0376ff9cc..0bed4d64d9 100644
--- a/autogpt_platform/frontend/src/services/analytics/consent-mode.ts
+++ b/autogpt_platform/frontend/src/services/analytics/consent-mode.ts
@@ -7,74 +7,29 @@ import {
} from "@/services/consent/consent";
import { DATA_LAYER_NAME } from "./gtag";
-const EU_MEMBER_STATES = [
- "AT",
- "BE",
- "BG",
- "HR",
- "CY",
- "CZ",
- "DK",
- "EE",
- "FI",
- "FR",
- "DE",
- "GR",
- "HU",
- "IE",
- "IT",
- "LV",
- "LT",
- "LU",
- "MT",
- "NL",
- "PL",
- "PT",
- "RO",
- "SK",
- "SI",
- "ES",
- "SE",
-];
-
-// EEA (EU + IS, LI, NO), the UK and Switzerland start with every Google
-// signal denied until the visitor answers the banner; everywhere else the tag
-// runs with consent granted by default. Mirrored on agpt.co so a click ID
-// collected there is handled the same way here.
-export const CONSENT_DENIED_BY_DEFAULT_REGIONS = [
- ...EU_MEMBER_STATES,
- "IS",
- "LI",
- "NO",
- "GB",
- "CH",
-];
-
// How long the tag holds its first hit for the banner's stored answer, so a
// returning visitor's first page view already carries it.
const WAIT_FOR_UPDATE_MS = 500;
// Consent Mode v2 defaults, rendered as a beforeInteractive script ahead of
-// Cookiebot and the Google tag. The updates come from followConsentForGoogleTag
-// below. The shim stays local so it doesn't define window.gtag: that global is
-// how the rest of the app knows the tag itself loaded.
+// Cookiebot and the Google tag. Every signal starts denied for every visitor
+// until Cookiebot has their answer; the updates come from
+// followConsentForGoogleTag below. There is deliberately no `region` split:
+// the vendored public/gtag.js has the location of the machine that downloaded
+// it baked in and uses that instead of looking the visitor up, so every
+// visitor would match the same region. The shim stays local so it doesn't
+// define window.gtag: that global is how the rest of the app knows the tag
+// itself loaded.
export function buildConsentDefaultsScript(): string {
return [
`window['${DATA_LAYER_NAME}'] = window['${DATA_LAYER_NAME}'] || [];`,
`(function(){`,
`function gtag(){window['${DATA_LAYER_NAME}'].push(arguments);}`,
- `gtag('consent','default',${JSON.stringify({
- ad_storage: "granted",
- ad_user_data: "granted",
- ad_personalization: "granted",
- analytics_storage: "granted",
- })});`,
`gtag('consent','default',${JSON.stringify({
ad_storage: "denied",
ad_user_data: "denied",
ad_personalization: "denied",
analytics_storage: "denied",
- region: CONSENT_DENIED_BY_DEFAULT_REGIONS,
wait_for_update: WAIT_FOR_UPDATE_MS,
})});`,
// Carries the ad click ID across pages in the URL while cookies are denied.
@@ -103,7 +58,7 @@ export function buildConsentUpdate(consent: ConsentState) {
* Sends the visitor's answer to the Google tag as a Consent Mode update, now
* and whenever it changes. Cookiebot's own Consent Mode integration sends the
* same signals; this keeps a denial reaching the tag even if that integration
- * is switched off in the Cookiebot admin. Until there is an answer the region
+ * is switched off in the Cookiebot admin. Until there is an answer the denied
* defaults stand; an answer Cookiebot later withdraws is sent as a denial.
* Returns the unsubscribe.
*/
diff --git a/autogpt_platform/frontend/src/services/analytics/google-ads.test.ts b/autogpt_platform/frontend/src/services/analytics/google-ads.test.ts
index d51423986b..b3fe02be37 100644
--- a/autogpt_platform/frontend/src/services/analytics/google-ads.test.ts
+++ b/autogpt_platform/frontend/src/services/analytics/google-ads.test.ts
@@ -65,8 +65,8 @@ describe("trackAdsConversion", () => {
});
it("withholds the identifiers until the banner is answered", () => {
- // Unanswered: Consent Mode denies ad_user_data in the EEA/UK/CH and the
- // browser can't tell which region it's in, so nothing identifying goes out.
+ // Unanswered: Consent Mode denies ad_user_data for every visitor until
+ // the banner is answered, so nothing identifying goes out.
removeCookiebot();
installCookiebot();
diff --git a/autogpt_platform/frontend/src/services/analytics/google-ads.ts b/autogpt_platform/frontend/src/services/analytics/google-ads.ts
index e550fea701..4cac4ad7c1 100644
--- a/autogpt_platform/frontend/src/services/analytics/google-ads.ts
+++ b/autogpt_platform/frontend/src/services/analytics/google-ads.ts
@@ -52,13 +52,11 @@ export function trackAdsConversion(
return gtag("event", "conversion", params);
}
-// An unanswered banner is not a yes. Outside the EEA/UK/CH the Consent Mode
-// default is `granted`, but that gate lives in the tag's `region` parameter and
-// Google resolves it by IP. So treating "no answer" as consent would hand
-// Google an email it was told to redact for every unanswered visitor in a
-// denied-by-default region, which is the vendor dependency this gate exists to
-// remove. Cookiebot's own answer (including "no consent required here") is
-// what counts.
+// An unanswered banner is not a yes. Consent Mode starts every visitor with
+// ad_user_data denied, so treating "no answer" as consent would hand Google an
+// email it was told to redact and leave the redaction up to the vendor, which
+// is the dependency this gate exists to remove. Cookiebot's own answer
+// (including "no consent required here") is what counts.
function mayReportIdentifiers(): boolean {
return hasConsentFor("advertising");
}