-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accommodate Apple iOS LMT bug (#1718)
- Loading branch information
1 parent
bc808a4
commit b74d7c0
Showing
9 changed files
with
785 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
endpoints/openrtb2/sample-requests/valid-whole/supplementary/app-ios140-no-ifa.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"description": "Well Formed iOS 14.0 App Request With Unspecified LMT + Empty IFA", | ||
"mockBidRequest": { | ||
"id": "some-request-id", | ||
"app": { | ||
"id": "some-app-id" | ||
}, | ||
"device": { | ||
"os": "iOS", | ||
"osv": "14.0", | ||
"ifa": "" | ||
}, | ||
"imp": [{ | ||
"id": "my-imp-id", | ||
"banner": { | ||
"format": [{ | ||
"w": 300, | ||
"h": 600 | ||
}] | ||
}, | ||
"ext": { | ||
"appnexus": { | ||
"placementId": 12883451 | ||
} | ||
} | ||
}] | ||
}, | ||
"expectedBidResponse": { | ||
"id": "some-request-id", | ||
"bidid": "test bid id", | ||
"nbr": 0 | ||
}, | ||
"expectedReturnCode": 200 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package lmt | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/mxmCherry/openrtb" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
"github.com/prebid/prebid-server/util/iosutil" | ||
) | ||
|
||
var ( | ||
int8Zero int8 = 0 | ||
int8One int8 = 1 | ||
) | ||
|
||
// ModifyForIOS modifies the request's LMT flag based on iOS version and identity. | ||
func ModifyForIOS(req *openrtb.BidRequest) { | ||
modifiers := map[iosutil.VersionClassification]modifier{ | ||
iosutil.Version140: modifyForIOS14X, | ||
iosutil.Version141: modifyForIOS14X, | ||
iosutil.Version142OrGreater: modifyForIOS142OrGreater, | ||
} | ||
modifyForIOS(req, modifiers) | ||
} | ||
|
||
func modifyForIOS(req *openrtb.BidRequest, modifiers map[iosutil.VersionClassification]modifier) { | ||
if !isRequestForIOS(req) { | ||
return | ||
} | ||
|
||
versionClassification := iosutil.DetectVersionClassification(req.Device.OSV) | ||
if modifier, ok := modifiers[versionClassification]; ok { | ||
modifier(req) | ||
} | ||
} | ||
|
||
func isRequestForIOS(req *openrtb.BidRequest) bool { | ||
return req != nil && req.App != nil && req.Device != nil && strings.EqualFold(req.Device.OS, "ios") | ||
} | ||
|
||
type modifier func(req *openrtb.BidRequest) | ||
|
||
func modifyForIOS14X(req *openrtb.BidRequest) { | ||
if req.Device.IFA == "" || req.Device.IFA == "00000000-0000-0000-0000-000000000000" { | ||
req.Device.Lmt = &int8One | ||
} else { | ||
req.Device.Lmt = &int8Zero | ||
} | ||
} | ||
|
||
func modifyForIOS142OrGreater(req *openrtb.BidRequest) { | ||
atts, err := openrtb_ext.ParseDeviceExtATTS(req.Device.Ext) | ||
if err != nil || atts == nil { | ||
return | ||
} | ||
|
||
switch *atts { | ||
case openrtb_ext.IOSAppTrackingStatusNotDetermined: | ||
req.Device.Lmt = &int8Zero | ||
case openrtb_ext.IOSAppTrackingStatusRestricted: | ||
req.Device.Lmt = &int8One | ||
case openrtb_ext.IOSAppTrackingStatusDenied: | ||
req.Device.Lmt = &int8One | ||
case openrtb_ext.IOSAppTrackingStatusAuthorized: | ||
req.Device.Lmt = &int8Zero | ||
} | ||
} |
Oops, something went wrong.