Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UOE-11191: Refactor: consume StoreURL from New portal UI and forward appstoreurl and appsource for applovinmax #925

Merged
merged 6 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions modules/pubmatic/openwrap/beforevalidationhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,11 @@ func (m OpenWrap) handleBeforeValidationHook(
}

if rCtx.Endpoint == models.EndpointAppLovinMax && payload.BidRequest.App != nil && payload.BidRequest.App.StoreURL == "" {
rCtx.AppLovinMax.AppStoreUrl = getProfileAppStoreUrlAndUpdateItunesID(rCtx, payload.BidRequest, impExt)
var isValidAppStoreUrl bool
rCtx.AppLovinMax.AppStoreUrl, isValidAppStoreUrl = getProfileAppStoreUrl(rCtx)
if isValidAppStoreUrl {
updateSkadnSourceapp(rCtx, rCtx.AppLovinMax.AppStoreUrl, payload.BidRequest, impExt)
}
rCtx.PageURL = rCtx.AppLovinMax.AppStoreUrl
}
impExt.Wrapper = nil
Expand Down Expand Up @@ -1344,36 +1348,39 @@ func isValidURL(urlVal string) bool {
return validator.IsRequestURL(urlVal) && validator.IsURL(urlVal)
}

func getProfileAppStoreUrlAndUpdateItunesID(rctx models.RequestCtx, bidRequest *openrtb2.BidRequest, impExt *models.ImpExtension) string {
func getProfileAppStoreUrl(rctx models.RequestCtx) (string, bool) {
isValidAppStoreUrl := false
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
glog.Errorf("[AppLovinMax] [PubID]: %d [ProfileID]: %d [Error]: app store url not present in DB", rctx.PubID, rctx.ProfileID)
return appStoreUrl, isValidAppStoreUrl
}
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
glog.Errorf("[AppLovinMax] [PubID]: %d [ProfileID]: %d [AppStoreUrl]: %s [Error]: Invalid app store url", rctx.PubID, rctx.ProfileID, appStoreUrl)
return appStoreUrl, isValidAppStoreUrl
}
isValidAppStoreUrl = true
return appStoreUrl, isValidAppStoreUrl
}

func updateSkadnSourceapp(rctx models.RequestCtx, appStoreUrl string, bidRequest *openrtb2.BidRequest, impExt *models.ImpExtension) {
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)
AvinashKapre marked this conversation as resolved.
Show resolved Hide resolved
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
}
AvinashKapre marked this conversation as resolved.
Show resolved Hide resolved
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 {
Expand Down
82 changes: 62 additions & 20 deletions modules/pubmatic/openwrap/beforevalidationhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6572,37 +6572,76 @@ func TestSetImpBidFloorParams(t *testing.T) {
}
}

func TestUpdateProfileAppStoreUrl(t *testing.T) {
func TestGetProfileAppStoreUrl(t *testing.T) {
type args struct {
rctx models.RequestCtx
}
tests := []struct {
name string
rctx models.RequestCtx
bidRequest *openrtb2.BidRequest
impExt *models.ImpExtension
wantAppStoreURL string
wantSourceApp string
name string
args args
want string
want1 bool
}{
{
name: "AppStoreUrl missing in DB",
rctx: models.RequestCtx{
PartnerConfigMap: map[int]map[string]string{
models.VersionLevelConfigID: {},
args: args{
rctx: models.RequestCtx{
PartnerConfigMap: map[int]map[string]string{
models.VersionLevelConfigID: {},
},
},
},
bidRequest: &openrtb2.BidRequest{App: &openrtb2.App{}},
wantAppStoreURL: "",
want: "",
want1: false,
},
{
name: "Invalid AppStoreUrl",
rctx: models.RequestCtx{
PartnerConfigMap: map[int]map[string]string{
models.VersionLevelConfigID: {
models.AppStoreUrl: "invalid-url",
args: args{
rctx: models.RequestCtx{
PartnerConfigMap: map[int]map[string]string{
models.VersionLevelConfigID: {
models.AppStoreUrl: "invalid-url",
},
},
},
},
bidRequest: &openrtb2.BidRequest{App: &openrtb2.App{}},
wantAppStoreURL: "invalid-url",
want: "invalid-url",
want1: false,
},
{
name: "Valid AppStoreUrl",
args: args{
rctx: models.RequestCtx{
PartnerConfigMap: map[int]map[string]string{
models.VersionLevelConfigID: {
models.AppStoreUrl: "https://apps.apple.com/app/id123456789",
},
},
},
},
want: "https://apps.apple.com/app/id123456789",
want1: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1 := getProfileAppStoreUrl(tt.args.rctx)
assert.Equal(t, tt.want, got)
assert.Equal(t, tt.want1, got1)
})
}
}

func TestUpdateSkadnSourceapp(t *testing.T) {
tests := []struct {
name string
rctx models.RequestCtx
appStoreUrl string
bidRequest *openrtb2.BidRequest
impExt *models.ImpExtension
wantAppStoreURL string
wantSourceApp string
}{
{
name: "Valid AppStoreUrl os is ios and SKAdnetwork is present in imp.ext",
rctx: models.RequestCtx{
Expand All @@ -6612,6 +6651,7 @@ func TestUpdateProfileAppStoreUrl(t *testing.T) {
},
},
},
appStoreUrl: "https://apps.apple.com/app/id123456789",
bidRequest: &openrtb2.BidRequest{
App: &openrtb2.App{},
Device: &openrtb2.Device{
Expand All @@ -6638,6 +6678,7 @@ func TestUpdateProfileAppStoreUrl(t *testing.T) {
},
},
},
appStoreUrl: "https://apps.apple.com/app/id123456789",
bidRequest: &openrtb2.BidRequest{
App: &openrtb2.App{},
Device: &openrtb2.Device{
Expand All @@ -6660,6 +6701,7 @@ func TestUpdateProfileAppStoreUrl(t *testing.T) {
},
},
},
appStoreUrl: "https://apps.apple.com/app/id123456789",
bidRequest: &openrtb2.BidRequest{
App: &openrtb2.App{},
Device: &openrtb2.Device{
Expand All @@ -6683,6 +6725,7 @@ func TestUpdateProfileAppStoreUrl(t *testing.T) {
},
},
},
appStoreUrl: "https://apps.apple.com/app/",
bidRequest: &openrtb2.BidRequest{
App: &openrtb2.App{},
Device: &openrtb2.Device{
Expand All @@ -6703,8 +6746,7 @@ func TestUpdateProfileAppStoreUrl(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotAppStoreURL := getProfileAppStoreUrlAndUpdateItunesID(tt.rctx, tt.bidRequest, tt.impExt)
assert.Equal(t, tt.wantAppStoreURL, gotAppStoreURL)
updateSkadnSourceapp(tt.rctx, tt.appStoreUrl, tt.bidRequest, tt.impExt)
if tt.impExt != nil {
if tt.impExt.SKAdnetwork != nil {
var skAdnetwork map[string]interface{}
Expand Down
Loading