feat: add helper method

This commit is contained in:
Kevin Franklin Kim 2024-09-26 21:11:09 +02:00
parent 4ebeac6af7
commit 7468cd8508
No known key found for this signature in database

View File

@ -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
}