Skip to content

Cookie banner integrations - GCM & posthog#1102

Merged
codenem merged 10 commits intomainfrom
cookie-banner-integrations
Apr 24, 2026
Merged

Cookie banner integrations - GCM & posthog#1102
codenem merged 10 commits intomainfrom
cookie-banner-integrations

Conversation

@codenem
Copy link
Copy Markdown
Contributor

@codenem codenem commented Apr 24, 2026

Closes ENG-287

Summary by cubic

Adds Google Consent Mode v2 and PostHog consent integrations to the cookie banner with UI controls, GraphQL fields, DB schema updates, and an SDK plugin system. Categories map to GCM signals and can control PostHog; defaults apply on load and updates propagate automatically (via gtag or window.dataLayer).

  • New Features

    • Google Consent Mode v2
      • Store mappings per category in gcm_consent_types; included in the published config, exposed via GraphQL; editable in the console with checkboxes and shown as badges.
      • Seed default mappings on banner creation (Analytics → analytics_storage, Advertising → ad_storage/ad_user_data/ad_personalization, Necessary → security_storage, Functional → functionality_storage/personalization_storage).
      • SDK sets defaults to denied and pushes updates via gtag('consent', ...) or window.dataLayer.
    • PostHog
      • posthog_consent per category with a partial unique index to allow only one per banner; enforced in the service and exposed via GraphQL; console toggle (NORMAL categories only).
      • Defaults to Analytics on banner creation; SDK opts out on load, then opts in/out based on consent.
    • SDK refactor
      • Introduced ConsentIntegration plugin API; default integrations: GCM and PostHog.
    • Minor improvements
      • Avoid duplicate detected cookies with InsertIfNotExists.
  • Migration

    • Run the new DB migrations.
    • Confirm category GCM mappings and which category controls PostHog (default: Analytics). Only one NORMAL category per banner can enable posthog_consent.

Written for commit e48da4d. Summary will update on new commits.

codenem added 9 commits April 24, 2026 17:13
Stores the Google Consent Mode v2 consent type mapping
per cookie category so each category can declare which
GCM signals it controls (e.g. analytics_storage,
ad_storage).

Signed-off-by: Émile Ré <emile@getprobo.com>
Include gcm_consent_types in the published banner config
so the cookie banner SDK can read category-to-GCM mappings
from the config endpoint.

Signed-off-by: Émile Ré <emile@getprobo.com>
Seed default categories with their Google Consent Mode v2
mappings (e.g. analytics -> analytics_storage, advertising
-> ad_storage + ad_user_data + ad_personalization). New
user-created categories default to an empty mapping.

Signed-off-by: Émile Ré <emile@getprobo.com>
Expose gcmConsentTypes on CookieCategory type and accept
it in UpdateCookieCategoryInput so the console can read
and write GCM consent type mappings per category.

Signed-off-by: Émile Ré <emile@getprobo.com>
Display Google Consent Mode mappings as badges on each
category and add a checkbox selector in the edit form
so users can configure which GCM signals each category
controls.

Signed-off-by: Émile Ré <emile@getprobo.com>
Set GCM defaults to denied on load, then push consent
updates via gtag('consent', 'update', ...) before
activating scripts. The mapping from category slugs to
GCM consent types comes from the banner config endpoint.

Signed-off-by: Émile Ré <emile@getprobo.com>
Add PostHog opt-in/opt-out consent support mirroring the existing Google
Consent Mode integration: database column, GraphQL field, console UI
toggle, and client-side posthog-js calls.

Extract both GCM and PostHog logic from CookieBannerClient into a
ConsentIntegration plugin interface so future integrations can be added
without modifying the client core.

Signed-off-by: Émile Ré <emile@getprobo.com>
Add a partial unique index ensuring only one category per banner can
have posthog_consent enabled. Default it to the analytics category on
banner creation, clear the previous mapping before setting a new one,
and restrict the toggle to NORMAL categories in both the service layer
and the console UI.

Signed-off-by: Émile Ré <emile@getprobo.com>
Fall back to pushing consent commands onto window.dataLayer when
window.gtag is not available, enabling compatibility with Google Tag
Manager setups that don't define a global gtag function.

Signed-off-by: Émile Ré <emile@getprobo.com>
@codenem codenem force-pushed the cookie-banner-integrations branch from cdc75a1 to 7a270f7 Compare April 24, 2026 13:13
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 19 files

Signed-off-by: Émile Ré <emile@getprobo.com>
@codenem codenem requested a review from a team April 24, 2026 13:17
@codenem codenem changed the title Cookie banner integrations Cookie banner integrations - GCM & posthog Apr 24, 2026
Copy link
Copy Markdown
Contributor

@SachaProbo SachaProbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add some e2e tests?

if errors.Is(err, coredata.ErrResourceAlreadyExists) {
continue
}
ok, err := cookie.InsertIfNotExists(ctx, tx, scope)
Copy link
Copy Markdown
Contributor

@SachaProbo SachaProbo Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ON CONFLICT clause to not rollback a transaction on the detect cookies endpoint of the REST API.
The usual insert stays there for feedback on conflict when adding cookies from the console

@codenem
Copy link
Copy Markdown
Contributor Author

codenem commented Apr 24, 2026

Maybe add some e2e tests?

Will do on next PR

@codenem codenem merged commit e48da4d into main Apr 24, 2026
18 checks passed
@codenem codenem deleted the cookie-banner-integrations branch April 24, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants