Skip to main content

systemprompt_cli/commands/core/content/analytics/
mod.rs

1pub mod campaign;
2pub mod clicks;
3pub mod journey;
4
5use crate::cli_settings::CliConfig;
6use crate::shared::render_result;
7use anyhow::{Context, Result};
8use clap::Subcommand;
9use systemprompt_database::DbPool;
10
11#[derive(Debug, Subcommand)]
12pub enum AnalyticsCommands {
13    #[command(about = "Show click history for a link")]
14    Clicks(clicks::ClicksArgs),
15
16    #[command(about = "Show campaign-level analytics")]
17    Campaign(campaign::CampaignArgs),
18
19    #[command(about = "Show content navigation graph")]
20    Journey(journey::JourneyArgs),
21}
22
23pub async fn execute(command: AnalyticsCommands, config: &CliConfig) -> Result<()> {
24    match command {
25        AnalyticsCommands::Clicks(args) => {
26            let result = clicks::execute(args, config)
27                .await
28                .context("Failed to get link clicks")?;
29            render_result(&result);
30        },
31        AnalyticsCommands::Campaign(args) => {
32            let result = campaign::execute(args, config)
33                .await
34                .context("Failed to get campaign analytics")?;
35            render_result(&result);
36        },
37        AnalyticsCommands::Journey(args) => {
38            let result = journey::execute(args, config)
39                .await
40                .context("Failed to get content journey")?;
41            render_result(&result);
42        },
43    }
44    Ok(())
45}
46
47pub async fn execute_with_pool(
48    command: AnalyticsCommands,
49    pool: &DbPool,
50    config: &CliConfig,
51) -> Result<()> {
52    match command {
53        AnalyticsCommands::Clicks(args) => {
54            let result = clicks::execute_with_pool(args, pool, config)
55                .await
56                .context("Failed to get link clicks")?;
57            render_result(&result);
58        },
59        AnalyticsCommands::Campaign(args) => {
60            let result = campaign::execute_with_pool(args, pool, config)
61                .await
62                .context("Failed to get campaign analytics")?;
63            render_result(&result);
64        },
65        AnalyticsCommands::Journey(args) => {
66            let result = journey::execute_with_pool(args, pool, config)
67                .await
68                .context("Failed to get content journey")?;
69            render_result(&result);
70        },
71    }
72    Ok(())
73}