github.com/prebid/prebid-server/v2@v2.18.0/analytics/pubstack/helpers/json.go (about) 1 package helpers 2 3 import ( 4 "fmt" 5 6 "github.com/prebid/openrtb/v20/openrtb2" 7 "github.com/prebid/prebid-server/v2/analytics" 8 "github.com/prebid/prebid-server/v2/util/jsonutil" 9 ) 10 11 func JsonifyAuctionObject(ao *analytics.AuctionObject, scope string) ([]byte, error) { 12 var logEntry *logAuction 13 if ao != nil { 14 var request *openrtb2.BidRequest 15 if ao.RequestWrapper != nil { 16 request = ao.RequestWrapper.BidRequest 17 } 18 logEntry = &logAuction{ 19 Status: ao.Status, 20 Errors: ao.Errors, 21 Request: request, 22 Response: ao.Response, 23 Account: ao.Account, 24 StartTime: ao.StartTime, 25 HookExecutionOutcome: ao.HookExecutionOutcome, 26 } 27 } 28 29 b, err := jsonutil.Marshal(&struct { 30 Scope string `json:"scope"` 31 *logAuction 32 }{ 33 Scope: scope, 34 logAuction: logEntry, 35 }) 36 37 if err == nil { 38 b = append(b, byte('\n')) 39 return b, nil 40 } 41 return nil, fmt.Errorf("auction object badly formed %v", err) 42 } 43 44 func JsonifyVideoObject(vo *analytics.VideoObject, scope string) ([]byte, error) { 45 var logEntry *logVideo 46 if vo != nil { 47 var request *openrtb2.BidRequest 48 if vo.RequestWrapper != nil { 49 request = vo.RequestWrapper.BidRequest 50 } 51 logEntry = &logVideo{ 52 Status: vo.Status, 53 Errors: vo.Errors, 54 Request: request, 55 Response: vo.Response, 56 VideoRequest: vo.VideoRequest, 57 VideoResponse: vo.VideoResponse, 58 StartTime: vo.StartTime, 59 } 60 } 61 62 b, err := jsonutil.Marshal(&struct { 63 Scope string `json:"scope"` 64 *logVideo 65 }{ 66 Scope: scope, 67 logVideo: logEntry, 68 }) 69 70 if err == nil { 71 b = append(b, byte('\n')) 72 return b, nil 73 } 74 return nil, fmt.Errorf("video object badly formed %v", err) 75 } 76 77 func JsonifyCookieSync(cso *analytics.CookieSyncObject, scope string) ([]byte, error) { 78 var logEntry *logUserSync 79 if cso != nil { 80 logEntry = &logUserSync{ 81 Status: cso.Status, 82 Errors: cso.Errors, 83 BidderStatus: cso.BidderStatus, 84 } 85 } 86 87 b, err := jsonutil.Marshal(&struct { 88 Scope string `json:"scope"` 89 *logUserSync 90 }{ 91 Scope: scope, 92 logUserSync: logEntry, 93 }) 94 95 if err == nil { 96 b = append(b, byte('\n')) 97 return b, nil 98 } 99 return nil, fmt.Errorf("cookie sync object badly formed %v", err) 100 } 101 102 func JsonifySetUIDObject(so *analytics.SetUIDObject, scope string) ([]byte, error) { 103 var logEntry *logSetUID 104 if so != nil { 105 logEntry = &logSetUID{ 106 Status: so.Status, 107 Bidder: so.Bidder, 108 UID: so.UID, 109 Errors: so.Errors, 110 Success: so.Success, 111 } 112 } 113 114 b, err := jsonutil.Marshal(&struct { 115 Scope string `json:"scope"` 116 *logSetUID 117 }{ 118 Scope: scope, 119 logSetUID: logEntry, 120 }) 121 122 if err == nil { 123 b = append(b, byte('\n')) 124 return b, nil 125 } 126 return nil, fmt.Errorf("set UID object badly formed %v", err) 127 } 128 129 func JsonifyAmpObject(ao *analytics.AmpObject, scope string) ([]byte, error) { 130 var logEntry *logAMP 131 if ao != nil { 132 var request *openrtb2.BidRequest 133 if ao.RequestWrapper != nil { 134 request = ao.RequestWrapper.BidRequest 135 } 136 logEntry = &logAMP{ 137 Status: ao.Status, 138 Errors: ao.Errors, 139 Request: request, 140 AuctionResponse: ao.AuctionResponse, 141 AmpTargetingValues: ao.AmpTargetingValues, 142 Origin: ao.Origin, 143 StartTime: ao.StartTime, 144 HookExecutionOutcome: ao.HookExecutionOutcome, 145 } 146 } 147 148 b, err := jsonutil.Marshal(&struct { 149 Scope string `json:"scope"` 150 *logAMP 151 }{ 152 Scope: scope, 153 logAMP: logEntry, 154 }) 155 156 if err == nil { 157 b = append(b, byte('\n')) 158 return b, nil 159 } 160 return nil, fmt.Errorf("amp object badly formed %v", err) 161 }