-
Notifications
You must be signed in to change notification settings - Fork 701
/
policy.go
33 lines (27 loc) · 931 Bytes
/
policy.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
package lmt
import "github.com/prebid/openrtb/v19/openrtb2"
const (
trackingUnrestricted = 0
trackingRestricted = 1
)
// Policy represents the LMT (Limit Ad Tracking) policy for an OpenRTB bid request.
type Policy struct {
Signal int
SignalProvided bool
}
// ReadFromRequest extracts the LMT (Limit Ad Tracking) policy from an OpenRTB bid request.
func ReadFromRequest(req *openrtb2.BidRequest) (policy Policy) {
if req != nil && req.Device != nil && req.Device.Lmt != nil {
policy.Signal = int(*req.Device.Lmt)
policy.SignalProvided = true
}
return
}
// CanEnforce returns true the LMT (Limit Ad Tracking) signal is provided by the publisher.
func (p Policy) CanEnforce() bool {
return p.SignalProvided
}
// ShouldEnforce returns true when the LMT (Limit Ad Tracking) policy is in effect.
func (p Policy) ShouldEnforce(bidder string) bool {
return p.SignalProvided && p.Signal == trackingRestricted
}