Implement analytics marker events (#6090)

* Analytics events

* prepare

* change route prefix

* update route return

* Add mod launcher analytics

* more UA strings

* fix ci

* caching on analytics events

* Return parent modpack versions for playtime queries

* sqlx prepare

* fmt

* dummy fixtures
This commit is contained in:
aecsocket
2026-05-19 13:06:04 +00:00
committed by GitHub
parent 48bb44155d
commit 244c263e40
19 changed files with 928 additions and 35 deletions
@@ -0,0 +1,55 @@
use std::collections::HashSet;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::models::ids::AnalyticsEventId;
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct AnalyticsEvent {
pub id: AnalyticsEventId,
#[serde(flatten)]
pub meta: AnalyticsEventMeta,
pub starts: DateTime<Utc>,
pub ends: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct AnalyticsEventMeta {
#[serde(default)]
pub title: String,
#[serde(default)]
pub announcement_url: Option<String>,
#[serde(default)]
pub for_metric_kind: HashSet<MetricKind>,
}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Hash,
Serialize,
Deserialize,
utoipa::ToSchema,
)]
#[serde(rename_all = "snake_case")]
pub enum MetricKind {
Views,
Downloads,
Playtime,
Revenue,
}
impl From<crate::database::models::DBAnalyticsEvent> for AnalyticsEvent {
fn from(data: crate::database::models::DBAnalyticsEvent) -> Self {
Self {
id: data.id.into(),
meta: data.meta,
starts: data.starts,
ends: data.ends,
}
}
}
+1
View File
@@ -26,3 +26,4 @@ base62_id!(ThreadMessageId);
base62_id!(UserSubscriptionId);
base62_id!(VersionId);
base62_id!(AffiliateCodeId);
base62_id!(AnalyticsEventId);
+1
View File
@@ -1,5 +1,6 @@
pub mod affiliate_code;
pub mod analytics;
pub mod analytics_event;
pub mod billing;
pub mod collections;
pub mod ids;