mirror of
https://github.com/modrinth/code.git
synced 2026-08-27 18:14:49 +00:00
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:
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,3 +26,4 @@ base62_id!(ThreadMessageId);
|
||||
base62_id!(UserSubscriptionId);
|
||||
base62_id!(VersionId);
|
||||
base62_id!(AffiliateCodeId);
|
||||
base62_id!(AnalyticsEventId);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod affiliate_code;
|
||||
pub mod analytics;
|
||||
pub mod analytics_event;
|
||||
pub mod billing;
|
||||
pub mod collections;
|
||||
pub mod ids;
|
||||
|
||||
Reference in New Issue
Block a user