openrtb_native1/response/event_tracker.rs
1/// 5.8 Event Tracker Response Object
2///
3/// The event trackers response is an array of objects and specifies the types of events the bidder
4/// wishes to track and the URLs/information to track them. Bidder must only respond with methods
5/// indicated as available in the request. Note that most javascript trackers expect to be loaded at
6/// impression time, so it’s not generally recommended for the buyer to respond with javascript
7/// trackers on other events, but the appropriateness of this is up to each buyer.
8#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
9pub struct EventTracker {
10 /// required; integer; -
11 /// Type of event to track. See Event Types table.
12 pub event: crate::EventType,
13
14 /// required; integer; -
15 /// Type of tracking requested. See Event Tracking Methods table.
16 pub method: crate::EventTrackingMethod,
17
18 /// optional; text; -
19 /// The URL of the image or js. Required for image or js, optional for custom.
20 #[serde(default, skip_serializing_if = "Option::is_none")]
21 pub url: Option<String>,
22
23 /// optional; object containing key:value pairs; -
24 /// To be agreed individually with the exchange, an array of key:value objects for custom
25 /// tracking, for example the account number of the DSP with a tracking company. IE
26 /// `{“accountnumber”:”123”}`.
27 #[serde(default, skip_serializing_if = "Option::is_none")]
28 pub customdata: Option<serde_json::Map<String, serde_json::Value>>,
29
30 /// optional; object; -
31 /// This object is a placeholder that may contain custom JSON agreed to by the parties to
32 /// support flexibility beyond the standard defined in this specification.
33 #[serde(default, skip_serializing_if = "Option::is_none")]
34 pub ext: Option<serde_json::Map<String, serde_json::Value>>,
35}
36
37#[cfg(test)]
38mod test {
39 use super::*;
40
41 #[test]
42 fn json() -> serde_json::Result<()> {
43 let json = r#"{"event":1,"method":1}"#;
44 let o1 = EventTracker {
45 event: crate::EventType::Impression,
46 method: crate::EventTrackingMethod::Img,
47 url: None,
48 customdata: None,
49 ext: None,
50 };
51 assert_eq!(serde_json::to_string(&o1)?, json);
52 assert_eq!(o1, serde_json::from_str::<EventTracker>(json)?);
53
54 Ok(())
55 }
56}