Skip to content

Commit

Permalink
Merge pull request #917 from PubMatic-OpenWrap/master_cherrypick_2409…
Browse files Browse the repository at this point in the history
…2024

OpenWrap Release 24th Sept 2024
  • Loading branch information
ShriprasadM authored Sep 23, 2024
2 parents 7bddc97 + 9579be3 commit 0d8fef1
Show file tree
Hide file tree
Showing 7 changed files with 437 additions and 10 deletions.
7 changes: 6 additions & 1 deletion modules/pubmatic/openwrap/applovinmax.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func updateDevice(signalDevice *openrtb2.Device, maxRequest *openrtb2.BidRequest
maxRequest.Device.ConnectionType = signalDevice.ConnectionType
}

if signalDevice.Model != "" {
maxRequest.Device.Model = signalDevice.Model
}

maxRequest.Device.Ext = setIfKeysExists(signalDevice.Ext, maxRequest.Device.Ext, "atts")

if signalDevice.Geo == nil {
Expand Down Expand Up @@ -130,6 +134,7 @@ func updateApp(signalApp *openrtb2.App, maxRequest *openrtb2.BidRequest) {
if signalApp.Domain != "" {
maxRequest.App.Domain = signalApp.Domain
}
maxRequest.App.StoreURL = signalApp.StoreURL
}

func updateRegs(signalRegs *openrtb2.Regs, maxRequest *openrtb2.BidRequest) {
Expand All @@ -144,7 +149,7 @@ func updateRegs(signalRegs *openrtb2.Regs, maxRequest *openrtb2.BidRequest) {
if signalRegs.COPPA != 0 {
maxRequest.Regs.COPPA = signalRegs.COPPA
}
maxRequest.Regs.Ext = setIfKeysExists(signalRegs.Ext, maxRequest.Regs.Ext, "gdpr", "gpp", "gpp_sid", "us_privacy")
maxRequest.Regs.Ext = setIfKeysExists(signalRegs.Ext, maxRequest.Regs.Ext, "gdpr", "gpp", "gpp_sid", "us_privacy", "dsa")
}

func updateSource(signalSource *openrtb2.Source, maxRequest *openrtb2.BidRequest) {
Expand Down
54 changes: 47 additions & 7 deletions modules/pubmatic/openwrap/applovinmax_test.go

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions modules/pubmatic/openwrap/beforevalidationhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"strconv"
"strings"
"unicode"

validator "github.com/asaskevich/govalidator"
"github.com/buger/jsonparser"
Expand Down Expand Up @@ -530,6 +531,11 @@ func (m OpenWrap) handleBeforeValidationHook(
if impExt.Wrapper != nil {
adserverURL = impExt.Wrapper.AdServerURL
}

if rCtx.Endpoint == models.EndpointAppLovinMax && payload.BidRequest.App != nil && payload.BidRequest.App.StoreURL == "" {
rCtx.AppLovinMax.AppStoreUrl = getProfileAppStoreUrlAndUpdateItunesID(rCtx, payload.BidRequest, impExt)
rCtx.PageURL = rCtx.AppLovinMax.AppStoreUrl
}
impExt.Wrapper = nil
impExt.Reward = nil
impExt.Bidder = nil
Expand Down Expand Up @@ -665,6 +671,12 @@ func (m *OpenWrap) applyProfileChanges(rctx models.RequestCtx, bidRequest *openr
bidRequest.Test = 1
}

if rctx.Endpoint == models.EndpointAppLovinMax {
if rctx.AppLovinMax.AppStoreUrl != "" {
bidRequest.App.StoreURL = rctx.AppLovinMax.AppStoreUrl
}
}

if cur, ok := rctx.PartnerConfigMap[models.VersionLevelConfigID][models.AdServerCurrency]; ok {
bidRequest.Cur = append(bidRequest.Cur, cur)
}
Expand Down Expand Up @@ -1289,3 +1301,49 @@ func isValidURL(urlVal string) bool {
}
return validator.IsRequestURL(urlVal) && validator.IsURL(urlVal)
}

func getProfileAppStoreUrlAndUpdateItunesID(rctx models.RequestCtx, bidRequest *openrtb2.BidRequest, impExt *models.ImpExtension) string {
appStoreUrl := rctx.PartnerConfigMap[models.VersionLevelConfigID][models.AppStoreUrl]
if appStoreUrl == "" {
glog.Errorf("[AppLovinMax] [PubID]: %d [ProfileID]: %d [Error]: app storeurl not present in DB", rctx.PubID, rctx.ProfileID)
return appStoreUrl
}
appStoreUrl = strings.TrimSpace(appStoreUrl)
if !isValidURL(appStoreUrl) {
glog.Errorf("[AppLovinMax] [PubID]: %d [ProfileID]: %d [AppStoreUrl]: %s [Error]: Invalid app storeurl", rctx.PubID, rctx.ProfileID, appStoreUrl)
return appStoreUrl
}
var err error
if bidRequest.Device != nil && strings.ToLower(bidRequest.Device.OS) == "ios" {
//no multiple imp supported for AppLovinMax
if impExt != nil {
if impExt.SKAdnetwork == nil {
glog.Errorf("[AppLovinMax] [PubID]: %d [ProfileID]: %d [Error]: skadn is missing in imp.ext", rctx.PubID, rctx.ProfileID, appStoreUrl)
return appStoreUrl
}
var itunesID string
if itunesID = extractItunesIdFromAppStoreUrl(appStoreUrl); itunesID == "" {
glog.Errorf("[AppLovinMax] [PubID]: %d [ProfileID]: %d [AppStoreUrl]: %s [Error]: itunes id is missing in app store url", rctx.PubID, rctx.ProfileID, appStoreUrl)
return appStoreUrl
}
if impExt.SKAdnetwork, err = jsonparser.Set(impExt.SKAdnetwork, []byte(strconv.Quote(itunesID)), "sourceapp"); err != nil {
glog.Errorf("[AppLovinMax] [PubID]: %d [ProfileID]: %d [AppStoreUrl]: %s [Error]: %s", rctx.PubID, rctx.ProfileID, appStoreUrl, err.Error())
}
}
}
return appStoreUrl
}

func extractItunesIdFromAppStoreUrl(url string) string {
url = strings.TrimSuffix(url, "/")
itunesID := ""
for i := len(url) - 1; i >= 0; i-- {
char := rune(url[i])
if unicode.IsDigit(char) {
itunesID = string(char) + itunesID
} else {
break
}
}
return itunesID
}
Loading

0 comments on commit 0d8fef1

Please sign in to comment.