/
convert_down.go
179 lines (148 loc) · 4.51 KB
/
convert_down.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package openrtb_ext
func ConvertDownTo25(r *RequestWrapper) error {
// schain
if err := moveSupplyChainFrom26To25(r); err != nil {
return err
}
// gdpr
if err := moveGDPRFrom26To25(r); err != nil {
return err
}
if err := moveConsentFrom26To25(r); err != nil {
return err
}
// ccpa
if err := moveUSPrivacyFrom26To25(r); err != nil {
return err
}
// eid
if err := moveEIDFrom26To25(r); err != nil {
return err
}
// imp
for _, imp := range r.GetImp() {
if err := moveRewardedFrom26ToPrebidExt(imp); err != nil {
return err
}
}
// Do not remove new OpenRTB 2.6 fields. The spec specifies that bidders and exchanges
// must tolerate new or unexpected fields gracefully, either ignoring them or treating
// them as unknown.
return nil
}
// moveSupplyChainFrom26To25 modifies the request to move the OpenRTB 2.6 supply chain
// object (req.source.schain) to the OpenRTB 2.5 location (req.source.ext.schain). If the
// OpenRTB 2.5 location is already present it may be overwritten. The OpenRTB 2.5 location
// is expected to be empty.
func moveSupplyChainFrom26To25(r *RequestWrapper) error {
if r.Source == nil || r.Source.SChain == nil {
return nil
}
// read and clear 2.6 location
schain26 := r.Source.SChain
r.Source.SChain = nil
// move to 2.5 location
sourceExt, err := r.GetSourceExt()
if err != nil {
return err
}
sourceExt.SetSChain(schain26)
return nil
}
// moveGDPRFrom26To25 modifies the request to move the OpenRTB 2.6 GDPR signal
// field (req.regs.gdpr) to the OpenRTB 2.5 location (req.regs.ext.gdpr). If the
// OpenRTB 2.5 location is already present it may be overwritten. The OpenRTB 2.5
// location is expected to be empty.
func moveGDPRFrom26To25(r *RequestWrapper) error {
if r.Regs == nil || r.Regs.GDPR == nil {
return nil
}
// read and clear 2.6 location
gdpr26 := r.Regs.GDPR
r.Regs.GDPR = nil
// move to 2.5 location
regExt, err := r.GetRegExt()
if err != nil {
return err
}
regExt.SetGDPR(gdpr26)
return nil
}
// moveConsentFrom26To25 modifies the request to move the OpenRTB 2.6 GDPR consent
// field (req.user.consent) to the OpenRTB 2.5 location (req.user.ext.consent). If
// the OpenRTB 2.5 location is already present it may be overwritten. The OpenRTB 2.5
// location is expected to be empty.
func moveConsentFrom26To25(r *RequestWrapper) error {
if r.User == nil || len(r.User.Consent) == 0 {
return nil
}
// read and clear 2.6 location
consent26 := r.User.Consent
r.User.Consent = ""
// move to 2.5 location
userExt, err := r.GetUserExt()
if err != nil {
return err
}
userExt.SetConsent(&consent26)
return nil
}
// moveUSPrivacyFrom26To25 modifies the request to move the OpenRTB 2.6 US Privacy (CCPA)
// consent string (req.regs.us_privacy) to the OpenRTB 2.5 location (req.regs.ext.us_privacy).
// If the OpenRTB 2.5 location is already present it may be overwritten. The OpenRTB 2.5
// location is expected to be empty.
func moveUSPrivacyFrom26To25(r *RequestWrapper) error {
if r.Regs == nil || len(r.Regs.USPrivacy) == 0 {
return nil
}
// read and clear 2.6 location
usprivacy26 := r.Regs.USPrivacy
r.Regs.USPrivacy = ""
// move to 2.5 location
regExt, err := r.GetRegExt()
if err != nil {
return err
}
regExt.SetUSPrivacy(usprivacy26)
return nil
}
// moveEIDFrom26To25 modifies the request to move the OpenRTB 2.6 external identifiers
// (req.user.eids) to the OpenRTB 2.5 location (req.user.ext.eids). If the OpenRTB 2.5
// location is already present it may be overwritten. The OpenRTB 2.5 location is
// expected to be empty.
func moveEIDFrom26To25(r *RequestWrapper) error {
if r.User == nil || r.User.EIDs == nil {
return nil
}
// read and clear 2.6 location
eid26 := r.User.EIDs
r.User.EIDs = nil
// move to 2.5 location
userExt, err := r.GetUserExt()
if err != nil {
return err
}
userExt.SetEid(&eid26)
return nil
}
// moveRewardedFrom26ToPrebidExt modifies the impression to move the OpenRTB 2.6 rewarded
// signal (imp[].rwdd) to the OpenRTB 2.x Prebid specific location (imp[].ext.prebid.is_rewarded_inventory).
// If the Prebid specific location is already present, it may be overwritten. The Prebid specific
// location is expected to be empty.
func moveRewardedFrom26ToPrebidExt(i *ImpWrapper) error {
if i.Rwdd == 0 {
return nil
}
// read and clear 2.6 location
rwdd26 := i.Rwdd
i.Rwdd = 0
// move to Prebid specific location
impExt, err := i.GetImpExt()
if err != nil {
return err
}
impExtPrebid := impExt.GetOrCreatePrebid()
impExtPrebid.IsRewardedInventory = &rwdd26
impExt.SetPrebid(impExtPrebid)
return nil
}