Add default GCM consent type mappings
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>
This commit is contained in:
@@ -19,17 +19,18 @@ import "go.probo.inc/probo/pkg/coredata"
|
||||
var SupportedLanguages = []string{"en", "fr", "de", "es"}
|
||||
|
||||
var defaultCategories = []struct {
|
||||
Name string
|
||||
Slug string
|
||||
Description string
|
||||
Kind coredata.CookieCategoryKind
|
||||
Rank int
|
||||
Name string
|
||||
Slug string
|
||||
Description string
|
||||
Kind coredata.CookieCategoryKind
|
||||
Rank int
|
||||
GCMConsentTypes []string
|
||||
}{
|
||||
{"Necessary", "necessary", "Essential cookies required for the website to function properly.", coredata.CookieCategoryKindNecessary, 0},
|
||||
{"Analytics", "analytics", "Cookies that help understand how visitors interact with the website.", coredata.CookieCategoryKindNormal, 1},
|
||||
{"Advertising", "advertising", "Cookies used to deliver relevant advertisements and track campaigns.", coredata.CookieCategoryKindNormal, 2},
|
||||
{"Functional", "functional", "Cookies that enable enhanced functionality and personalization.", coredata.CookieCategoryKindNormal, 3},
|
||||
{"Uncategorised", "uncategorised", "Cookies that have not been assigned to a category yet.", coredata.CookieCategoryKindUncategorised, 4},
|
||||
{"Necessary", "necessary", "Essential cookies required for the website to function properly.", coredata.CookieCategoryKindNecessary, 0, []string{"security_storage"}},
|
||||
{"Analytics", "analytics", "Cookies that help understand how visitors interact with the website.", coredata.CookieCategoryKindNormal, 1, []string{"analytics_storage"}},
|
||||
{"Advertising", "advertising", "Cookies used to deliver relevant advertisements and track campaigns.", coredata.CookieCategoryKindNormal, 2, []string{"ad_storage", "ad_user_data", "ad_personalization"}},
|
||||
{"Functional", "functional", "Cookies that enable enhanced functionality and personalization.", coredata.CookieCategoryKindNormal, 3, []string{"functionality_storage", "personalization_storage"}},
|
||||
{"Uncategorised", "uncategorised", "Cookies that have not been assigned to a category yet.", coredata.CookieCategoryKindUncategorised, 4, nil},
|
||||
}
|
||||
|
||||
var defaultCategoryTranslationsByLanguage = map[string]map[string]struct {
|
||||
|
||||
@@ -73,6 +73,7 @@ type (
|
||||
Name *string
|
||||
Slug *string
|
||||
Description *string
|
||||
GCMConsentTypes *[]string
|
||||
}
|
||||
|
||||
CreateCookieRequest struct {
|
||||
@@ -557,17 +558,22 @@ func (s *Service) CreateCookieBanner(
|
||||
|
||||
slugToGID := make(map[string]gid.GID, len(defaultCategories))
|
||||
for _, dc := range defaultCategories {
|
||||
gcmConsentTypes := dc.GCMConsentTypes
|
||||
if gcmConsentTypes == nil {
|
||||
gcmConsentTypes = []string{}
|
||||
}
|
||||
category := &coredata.CookieCategory{
|
||||
ID: gid.New(scope.GetTenantID(), coredata.CookieCategoryEntityType),
|
||||
OrganizationID: banner.OrganizationID,
|
||||
CookieBannerID: banner.ID,
|
||||
Name: dc.Name,
|
||||
Slug: dc.Slug,
|
||||
Description: dc.Description,
|
||||
Kind: dc.Kind,
|
||||
Rank: dc.Rank,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
ID: gid.New(scope.GetTenantID(), coredata.CookieCategoryEntityType),
|
||||
OrganizationID: banner.OrganizationID,
|
||||
CookieBannerID: banner.ID,
|
||||
Name: dc.Name,
|
||||
Slug: dc.Slug,
|
||||
Description: dc.Description,
|
||||
Kind: dc.Kind,
|
||||
Rank: dc.Rank,
|
||||
GCMConsentTypes: gcmConsentTypes,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
if err := category.Insert(ctx, tx, scope); err != nil {
|
||||
@@ -974,16 +980,17 @@ func (s *Service) CreateCookieCategory(
|
||||
now := time.Now()
|
||||
|
||||
category = &coredata.CookieCategory{
|
||||
ID: gid.New(scope.GetTenantID(), coredata.CookieCategoryEntityType),
|
||||
OrganizationID: banner.OrganizationID,
|
||||
CookieBannerID: req.CookieBannerID,
|
||||
Name: req.Name,
|
||||
Slug: req.Slug,
|
||||
Description: req.Description,
|
||||
Kind: coredata.CookieCategoryKindNormal,
|
||||
Rank: req.Rank,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
ID: gid.New(scope.GetTenantID(), coredata.CookieCategoryEntityType),
|
||||
OrganizationID: banner.OrganizationID,
|
||||
CookieBannerID: req.CookieBannerID,
|
||||
Name: req.Name,
|
||||
Slug: req.Slug,
|
||||
Description: req.Description,
|
||||
Kind: coredata.CookieCategoryKindNormal,
|
||||
Rank: req.Rank,
|
||||
GCMConsentTypes: []string{},
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
if err := category.Insert(ctx, tx, scope); err != nil {
|
||||
@@ -1337,6 +1344,9 @@ func (s *Service) UpdateCookieCategory(
|
||||
if req.Description != nil {
|
||||
category.Description = *req.Description
|
||||
}
|
||||
if req.GCMConsentTypes != nil {
|
||||
category.GCMConsentTypes = *req.GCMConsentTypes
|
||||
}
|
||||
|
||||
category.UpdatedAt = time.Now()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user