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:
@@ -74,6 +74,7 @@ type (
|
||||
Slug *string
|
||||
Description *string
|
||||
GCMConsentTypes *[]string
|
||||
PostHogConsent *bool
|
||||
}
|
||||
|
||||
CreateCookieRequest struct {
|
||||
@@ -360,6 +361,7 @@ func buildSnapshot(
|
||||
Kind: c.Kind,
|
||||
Cookies: cookies,
|
||||
GCMConsentTypes: gcmConsentTypes,
|
||||
PostHogConsent: c.PostHogConsent,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1347,6 +1349,9 @@ func (s *Service) UpdateCookieCategory(
|
||||
if req.GCMConsentTypes != nil {
|
||||
category.GCMConsentTypes = *req.GCMConsentTypes
|
||||
}
|
||||
if req.PostHogConsent != nil {
|
||||
category.PostHogConsent = *req.PostHogConsent
|
||||
}
|
||||
|
||||
category.UpdatedAt = time.Now()
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
16
pkg/coredata/migrations/20260424T112802Z.sql
Normal file
16
pkg/coredata/migrations/20260424T112802Z.sql
Normal 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;
|
||||
@@ -472,6 +472,7 @@ func (r *mutationResolver) UpdateCookieCategory(ctx context.Context, input types
|
||||
Slug: input.Slug,
|
||||
Description: input.Description,
|
||||
GCMConsentTypes: gcmConsentTypes,
|
||||
PostHogConsent: input.PosthogConsent,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -124,6 +124,7 @@ type CookieCategory implements Node {
|
||||
kind: CookieCategoryKind!
|
||||
rank: Int!
|
||||
gcmConsentTypes: [String!]!
|
||||
posthogConsent: Boolean!
|
||||
|
||||
cookies(
|
||||
first: Int
|
||||
@@ -310,6 +311,7 @@ input UpdateCookieCategoryInput {
|
||||
slug: String
|
||||
description: String
|
||||
gcmConsentTypes: [String!]
|
||||
posthogConsent: Boolean
|
||||
}
|
||||
|
||||
input DeleteCookieCategoryInput {
|
||||
|
||||
@@ -76,6 +76,7 @@ func NewCookieCategory(c *coredata.CookieCategory) *CookieCategory {
|
||||
Kind: c.Kind,
|
||||
Rank: c.Rank,
|
||||
GcmConsentTypes: gcmConsentTypes,
|
||||
PosthogConsent: c.PostHogConsent,
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user