Skip to content

Commit cbb6eb6

Browse files
committed
add screen size to the backend
1 parent bc816b8 commit cbb6eb6

File tree

6 files changed

+17
-1
lines changed

6 files changed

+17
-1
lines changed

src/app/core/reports.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub enum Dimension {
6262
UtmCampaign,
6363
UtmContent,
6464
UtmTerm,
65+
ScreenResolution,
6566
}
6667

6768
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, Copy, Hash, Eq, PartialEq, PartialOrd, Ord)]
@@ -181,6 +182,7 @@ fn filter_sql(filters: &[DimensionFilter]) -> Result<(String, ParamVec<'_>)> {
181182
Dimension::UtmCampaign => format!("utm_campaign {filter_value}"),
182183
Dimension::UtmContent => format!("utm_content {filter_value}"),
183184
Dimension::UtmTerm => format!("utm_term {filter_value}"),
185+
Dimension::ScreenResolution => format!("concat_ws('x', screen_width::text, screen_height::text) {filter_value}"),
184186
})
185187
})
186188
.collect::<Result<Vec<String>>>()?;
@@ -457,6 +459,7 @@ pub fn dimension_report(
457459
Dimension::UtmCampaign => ("utm_campaign", "utm_campaign"),
458460
Dimension::UtmContent => ("utm_content", "utm_content"),
459461
Dimension::UtmTerm => ("utm_term", "utm_term"),
462+
Dimension::ScreenResolution => ("concat_ws('x', screen_width::text, screen_height::text)", "screen_width, screen_height"),
460463
};
461464

462465
params.push(range.start);

src/app/models.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub struct Event {
2323
pub utm_campaign: Option<String>,
2424
pub utm_content: Option<String>,
2525
pub utm_term: Option<String>,
26+
pub screen_width: Option<i32>,
27+
pub screen_height: Option<i32>,
2628
}
2729

2830
#[derive(Debug, Clone)]
@@ -100,6 +102,8 @@ macro_rules! event_params {
100102
$event.utm_term,
101103
None::<std::time::Duration>,
102104
None::<std::time::Duration>,
105+
$event.screen_width,
106+
$event.screen_height,
103107
]
104108
};
105109
}

src/utils/seed.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ pub fn random_events(
125125
utm_medium: Some(random_el(UTM_MEDIUMS, 0.6).to_string()),
126126
utm_source: Some(random_el(UTM_SOURCES, 0.6).to_string()),
127127
utm_term: Some(random_el(UTM_TERMS, 0.6).to_string()),
128+
screen_width: None,
129+
screen_height: None,
128130
})
129131
})
130132
}

src/web/routes/dashboard.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ async fn project_detailed_handler(
227227
let city = city.filter(|city| !city.is_empty());
228228
data.push(DimensionTableRow { dimension_value: key, value, display_name: city, icon: country });
229229
}
230+
Dimension::ScreenResolution => {
231+
data.push(DimensionTableRow { dimension_value: key, value, display_name: None, icon: None });
232+
}
230233
_ => {
231234
data.push(DimensionTableRow { dimension_value: key, value, display_name: None, icon: None });
232235
}

src/web/routes/event.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ struct EventRequest {
3030
url: String,
3131
referrer: Option<String>,
3232
utm: Option<Utm>,
33+
screen_width: Option<i32>,
34+
screen_height: Option<i32>,
3335
}
3436

3537
#[derive(serde::Deserialize, JsonSchema)]
@@ -124,6 +126,8 @@ fn process_event(
124126
utm_medium: event.utm.as_ref().and_then(|u| u.medium.clone()),
125127
utm_source: event.utm.as_ref().and_then(|u| u.source.clone()),
126128
utm_term: event.utm.as_ref().and_then(|u| u.term.clone()),
129+
screen_width: event.screen_width,
130+
screen_height: event.screen_height,
127131
};
128132

129133
events.send(event)?;

web/src/api/dashboard.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)