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,
4//! journey) against the invocation's [`CommandContext`].
5//!
6//! Copyright (c) systemprompt.io — Business Source License 1.1.
7//! See <https://systemprompt.io> for licensing details.
8
9pub mod campaign;
10pub mod clicks;
11pub mod journey;
12
13use crate::context::CommandContext;
14use crate::shared::render_result;
15use anyhow::{Context, Result};
16use clap::Subcommand;
17
18#[derive(Debug, Subcommand)]
19pub enum AnalyticsCommands {
20    #[command(about = "Show click history for a link")]
21    Clicks(clicks::ClicksArgs),
22
23    #[command(about = "Show campaign-level analytics")]
24    Campaign(campaign::CampaignArgs),
25
26    #[command(about = "Show content navigation graph")]
27    Journey(journey::JourneyArgs),
28}
29
30pub async fn execute(command: AnalyticsCommands, ctx: &CommandContext) -> Result<()> {
31    match command {
32        AnalyticsCommands::Clicks(args) => {
33            let result = clicks::execute(args, ctx)
34                .await
35                .context("Failed to get link clicks")?;
36            render_result(&result, &ctx.cli);
37        },
38        AnalyticsCommands::Campaign(args) => {
39            let result = campaign::execute(args, ctx)
40                .await
41                .context("Failed to get campaign analytics")?;
42            render_result(&result, &ctx.cli);
43        },
44        AnalyticsCommands::Journey(args) => {
45            let result = journey::execute(args, ctx)
46                .await
47                .context("Failed to get content journey")?;
48            render_result(&result, &ctx.cli);
49        },
50    }
51    Ok(())
52}