diff --git a/pkg/encoding/gtag/consent.go b/pkg/encoding/gtag/consent.go index 81a0cb4..c1ab4d8 100644 --- a/pkg/encoding/gtag/consent.go +++ b/pkg/encoding/gtag/consent.go @@ -1,5 +1,9 @@ package gtag +import ( + "strings" +) + type Consent struct { // Current Google Consent Status. Format 'G1'+'AdsStorageBoolStatus'`+'AnalyticsStorageBoolStatus' // Example: G101 @@ -14,3 +18,29 @@ type Consent struct { // Example: G111 GoogleConsentDefault *string `json:"google_consent_default,omitempty" gtag:"gcd,omitempty"` } + +// ------------------------------------------------------------------------------------------------ +// ~ Public methods +// ------------------------------------------------------------------------------------------------ + +func (c Consent) AdStorage() bool { + if c.GoogleConsentUpdate != nil { + gcs := *c.GoogleConsentUpdate + if strings.HasPrefix(gcs, "G1") && len(gcs) == 4 { + return gcs[2:3] == "1" + } + return false + } + return true +} + +func (c Consent) AnalyticsStorage() bool { + if c.GoogleConsentUpdate != nil { + gcs := *c.GoogleConsentUpdate + if strings.HasPrefix(gcs, "G1") && len(gcs) == 4 { + return gcs[3:4] == "1" + } + return false + } + return true +}