forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syncer.go
68 lines (57 loc) · 1.63 KB
/
syncer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package adapters
import (
"text/template"
"github.com/prebid/prebid-server/macros"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/privacy"
"github.com/prebid/prebid-server/usersync"
)
func GDPRAwareSyncerIDs(syncers map[openrtb_ext.BidderName]usersync.Usersyncer) map[openrtb_ext.BidderName]uint16 {
gdprAwareSyncers := make(map[openrtb_ext.BidderName]uint16, len(syncers))
for bidderName, syncer := range syncers {
if syncer.GDPRVendorID() != 0 {
gdprAwareSyncers[bidderName] = syncer.GDPRVendorID()
}
}
return gdprAwareSyncers
}
type Syncer struct {
familyName string
gdprVendorID uint16
urlTemplate *template.Template
syncType SyncType
}
func NewSyncer(familyName string, vendorID uint16, urlTemplate *template.Template, syncType SyncType) *Syncer {
return &Syncer{
familyName: familyName,
gdprVendorID: vendorID,
urlTemplate: urlTemplate,
syncType: syncType,
}
}
type SyncType string
const (
SyncTypeRedirect SyncType = "redirect"
SyncTypeIframe SyncType = "iframe"
)
func (s *Syncer) GetUsersyncInfo(privacyPolicies privacy.Policies) (*usersync.UsersyncInfo, error) {
syncURL, err := macros.ResolveMacros(*s.urlTemplate, macros.UserSyncTemplateParams{
GDPR: privacyPolicies.GDPR.Signal,
GDPRConsent: privacyPolicies.GDPR.Consent,
USPrivacy: privacyPolicies.CCPA.Value,
})
if err != nil {
return nil, err
}
return &usersync.UsersyncInfo{
URL: syncURL,
Type: string(s.syncType),
SupportCORS: false,
}, err
}
func (s *Syncer) FamilyName() string {
return s.familyName
}
func (s *Syncer) GDPRVendorID() uint16 {
return s.gdprVendorID
}