Skip to main content

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

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