mirror of
https://github.com/foomo/sesamy-go.git
synced 2025-10-16 12:35:43 +00:00
feat: add helper method
This commit is contained in:
parent
4ebeac6af7
commit
7468cd8508
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user