diff --git a/pkg/cookiebanner/defaults.go b/pkg/cookiebanner/defaults.go index 7891a1455..677a743b5 100644 --- a/pkg/cookiebanner/defaults.go +++ b/pkg/cookiebanner/defaults.go @@ -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 { diff --git a/pkg/cookiebanner/service.go b/pkg/cookiebanner/service.go index 2aa970083..bfba132df 100644 --- a/pkg/cookiebanner/service.go +++ b/pkg/cookiebanner/service.go @@ -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()