edgee_components_runtime/data_collection/versions/v1_0_1/
convert.rs1use crate::data_collection::convert::{convert_products, convert_properties};
2use crate::data_collection::payload;
3use crate::data_collection::versions::v1_0_1::data_collection::exports::edgee::components1_0_1::data_collection as DC;
4
5impl From<payload::Event> for DC::Event {
6 fn from(value: payload::Event) -> Self {
7 let data = match value.data {
8 payload::Data::Page(page) => DC::Data::Page(page.into()),
9 payload::Data::User(user) => DC::Data::User(user.into()),
10 payload::Data::Track(track) => DC::Data::Track(track.into()),
11 };
12 let consent = match value.consent {
13 Some(payload::Consent::Pending) => Some(DC::Consent::Pending),
14 Some(payload::Consent::Granted) => Some(DC::Consent::Granted),
15 Some(payload::Consent::Denied) => Some(DC::Consent::Denied),
16 None => None,
17 };
18 Self {
19 uuid: value.uuid,
20 timestamp: value.timestamp.timestamp(),
21 timestamp_millis: value.timestamp.timestamp_millis(),
22 timestamp_micros: value.timestamp.timestamp_micros(),
23 event_type: value.event_type.into(),
24 data,
25 context: value.context.into(),
26 consent,
27 }
28 }
29}
30
31impl From<payload::EventType> for DC::EventType {
32 fn from(value: payload::EventType) -> Self {
33 match value {
34 payload::EventType::Page => Self::Page,
35 payload::EventType::User => Self::User,
36 payload::EventType::Track => Self::Track,
37 }
38 }
39}
40
41impl From<payload::Page> for DC::PageData {
42 fn from(value: payload::Page) -> Self {
43 Self {
44 name: value.name,
45 category: value.category,
46 keywords: value.keywords,
47 title: value.title,
48 url: value.url,
49 path: value.path,
50 search: value.search,
51 referrer: value.referrer,
52 properties: convert_properties(value.properties.clone()),
53 }
54 }
55}
56
57impl From<payload::User> for DC::UserData {
58 fn from(value: payload::User) -> Self {
59 Self {
60 user_id: value.user_id,
61 anonymous_id: value.anonymous_id,
62 edgee_id: value.edgee_id,
63 properties: convert_properties(value.properties.clone()),
64 }
65 }
66}
67
68impl From<payload::Track> for DC::TrackData {
69 fn from(value: payload::Track) -> Self {
70 Self {
71 name: value.name,
72 properties: convert_properties(value.properties.clone()),
73 products: convert_products(value.products.clone()),
74 }
75 }
76}
77
78impl From<payload::Context> for DC::Context {
79 fn from(value: payload::Context) -> Self {
80 Self {
81 page: value.page.into(),
82 user: value.user.into(),
83 client: value.client.into(),
84 campaign: value.campaign.into(),
85 session: value.session.into(),
86 }
87 }
88}
89
90impl From<payload::Campaign> for DC::Campaign {
91 fn from(value: payload::Campaign) -> Self {
92 Self {
93 name: value.name,
94 source: value.source,
95 medium: value.medium,
96 term: value.term,
97 content: value.content,
98 creative_format: value.creative_format,
99 marketing_tactic: value.marketing_tactic,
100 }
101 }
102}
103
104impl From<payload::Client> for DC::Client {
105 fn from(value: payload::Client) -> Self {
106 Self {
107 ip: value.ip,
108 locale: value.locale,
109 timezone: value.timezone,
110 user_agent: value.user_agent,
111 user_agent_architecture: value.user_agent_architecture,
112 user_agent_bitness: value.user_agent_bitness,
113 user_agent_full_version_list: value.user_agent_full_version_list,
114 user_agent_version_list: value.user_agent_version_list,
115 user_agent_mobile: value.user_agent_mobile,
116 user_agent_model: value.user_agent_model,
117 os_name: value.os_name,
118 os_version: value.os_version,
119 screen_width: value.screen_width,
120 screen_height: value.screen_height,
121 screen_density: value.screen_density,
122 continent: value.continent,
123 country_code: value.country_code,
124 country_name: value.country_name,
125 region: value.region,
126 city: value.city,
127 }
128 }
129}
130
131impl From<payload::Session> for DC::Session {
132 fn from(value: payload::Session) -> Self {
133 Self {
134 session_id: value.session_id,
135 previous_session_id: value.previous_session_id,
136 session_count: value.session_count,
137 session_start: value.session_start,
138 first_seen: value.first_seen.timestamp(),
139 last_seen: value.last_seen.timestamp(),
140 }
141 }
142}