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:
@@ -24,12 +24,13 @@ var defaultCategories = []struct {
|
|||||||
Description string
|
Description string
|
||||||
Kind coredata.CookieCategoryKind
|
Kind coredata.CookieCategoryKind
|
||||||
Rank int
|
Rank int
|
||||||
|
GCMConsentTypes []string
|
||||||
}{
|
}{
|
||||||
{"Necessary", "necessary", "Essential cookies required for the website to function properly.", coredata.CookieCategoryKindNecessary, 0},
|
{"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},
|
{"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},
|
{"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},
|
{"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},
|
{"Uncategorised", "uncategorised", "Cookies that have not been assigned to a category yet.", coredata.CookieCategoryKindUncategorised, 4, nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultCategoryTranslationsByLanguage = map[string]map[string]struct {
|
var defaultCategoryTranslationsByLanguage = map[string]map[string]struct {
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ type (
|
|||||||
Name *string
|
Name *string
|
||||||
Slug *string
|
Slug *string
|
||||||
Description *string
|
Description *string
|
||||||
|
GCMConsentTypes *[]string
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateCookieRequest struct {
|
CreateCookieRequest struct {
|
||||||
@@ -557,6 +558,10 @@ func (s *Service) CreateCookieBanner(
|
|||||||
|
|
||||||
slugToGID := make(map[string]gid.GID, len(defaultCategories))
|
slugToGID := make(map[string]gid.GID, len(defaultCategories))
|
||||||
for _, dc := range defaultCategories {
|
for _, dc := range defaultCategories {
|
||||||
|
gcmConsentTypes := dc.GCMConsentTypes
|
||||||
|
if gcmConsentTypes == nil {
|
||||||
|
gcmConsentTypes = []string{}
|
||||||
|
}
|
||||||
category := &coredata.CookieCategory{
|
category := &coredata.CookieCategory{
|
||||||
ID: gid.New(scope.GetTenantID(), coredata.CookieCategoryEntityType),
|
ID: gid.New(scope.GetTenantID(), coredata.CookieCategoryEntityType),
|
||||||
OrganizationID: banner.OrganizationID,
|
OrganizationID: banner.OrganizationID,
|
||||||
@@ -566,6 +571,7 @@ func (s *Service) CreateCookieBanner(
|
|||||||
Description: dc.Description,
|
Description: dc.Description,
|
||||||
Kind: dc.Kind,
|
Kind: dc.Kind,
|
||||||
Rank: dc.Rank,
|
Rank: dc.Rank,
|
||||||
|
GCMConsentTypes: gcmConsentTypes,
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
@@ -982,6 +988,7 @@ func (s *Service) CreateCookieCategory(
|
|||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Kind: coredata.CookieCategoryKindNormal,
|
Kind: coredata.CookieCategoryKindNormal,
|
||||||
Rank: req.Rank,
|
Rank: req.Rank,
|
||||||
|
GCMConsentTypes: []string{},
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
@@ -1337,6 +1344,9 @@ func (s *Service) UpdateCookieCategory(
|
|||||||
if req.Description != nil {
|
if req.Description != nil {
|
||||||
category.Description = *req.Description
|
category.Description = *req.Description
|
||||||
}
|
}
|
||||||
|
if req.GCMConsentTypes != nil {
|
||||||
|
category.GCMConsentTypes = *req.GCMConsentTypes
|
||||||
|
}
|
||||||
|
|
||||||
category.UpdatedAt = time.Now()
|
category.UpdatedAt = time.Now()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user