diff --git a/analytics/build/build.go b/analytics/build/build.go index fc47835b088..4cba9a3f1a6 100644 --- a/analytics/build/build.go +++ b/analytics/build/build.go @@ -160,6 +160,9 @@ func evaluateActivities(rw *openrtb_ext.RequestWrapper, ac privacy.ActivityContr } func updateReqWrapperForAnalytics(rw *openrtb_ext.RequestWrapper, adapterName string, isCloned bool) *openrtb_ext.RequestWrapper { + if rw == nil { + return nil + } reqExt, _ := rw.GetRequestExt() reqExtPrebid := reqExt.GetPrebid() if reqExtPrebid == nil { diff --git a/analytics/build/build_test.go b/analytics/build/build_test.go index 5071f93a6f7..d794c01ab8c 100644 --- a/analytics/build/build_test.go +++ b/analytics/build/build_test.go @@ -591,12 +591,22 @@ func TestUpdateReqWrapperForAnalytics(t *testing.T) { Ext: []byte(`{"prebid":{"analytics":{"adapter1":{"client-analytics":true},"adapter2":{"client-analytics":false}}}}`)}, }, }, + { + description: "Given request is nil, check there are no exceptions", + givenReqWrapper: nil, + givenAdapterName: "adapter1", + givenIsCloned: false, + expectedUpdatedBidRequest: nil, + expectedCloneRequest: nil, + }, } for _, test := range tests { t.Run(test.description, func(t *testing.T) { cloneReq := updateReqWrapperForAnalytics(test.givenReqWrapper, test.givenAdapterName, test.givenIsCloned) - assert.Equal(t, test.expectedUpdatedBidRequest, test.givenReqWrapper.BidRequest) + if test.givenReqWrapper != nil { + assert.Equal(t, test.expectedUpdatedBidRequest, test.givenReqWrapper.BidRequest) + } assert.Equal(t, test.expectedCloneRequest, cloneReq) }) }