Add PostHog consent integration and extract integration plugin system

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>
This commit is contained in:
Émile Ré
2026-04-24 15:51:40 +04:00
parent c6f548b8ff
commit 7f1dffad80
14 changed files with 281 additions and 54 deletions

View File

@@ -55,6 +55,7 @@ type (
Kind CookieCategoryKind `json:"kind"`
Cookies CookieItems `json:"cookies"`
GCMConsentTypes []string `json:"gcm_consent_types"`
PostHogConsent bool `json:"posthog_consent"`
}
CookieBannerVersion struct {

View File

@@ -48,6 +48,7 @@ type (
Kind CookieCategoryKind `db:"kind"`
Rank int `db:"rank"`
GCMConsentTypes []string `db:"gcm_consent_types"`
PostHogConsent bool `db:"posthog_consent"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
@@ -111,6 +112,7 @@ SELECT
kind,
rank,
gcm_consent_types,
posthog_consent,
created_at,
updated_at
FROM
@@ -162,6 +164,7 @@ SELECT
kind,
rank,
gcm_consent_types,
posthog_consent,
created_at,
updated_at
FROM
@@ -241,6 +244,7 @@ SELECT
kind,
rank,
gcm_consent_types,
posthog_consent,
created_at,
updated_at
FROM
@@ -289,6 +293,7 @@ INSERT INTO cookie_categories (
kind,
rank,
gcm_consent_types,
posthog_consent,
created_at,
updated_at
) VALUES (
@@ -302,6 +307,7 @@ INSERT INTO cookie_categories (
@kind,
@rank,
@gcm_consent_types,
@posthog_consent,
@created_at,
@updated_at
)
@@ -318,6 +324,7 @@ INSERT INTO cookie_categories (
"kind": c.Kind,
"rank": c.Rank,
"gcm_consent_types": c.GCMConsentTypes,
"posthog_consent": c.PostHogConsent,
"created_at": c.CreatedAt,
"updated_at": c.UpdatedAt,
}
@@ -347,6 +354,7 @@ SET
slug = @slug,
description = @description,
gcm_consent_types = @gcm_consent_types,
posthog_consent = @posthog_consent,
updated_at = @updated_at
WHERE
%s
@@ -361,6 +369,7 @@ WHERE
"slug": c.Slug,
"description": c.Description,
"gcm_consent_types": c.GCMConsentTypes,
"posthog_consent": c.PostHogConsent,
"updated_at": c.UpdatedAt,
}
maps.Copy(args, scope.SQLArguments())
@@ -477,6 +486,7 @@ SELECT
kind,
rank,
gcm_consent_types,
posthog_consent,
created_at,
updated_at
FROM

View File

@@ -0,0 +1,16 @@
-- Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-- PERFORMANCE OF THIS SOFTWARE.
ALTER TABLE cookie_categories ADD COLUMN posthog_consent BOOLEAN NOT NULL DEFAULT false;
ALTER TABLE cookie_categories ALTER COLUMN posthog_consent DROP DEFAULT;