Skip to main content

wechat_mp_analytics/
lib.rs

1//! 微信小程序数据分析
2//!
3//! 文档:[数据分析接口列表](https://developers.weixin.qq.com/miniprogram/dev/server/API/data-analysis/)
4
5mod date;
6mod others;
7mod retain;
8mod trend;
9
10pub use date::DateRange;
11pub use others::*;
12pub use retain::*;
13pub use trend::*;
14
15use wechat_mp_core::MpClient;
16
17/// 数据分析 API 门面
18#[derive(Clone)]
19pub struct AnalyticsApi {
20    client: MpClient,
21}
22
23impl AnalyticsApi {
24    pub fn new(client: MpClient) -> Self {
25        Self { client }
26    }
27
28    pub fn client(&self) -> &MpClient {
29        &self.client
30    }
31
32    // —— 留存 ——
33
34    pub async fn daily_retain(
35        &self,
36        range: &DateRange,
37    ) -> wechat_mp_core::Result<RetainResponse> {
38        daily_retain(&self.client, range).await
39    }
40
41    pub async fn weekly_retain(
42        &self,
43        range: &DateRange,
44    ) -> wechat_mp_core::Result<RetainResponse> {
45        weekly_retain(&self.client, range).await
46    }
47
48    pub async fn monthly_retain(
49        &self,
50        range: &DateRange,
51    ) -> wechat_mp_core::Result<RetainResponse> {
52        monthly_retain(&self.client, range).await
53    }
54
55    // —— 趋势 ——
56
57    pub async fn daily_visit_trend(
58        &self,
59        range: &DateRange,
60    ) -> wechat_mp_core::Result<VisitTrendResponse> {
61        daily_visit_trend(&self.client, range).await
62    }
63
64    pub async fn weekly_visit_trend(
65        &self,
66        range: &DateRange,
67    ) -> wechat_mp_core::Result<VisitTrendResponse> {
68        weekly_visit_trend(&self.client, range).await
69    }
70
71    pub async fn monthly_visit_trend(
72        &self,
73        range: &DateRange,
74    ) -> wechat_mp_core::Result<VisitTrendResponse> {
75        monthly_visit_trend(&self.client, range).await
76    }
77
78    // —— 其他 ——
79
80    pub async fn daily_summary(
81        &self,
82        range: &DateRange,
83    ) -> wechat_mp_core::Result<DailySummaryResponse> {
84        daily_summary(&self.client, range).await
85    }
86
87    pub async fn visit_page(
88        &self,
89        range: &DateRange,
90    ) -> wechat_mp_core::Result<VisitPageResponse> {
91        visit_page(&self.client, range).await
92    }
93
94    pub async fn user_portrait(
95        &self,
96        range: &DateRange,
97    ) -> wechat_mp_core::Result<UserPortraitResponse> {
98        user_portrait(&self.client, range).await
99    }
100
101    pub async fn visit_distribution(
102        &self,
103        range: &DateRange,
104    ) -> wechat_mp_core::Result<VisitDistributionResponse> {
105        visit_distribution(&self.client, range).await
106    }
107
108    pub async fn performance_boot(
109        &self,
110        req: &PerformanceRequest,
111    ) -> wechat_mp_core::Result<PerformanceResponse> {
112        performance_boot(&self.client, req).await
113    }
114}