-
Notifications
You must be signed in to change notification settings - Fork 726
/
model.go
50 lines (44 loc) · 1.35 KB
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package agma
import (
"fmt"
"time"
"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/jsonutil"
)
type EventType string
const (
EventTypeAuction EventType = "auction"
EventTypeAmp EventType = "amp"
EventTypeVideo EventType = "video"
)
type logObject struct {
EventType EventType `json:"type"`
RequestId string `json:"id"`
AccountCode string `json:"code"`
Site *openrtb2.Site `json:"site,omitempty"`
App *openrtb2.App `json:"app,omitempty"`
Device *openrtb2.Device `json:"device,omitempty"`
User *openrtb2.User `json:"user,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
func serializeAnayltics(
requestwrapper *openrtb_ext.RequestWrapper,
eventType EventType,
code string,
createdAt time.Time,
) ([]byte, error) {
if requestwrapper == nil || requestwrapper.BidRequest == nil {
return nil, fmt.Errorf("requestwrapper or BidRequest object nil")
}
return jsonutil.Marshal(&logObject{
EventType: eventType,
RequestId: requestwrapper.ID,
AccountCode: code,
Site: requestwrapper.BidRequest.Site,
App: requestwrapper.BidRequest.App,
Device: requestwrapper.BidRequest.Device,
User: requestwrapper.BidRequest.User,
CreatedAt: createdAt,
})
}