From 7f1dffad80ef71b05e5751c82ce3e5d573709669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Fri, 24 Apr 2026 15:51:40 +0400 Subject: [PATCH] Add PostHog consent integration and extract integration plugin system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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é --- .../cookies/_components/CategorySection.tsx | 19 ++++- .../cookies/_components/EditCategoryForm.tsx | 24 +++++- packages/cookie-banner/src/client.ts | 63 +++------------- .../cookie-banner/src/integrations/gcm.ts | 73 +++++++++++++++++++ .../cookie-banner/src/integrations/index.ts | 28 +++++++ .../src/integrations/integration.ts | 23 ++++++ .../cookie-banner/src/integrations/posthog.ts | 69 ++++++++++++++++++ pkg/cookiebanner/service.go | 5 ++ pkg/coredata/cookie_banner_version.go | 1 + pkg/coredata/cookie_category.go | 10 +++ pkg/coredata/migrations/20260424T112802Z.sql | 16 ++++ .../api/console/v1/cookie_banner_resolvers.go | 1 + .../console/v1/graphql/cookie_banner.graphql | 2 + .../api/console/v1/types/cookie_category.go | 1 + 14 files changed, 281 insertions(+), 54 deletions(-) create mode 100644 packages/cookie-banner/src/integrations/gcm.ts create mode 100644 packages/cookie-banner/src/integrations/index.ts create mode 100644 packages/cookie-banner/src/integrations/integration.ts create mode 100644 packages/cookie-banner/src/integrations/posthog.ts create mode 100644 pkg/coredata/migrations/20260424T112802Z.sql diff --git a/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/CategorySection.tsx b/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/CategorySection.tsx index 90893b9ec..11f5b2f09 100644 --- a/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/CategorySection.tsx +++ b/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/CategorySection.tsx @@ -60,6 +60,7 @@ export const categorySectionFragment = graphql` description kind gcmConsentTypes + posthogConsent cookies(first: 100, orderBy: { field: CREATED_AT, direction: ASC }) @connection(key: "CategorySection_cookies", filters: []) @required(action: THROW) { @@ -99,6 +100,7 @@ const updateCategoryMutation = graphql` description rank gcmConsentTypes + posthogConsent updatedAt } cookieBanner { @@ -239,7 +241,10 @@ export function CategorySection({ categoryKey, onDelete }: CategorySectionProps) const cookies = category.cookies.edges.map(e => e.node); const isMutating = isUpdating || isCreating || isUpdatingCookie; - const handleSaveCategory = (name: string, slug: string, description: string, gcmConsentTypes: string[]) => { + const handleSaveCategory = ( + name: string, slug: string, description: string, + gcmConsentTypes: string[], posthogConsent: boolean, + ) => { updateCategory({ variables: { input: { @@ -248,6 +253,7 @@ export function CategorySection({ categoryKey, onDelete }: CategorySectionProps) slug, description, gcmConsentTypes, + posthogConsent, }, }, onCompleted(_response, errors) { @@ -485,6 +491,7 @@ export function CategorySection({ categoryKey, onDelete }: CategorySectionProps) slug={category.slug} description={category.description} gcmConsentTypes={[...category.gcmConsentTypes]} + posthogConsent={category.posthogConsent} isUpdating={isUpdating} onSave={handleSaveCategory} onCancel={() => setIsEditingCategory(false)} @@ -541,6 +548,16 @@ export function CategorySection({ categoryKey, onDelete }: CategorySectionProps) ))} )} + {category.posthogConsent && ( +
+ + {__("PostHog:")} + + + {__("Tracking consent")} + +
+ )} )} diff --git a/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/EditCategoryForm.tsx b/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/EditCategoryForm.tsx index 500b569fb..618c8866b 100644 --- a/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/EditCategoryForm.tsx +++ b/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/EditCategoryForm.tsx @@ -31,8 +31,9 @@ interface EditCategoryFormProps { slug: string; description: string; gcmConsentTypes: string[]; + posthogConsent: boolean; isUpdating: boolean; - onSave: (name: string, slug: string, description: string, gcmConsentTypes: string[]) => void; + onSave: (name: string, slug: string, description: string, gcmConsentTypes: string[], posthogConsent: boolean) => void; onCancel: () => void; } @@ -41,6 +42,7 @@ export function EditCategoryForm({ slug, description, gcmConsentTypes, + posthogConsent, isUpdating, onSave, onCancel, @@ -50,6 +52,7 @@ export function EditCategoryForm({ const [editSlug, setEditSlug] = useState(slug); const [editDescription, setEditDescription] = useState(description); const [editGcmTypes, setEditGcmTypes] = useState(gcmConsentTypes); + const [editPosthogConsent, setEditPosthogConsent] = useState(posthogConsent); const toggleGcmType = (type: string) => { setEditGcmTypes(prev => @@ -102,11 +105,28 @@ export function EditCategoryForm({ ))} +
+ +

+ {__("Control PostHog tracking consent based on this category.")} +

+ +