github.com/prebid/prebid-server/v2@v2.18.0/privacy/lmt/ios.go (about) 1 package lmt 2 3 import ( 4 "strings" 5 6 "github.com/prebid/openrtb/v20/openrtb2" 7 "github.com/prebid/prebid-server/v2/openrtb_ext" 8 "github.com/prebid/prebid-server/v2/util/iosutil" 9 ) 10 11 var ( 12 int8Zero int8 = 0 13 int8One int8 = 1 14 ) 15 16 // ModifyForIOS modifies the request's LMT flag based on iOS version and identity. 17 func ModifyForIOS(req *openrtb2.BidRequest) { 18 modifiers := map[iosutil.VersionClassification]modifier{ 19 iosutil.Version140: modifyForIOS14X, 20 iosutil.Version141: modifyForIOS14X, 21 iosutil.Version142OrGreater: modifyForIOS142OrGreater, 22 } 23 modifyForIOS(req, modifiers) 24 } 25 26 func modifyForIOS(req *openrtb2.BidRequest, modifiers map[iosutil.VersionClassification]modifier) { 27 if !isRequestForIOS(req) { 28 return 29 } 30 31 versionClassification := iosutil.DetectVersionClassification(req.Device.OSV) 32 if modifier, ok := modifiers[versionClassification]; ok { 33 modifier(req) 34 } 35 } 36 37 func isRequestForIOS(req *openrtb2.BidRequest) bool { 38 return req != nil && req.App != nil && req.Device != nil && strings.EqualFold(req.Device.OS, "ios") 39 } 40 41 type modifier func(req *openrtb2.BidRequest) 42 43 func modifyForIOS14X(req *openrtb2.BidRequest) { 44 if req.Device.IFA == "" || req.Device.IFA == "00000000-0000-0000-0000-000000000000" { 45 req.Device.Lmt = &int8One 46 } else { 47 req.Device.Lmt = &int8Zero 48 } 49 } 50 51 func modifyForIOS142OrGreater(req *openrtb2.BidRequest) { 52 atts, err := openrtb_ext.ParseDeviceExtATTS(req.Device.Ext) 53 if err != nil || atts == nil { 54 return 55 } 56 57 switch *atts { 58 case openrtb_ext.IOSAppTrackingStatusNotDetermined: 59 req.Device.Lmt = &int8One 60 case openrtb_ext.IOSAppTrackingStatusRestricted: 61 req.Device.Lmt = &int8One 62 case openrtb_ext.IOSAppTrackingStatusDenied: 63 req.Device.Lmt = &int8One 64 case openrtb_ext.IOSAppTrackingStatusAuthorized: 65 req.Device.Lmt = &int8Zero 66 } 67 }