use crate::js::{Object, Value};
use crate::obj;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SiteRow {
pub id: String,
pub name: String,
pub hostnames: Vec<String>,
pub timezone: String,
}
impl SiteRow {
pub fn to_value(&self) -> Value {
obj! {
"id" => self.id.clone(),
"name" => self.name.clone(),
"hostnames" => Value::Array(self.hostnames.iter().map(|h| Value::from(h.as_str())).collect()),
"timezone" => self.timezone.clone(),
}
}
}
pub type SiteOverrides = Object;
#[derive(Clone, Debug, PartialEq)]
pub struct GoalRow {
pub id: String,
pub site: String,
pub name: String,
pub kind: String,
pub match_: String,
pub click_by: String,
pub value_mode: String,
pub value: f64,
pub value_prop: String,
pub currency: String,
pub created_at: i64,
}
impl GoalRow {
pub fn to_value(&self) -> Value {
obj! {
"id" => self.id.clone(), "site" => self.site.clone(), "name" => self.name.clone(), "kind" => self.kind.clone(),
"match" => self.match_.clone(), "clickBy" => self.click_by.clone(), "valueMode" => self.value_mode.clone(),
"value" => self.value, "valueProp" => self.value_prop.clone(), "currency" => self.currency.clone(),
"createdAt" => self.created_at,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ReportRow {
pub id: String,
pub site: String,
pub email: String,
pub frequency: String,
pub lang: String,
pub token: String,
pub origin: String,
pub last_period: String,
pub last_sent_at: Option<i64>,
pub created_at: i64,
}
impl ReportRow {
pub fn to_value(&self) -> Value {
obj! {
"id" => self.id.clone(), "site" => self.site.clone(), "email" => self.email.clone(), "frequency" => self.frequency.clone(),
"lang" => self.lang.clone(), "token" => self.token.clone(), "origin" => self.origin.clone(),
"lastPeriod" => self.last_period.clone(), "lastSentAt" => self.last_sent_at, "createdAt" => self.created_at,
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct GoalTotals {
pub conversions: f64,
pub visitors: f64,
pub revenue: f64,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ShareRow {
pub id: String,
pub site: String,
pub name: String,
pub created_at: i64,
}
impl ShareRow {
pub fn to_value(&self) -> Value {
obj! { "id" => self.id.clone(), "site" => self.site.clone(), "name" => self.name.clone(), "createdAt" => self.created_at }
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FunnelStep {
pub kind: String,
pub match_: String,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FunnelRow {
pub id: String,
pub site: String,
pub name: String,
pub steps: Vec<FunnelStep>,
pub created_at: i64,
}
impl FunnelRow {
pub fn steps_value(&self) -> Value {
Value::Array(
self.steps.iter().map(|s| obj! { "kind" => s.kind.clone(), "match" => s.match_.clone() }).collect(),
)
}
pub fn to_value(&self) -> Value {
obj! { "id" => self.id.clone(), "site" => self.site.clone(), "name" => self.name.clone(), "steps" => self.steps_value(), "createdAt" => self.created_at }
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TokenRow {
pub id: String,
pub name: String,
pub site: String,
pub scope: String,
pub hash: String,
pub hint: String,
pub created_at: i64,
pub last_used_at: Option<i64>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LinkRow {
pub id: String,
pub site: String,
pub domain: String,
pub slug: String,
pub name: String,
pub url: String,
pub created_at: i64,
pub updated_at: i64,
}
impl LinkRow {
pub fn to_object(&self) -> Object {
let mut o = Object::new();
o.set("id", self.id.clone());
o.set("site", self.site.clone());
o.set("domain", self.domain.clone());
o.set("slug", self.slug.clone());
o.set("name", self.name.clone());
o.set("url", self.url.clone());
o.set("createdAt", self.created_at);
o.set("updatedAt", self.updated_at);
o
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct SessionRow {
pub id: String,
pub site: String,
pub visitor: String,
pub started_at: i64,
pub hostname: String,
pub referrer_host: String,
pub referrer_path: String,
pub source: String,
pub channel: String,
pub utm_source: String,
pub utm_medium: String,
pub utm_campaign: String,
pub utm_term: String,
pub utm_content: String,
pub country: String,
pub region: String,
pub city: String,
pub browser: String,
pub browser_version: String,
pub os: String,
pub os_version: String,
pub device: String,
pub screen: String,
pub language: String,
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct EventRow {
pub site: String,
pub ts: i64,
pub kind: String,
pub visitor: String,
pub session: String,
pub pageview: String,
pub path: String,
pub hostname: String,
pub title: String,
pub name: String,
pub props: Option<Object>,
pub engaged_ms: i64,
pub scroll: Option<i64>,
pub link: String,
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct Stats {
pub visitors: f64,
pub visits: f64,
pub pageviews: f64,
pub views_per_visit: f64,
pub bounce_rate: f64,
pub visit_duration: f64,
}
impl Stats {
pub fn to_value(&self) -> Value {
obj! {
"visitors" => self.visitors, "visits" => self.visits, "pageviews" => self.pageviews,
"viewsPerVisit" => self.views_per_visit, "bounceRate" => self.bounce_rate, "visitDuration" => self.visit_duration,
}
}
pub fn get(&self, key: &str) -> f64 {
match key {
"visitors" => self.visitors,
"visits" => self.visits,
"pageviews" => self.pageviews,
"viewsPerVisit" => self.views_per_visit,
"bounceRate" => self.bounce_rate,
"visitDuration" => self.visit_duration,
_ => 0.0,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PageviewInfo {
pub session: String,
pub visitor: String,
pub path: String,
pub hostname: String,
pub ts: i64,
pub started_at: i64,
pub last_at: i64,
}