1use crate::js::{Object, Value};
5use crate::obj;
6
7#[derive(Clone, Debug, PartialEq, Eq)]
9pub struct SiteRow {
10 pub id: String,
12 pub name: String,
14 pub hostnames: Vec<String>,
16 pub timezone: String,
18}
19
20impl SiteRow {
21 pub fn to_value(&self) -> Value {
23 obj! {
24 "id" => self.id.clone(),
25 "name" => self.name.clone(),
26 "hostnames" => Value::Array(self.hostnames.iter().map(|h| Value::from(h.as_str())).collect()),
27 "timezone" => self.timezone.clone(),
28 }
29 }
30}
31
32pub type SiteOverrides = Object;
35
36#[derive(Clone, Debug, PartialEq)]
38pub struct GoalRow {
39 pub id: String,
41 pub site: String,
43 pub name: String,
45 pub kind: String,
47 pub match_: String,
49 pub click_by: String,
51 pub value_mode: String,
53 pub value: f64,
55 pub value_prop: String,
57 pub currency: String,
59 pub created_at: i64,
61}
62
63impl GoalRow {
64 pub fn to_value(&self) -> Value {
66 obj! {
67 "id" => self.id.clone(), "site" => self.site.clone(), "name" => self.name.clone(), "kind" => self.kind.clone(),
68 "match" => self.match_.clone(), "clickBy" => self.click_by.clone(), "valueMode" => self.value_mode.clone(),
69 "value" => self.value, "valueProp" => self.value_prop.clone(), "currency" => self.currency.clone(),
70 "createdAt" => self.created_at,
71 }
72 }
73}
74
75#[derive(Clone, Debug, PartialEq, Eq)]
77pub struct ReportRow {
78 pub id: String,
80 pub site: String,
82 pub email: String,
84 pub frequency: String,
86 pub lang: String,
88 pub token: String,
90 pub origin: String,
92 pub last_period: String,
94 pub last_sent_at: Option<i64>,
96 pub created_at: i64,
98}
99
100impl ReportRow {
101 pub fn to_value(&self) -> Value {
103 obj! {
104 "id" => self.id.clone(), "site" => self.site.clone(), "email" => self.email.clone(), "frequency" => self.frequency.clone(),
105 "lang" => self.lang.clone(), "token" => self.token.clone(), "origin" => self.origin.clone(),
106 "lastPeriod" => self.last_period.clone(), "lastSentAt" => self.last_sent_at, "createdAt" => self.created_at,
107 }
108 }
109}
110
111#[derive(Clone, Copy, Debug, Default, PartialEq)]
113pub struct GoalTotals {
114 pub conversions: f64,
116 pub visitors: f64,
118 pub revenue: f64,
120}
121
122#[derive(Clone, Debug, PartialEq, Eq)]
124pub struct ShareRow {
125 pub id: String,
127 pub site: String,
129 pub name: String,
131 pub created_at: i64,
133}
134
135impl ShareRow {
136 pub fn to_value(&self) -> Value {
138 obj! { "id" => self.id.clone(), "site" => self.site.clone(), "name" => self.name.clone(), "createdAt" => self.created_at }
139 }
140}
141
142#[derive(Clone, Debug, PartialEq, Eq)]
144pub struct FunnelStep {
145 pub kind: String,
147 pub match_: String,
149}
150
151#[derive(Clone, Debug, PartialEq, Eq)]
153pub struct FunnelRow {
154 pub id: String,
156 pub site: String,
158 pub name: String,
160 pub steps: Vec<FunnelStep>,
162 pub created_at: i64,
164}
165
166impl FunnelRow {
167 pub fn steps_value(&self) -> Value {
169 Value::Array(
170 self.steps.iter().map(|s| obj! { "kind" => s.kind.clone(), "match" => s.match_.clone() }).collect(),
171 )
172 }
173
174 pub fn to_value(&self) -> Value {
176 obj! { "id" => self.id.clone(), "site" => self.site.clone(), "name" => self.name.clone(), "steps" => self.steps_value(), "createdAt" => self.created_at }
177 }
178}
179
180#[derive(Clone, Debug, PartialEq, Eq)]
182pub struct TokenRow {
183 pub id: String,
185 pub name: String,
187 pub site: String,
189 pub scope: String,
192 pub hash: String,
194 pub hint: String,
196 pub created_at: i64,
198 pub last_used_at: Option<i64>,
200}
201
202#[derive(Clone, Debug, PartialEq, Eq)]
204pub struct LinkRow {
205 pub id: String,
207 pub site: String,
209 pub domain: String,
211 pub slug: String,
213 pub name: String,
215 pub url: String,
217 pub created_at: i64,
219 pub updated_at: i64,
221}
222
223impl LinkRow {
224 pub fn to_object(&self) -> Object {
226 let mut o = Object::new();
227 o.set("id", self.id.clone());
228 o.set("site", self.site.clone());
229 o.set("domain", self.domain.clone());
230 o.set("slug", self.slug.clone());
231 o.set("name", self.name.clone());
232 o.set("url", self.url.clone());
233 o.set("createdAt", self.created_at);
234 o.set("updatedAt", self.updated_at);
235 o
236 }
237}
238
239#[derive(Clone, Debug, Default, PartialEq, Eq)]
241pub struct SessionRow {
242 pub id: String,
244 pub site: String,
246 pub visitor: String,
248 pub started_at: i64,
250 pub hostname: String,
252 pub referrer_host: String,
254 pub referrer_path: String,
256 pub source: String,
258 pub channel: String,
260 pub utm_source: String,
262 pub utm_medium: String,
264 pub utm_campaign: String,
266 pub utm_term: String,
268 pub utm_content: String,
270 pub country: String,
272 pub region: String,
274 pub city: String,
276 pub browser: String,
278 pub browser_version: String,
280 pub os: String,
282 pub os_version: String,
284 pub device: String,
286 pub screen: String,
288 pub language: String,
290}
291
292#[derive(Clone, Debug, Default, PartialEq)]
294pub struct EventRow {
295 pub site: String,
297 pub ts: i64,
299 pub kind: String,
301 pub visitor: String,
303 pub session: String,
305 pub pageview: String,
307 pub path: String,
309 pub hostname: String,
311 pub title: String,
313 pub name: String,
315 pub props: Option<Object>,
317 pub engaged_ms: i64,
319 pub scroll: Option<i64>,
321 pub link: String,
323}
324
325#[derive(Clone, Copy, Debug, Default, PartialEq)]
327pub struct Stats {
328 pub visitors: f64,
330 pub visits: f64,
332 pub pageviews: f64,
334 pub views_per_visit: f64,
336 pub bounce_rate: f64,
338 pub visit_duration: f64,
340}
341
342impl Stats {
343 pub fn to_value(&self) -> Value {
345 obj! {
346 "visitors" => self.visitors, "visits" => self.visits, "pageviews" => self.pageviews,
347 "viewsPerVisit" => self.views_per_visit, "bounceRate" => self.bounce_rate, "visitDuration" => self.visit_duration,
348 }
349 }
350
351 pub fn get(&self, key: &str) -> f64 {
353 match key {
354 "visitors" => self.visitors,
355 "visits" => self.visits,
356 "pageviews" => self.pageviews,
357 "viewsPerVisit" => self.views_per_visit,
358 "bounceRate" => self.bounce_rate,
359 "visitDuration" => self.visit_duration,
360 _ => 0.0,
361 }
362 }
363}
364
365#[derive(Clone, Debug, PartialEq, Eq)]
367pub struct PageviewInfo {
368 pub session: String,
370 pub visitor: String,
372 pub path: String,
374 pub hostname: String,
376 pub ts: i64,
378 pub started_at: i64,
380 pub last_at: i64,
382}