Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Instrument self-hosted billing conversion stages

rcourtmanc20766b7b8d3
diff --git a/docs/release-control/v6/internal/subsystems/cloud-paid.md b/docs/release-control/v6/internal/subsystems/cloud-paid.md
index 1aee2cbbef..aff250b0dd 100644
--- a/docs/release-control/v6/internal/subsystems/cloud-paid.md
+++ b/docs/release-control/v6/internal/subsystems/cloud-paid.md
@@ -318,6 +318,16 @@ Insights`, rather than reviving generic `AI Patrol` or `AI ... analysis`
warning-banner payloads are built, while leaving non-community plan labels
available for bounded hosted or legacy continuity contracts that still
carry explicit monitored-system ceilings.
+12. Keep self-hosted commercial funnel stage ownership explicit:
+ `pkg/licensing/conversion_events.go`,
+ `pkg/licensing/conversion_store.go`, and
+ `frontend-modern/src/utils/upgradeMetrics.ts` own in-app `Plans & Billing`
+ stage events such as `pricing_viewed` and `checkout_clicked`, while
+ `pulse-pro:license-server/v6_checkout.go` owns the Pulse Account handoff
+ equivalents bound to `portal_handoff_id`. Pulse must not infer those
+ portal stages from referrer state, and the commercial service must keep
+ those self-hosted handoffs on release track `v6` even while the public
+ site remains on `v5` before GA.
## Current State
@@ -1550,6 +1560,18 @@ feature/limit primitives, billing and entitlement type shapes, commercial
migration and trial flow, conversion telemetry, host lifecycle tracking, and
public-key/build-mode boundaries should all resolve through explicit proof
routes rather than a package-wide `pkg/licensing/` fallback.
+That same conversion-telemetry boundary now treats self-hosted commercial
+progression as explicit stage events instead of inferring everything from
+backend completion. `pkg/licensing/conversion_events.go`,
+`pkg/licensing/conversion_store.go`, and
+`frontend-modern/src/utils/upgradeMetrics.ts` own local `pricing_viewed` and
+`checkout_clicked` events for the in-app `Plans & Billing` plan surface, while
+`pulse-pro:license-server/v6_checkout.go` owns the Pulse Account handoff
+equivalents bound to `portal_handoff_id` and the canonical checkout intent.
+The browser app must not try to recreate those Pulse Account stages from
+referrer state, and the commercial service must not collapse self-hosted v6
+handoffs back onto the public-site release track when production public GA is
+still on v5.
Stripe checkout and subscription webhook persistence now also follows the
canonical Cloud/MSP limit rule: when paid state is granted, billing-state
writes must persist authoritative `limits.max_monitored_systems` derived from canonical
diff --git a/frontend-modern/src/components/Settings/ProLicensePanel.tsx b/frontend-modern/src/components/Settings/ProLicensePanel.tsx
index 34ac0a369b..90bf77d352 100644
--- a/frontend-modern/src/components/Settings/ProLicensePanel.tsx
+++ b/frontend-modern/src/components/Settings/ProLicensePanel.tsx
@@ -113,7 +113,9 @@ const ProLicensePanelContent: Component = () => {
monitoredSystemContinuityNotice={state.monitoredSystemContinuityNotice()}
onReload={() => void state.loadPanelData()}
planSelectionPrompt={state.planSelectionPrompt()}
+ onPlanSelectionPromptClick={state.handlePlanSelectionPromptClick}
purchaseActivationAction={state.purchaseActivationAction()}
+ onPurchaseActivationActionClick={state.handlePurchaseActivationActionClick}
purchaseActivationNotice={state.purchaseActivationNotice()}
statusPresentation={state.statusPresentation()}
trialActivationNotice={state.trialActivationNotice()}
diff --git a/frontend-modern/src/components/Settings/ProLicensePlanSection.tsx b/frontend-modern/src/components/Settings/ProLicensePlanSection.tsx
index fad7aadcbd..2f52335d36 100644
--- a/frontend-modern/src/components/Settings/ProLicensePlanSection.tsx
+++ b/frontend-modern/src/components/Settings/ProLicensePlanSection.tsx
@@ -53,11 +53,13 @@ interface ProLicensePlanSectionProps {
monitoredSystemContinuityNotice: Notice | null;
onReload: () => void;
planSelectionPrompt: ActionNotice | null;
+ onPlanSelectionPromptClick: () => void;
purchaseActivationNotice: Notice | null;
purchaseActivationAction: {
label: string;
destination: UpgradeDestination;
} | null;
+ onPurchaseActivationActionClick: () => void;
statusPresentation: {
badgeClass: string;
label: string;
@@ -88,6 +90,7 @@ export const ProLicensePlanSection: Component<ProLicensePlanSectionProps> = (pro
<UpgradeLink
class="inline-flex items-center gap-1 mt-3 min-h-10 sm:min-h-9 rounded-md border border-current/20 px-3 py-2 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
destination={action().destination}
+ onClick={props.onPurchaseActivationActionClick}
>
{action().label}
</UpgradeLink>
@@ -104,6 +107,7 @@ export const ProLicensePlanSection: Component<ProLicensePlanSectionProps> = (pro
<UpgradeLink
class="inline-flex items-center gap-1 mt-3 min-h-10 sm:min-h-9 rounded-md border border-current/20 px-3 py-2 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
destination={prompt().actionDestination}
+ onClick={props.onPlanSelectionPromptClick}
>
{prompt().actionLabel}
</UpgradeLink>
diff --git a/frontend-modern/src/components/Settings/__tests__/ProLicensePanel.test.tsx b/frontend-modern/src/components/Settings/__tests__/ProLicensePanel.test.tsx
index 553ebecfe4..2d8b963483 100644
--- a/frontend-modern/src/components/Settings/__tests__/ProLicensePanel.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/ProLicensePanel.test.tsx
@@ -28,6 +28,8 @@ import {
let mockEntitlements: LicenseEntitlements | null = null;
+const trackPricingViewedMock = vi.fn();
+const trackCheckoutClickedMock = vi.fn();
const loadRuntimeLicenseStatusMock = vi.fn();
const loadCommercialPostureMock = vi.fn();
const loadLicenseEntitlementsMock = vi.fn();
@@ -94,6 +96,11 @@ vi.mock('@/stores/notifications', () => ({
},
}));
+vi.mock('@/utils/upgradeMetrics', () => ({
+ trackPricingViewed: (...args: unknown[]) => trackPricingViewedMock(...args),
+ trackCheckoutClicked: (...args: unknown[]) => trackCheckoutClickedMock(...args),
+}));
+
describe('ProLicensePanel', () => {
const renderPanel = () =>
render(() => (
@@ -115,6 +122,8 @@ describe('ProLicensePanel', () => {
loadRuntimeLicenseStatusMock.mockReset();
loadCommercialPostureMock.mockReset();
loadLicenseEntitlementsMock.mockReset();
+ trackPricingViewedMock.mockReset();
+ trackCheckoutClickedMock.mockReset();
licenseEntitlementsLoadErrorMock.mockReset();
startProTrialMock.mockReset();
activateLicenseMock.mockReset();
@@ -208,6 +217,10 @@ describe('ProLicensePanel', () => {
});
expect(screen.getAllByText('Compare self-hosted plans').length).toBeGreaterThan(0);
+ expect(trackPricingViewedMock).toHaveBeenCalledWith(
+ 'settings_self_hosted_billing_plan',
+ SELF_HOSTED_PRO_BILLING_PLAN_SELECTION_INTENT,
+ );
expect(screen.getByText(/Community keeps monitoring free/i)).toBeInTheDocument();
const compareLinks = screen.getAllByRole('link', { name: 'Compare plans' });
expect(
@@ -219,6 +232,21 @@ describe('ProLicensePanel', () => {
).toBe(true);
});
+ it('tracks compare-plan checkout intent from the self-hosted billing prompt', async () => {
+ renderPanel();
+
+ await waitFor(() => {
+ expect(loadLicenseEntitlementsMock).toHaveBeenCalled();
+ });
+
+ await fireEvent.click(screen.getAllByRole('link', { name: 'Compare plans' })[0]);
+
+ expect(trackCheckoutClickedMock).toHaveBeenCalledWith(
+ 'settings_self_hosted_billing_compare_prompt',
+ SELF_HOSTED_PRO_BILLING_PLAN_SELECTION_INTENT,
+ );
+ });
+
it('hides start trial action and shows trial-ended banner when trial was already used', async () => {
mockEntitlements = {
capabilities: [],
diff --git a/frontend-modern/src/components/Settings/useProLicensePanelState.ts b/frontend-modern/src/components/Settings/useProLicensePanelState.ts
index f041618b64..440505b3ad 100644
--- a/frontend-modern/src/components/Settings/useProLicensePanelState.ts
+++ b/frontend-modern/src/components/Settings/useProLicensePanelState.ts
@@ -46,6 +46,7 @@ import {
SELF_HOSTED_PRO_BILLING_PURCHASE_QUERY_PARAM,
SELF_HOSTED_PRO_BILLING_USAGE_HREF,
SELF_HOSTED_PRO_BILLING_USAGE_ROUTE,
+ isSelfHostedPurchaseStartDestination,
type SelfHostedBillingPlanIntent,
type SelfHostedBillingSection,
} from '@/utils/pricingHandoff';
@@ -58,6 +59,7 @@ import {
resolveMonitoredSystemCapacityStatus,
} from '@/utils/monitoredSystemPresentation';
import { runStartProTrialAction } from '@/utils/trialStartAction';
+import { trackCheckoutClicked, trackPricingViewed } from '@/utils/upgradeMetrics';
import { resolveUpgradeDestination, type UpgradeDestination } from '@/utils/upgradeNavigation';
import { SELF_HOSTED_PRO_BILLING_PRESENTATION } from './selfHostedBillingPresentation';
@@ -199,6 +201,20 @@ export function useProLicensePanelState() {
navigate(SELF_HOSTED_PRO_BILLING_PLAN_ROUTE, { replace: true, scroll: false });
});
+ let trackedPlanPricingView = false;
+ createEffect(() => {
+ const planVisible = panelDataSettled() && activeSection() === 'plan';
+ if (!planVisible) {
+ trackedPlanPricingView = false;
+ return;
+ }
+ if (trackedPlanPricingView) {
+ return;
+ }
+ trackPricingViewed('settings_self_hosted_billing_plan', SELF_HOSTED_PRO_BILLING_PLAN_SELECTION_INTENT);
+ trackedPlanPricingView = true;
+ });
+
const setActiveSection = (section: string) => {
if (section !== 'plan' && section !== 'usage') {
return;
@@ -261,6 +277,13 @@ export function useProLicensePanelState() {
};
});
+ const handlePlanSelectionPromptClick = () => {
+ trackCheckoutClicked(
+ 'settings_self_hosted_billing_compare_prompt',
+ SELF_HOSTED_PRO_BILLING_PLAN_SELECTION_INTENT,
+ );
+ };
+
const showTrialStart = createMemo(() => {
const current = entitlements();
if (!current) return false;
@@ -479,6 +502,17 @@ export function useProLicensePanelState() {
}
});
+ const handlePurchaseActivationActionClick = () => {
+ const action = purchaseActivationAction();
+ if (!action || !isSelfHostedPurchaseStartDestination(action.destination.href)) {
+ return;
+ }
+ trackCheckoutClicked(
+ 'settings_self_hosted_billing_purchase_return',
+ purchaseActivationIntent() ?? SELF_HOSTED_PRO_BILLING_PLAN_SELECTION_INTENT,
+ );
+ };
+
const commercialMigrationNotice = createMemo(() =>
getCommercialMigrationNotice(entitlements()?.commercial_migration),
);
@@ -602,8 +636,10 @@ export function useProLicensePanelState() {
loading,
looksLikeLegacyLicenseKey,
planSelectionPrompt,
+ handlePlanSelectionPromptClick,
purchaseActivationNotice,
purchaseActivationAction,
+ handlePurchaseActivationActionClick,
setActiveSection,
setLicenseKey,
showUsageSection,
diff --git a/frontend-modern/src/utils/__tests__/upgradeMetrics.test.ts b/frontend-modern/src/utils/__tests__/upgradeMetrics.test.ts
index fb87111fdc..37777da5d7 100644
--- a/frontend-modern/src/utils/__tests__/upgradeMetrics.test.ts
+++ b/frontend-modern/src/utils/__tests__/upgradeMetrics.test.ts
@@ -9,6 +9,8 @@ vi.mock('@/utils/apiClient', () => ({
}));
import {
+ trackCheckoutClicked,
+ trackPricingViewed,
trackAgentFirstConnected,
trackAgentInstallCommandCopied,
trackAgentInstallProfileSelected,
@@ -47,4 +49,17 @@ describe('upgradeMetrics local-only UX metrics wrappers', () => {
expect(apiFetchMock).toHaveBeenCalledTimes(1);
});
+
+ it('sends canonical pricing and checkout funnel events for self-hosted billing surfaces', () => {
+ trackPricingViewed('settings_self_hosted_billing_plan', 'self_hosted_plan');
+ trackCheckoutClicked('settings_self_hosted_billing_compare_prompt', 'self_hosted_plan');
+
+ expect(apiFetchMock).toHaveBeenCalledTimes(2);
+ expect(getPayloadForCall(0).type).toBe('pricing_viewed');
+ expect(getPayloadForCall(0).surface).toBe('settings_self_hosted_billing_plan');
+ expect(getPayloadForCall(0).capability).toBe('self_hosted_plan');
+ expect(getPayloadForCall(1).type).toBe('checkout_clicked');
+ expect(getPayloadForCall(1).surface).toBe('settings_self_hosted_billing_compare_prompt');
+ expect(getPayloadForCall(1).capability).toBe('self_hosted_plan');
+ });
});
diff --git a/frontend-modern/src/utils/upgradeMetrics.ts b/frontend-modern/src/utils/upgradeMetrics.ts
index 96fe15c40f..89afdf4eeb 100644
--- a/frontend-modern/src/utils/upgradeMetrics.ts
+++ b/frontend-modern/src/utils/upgradeMetrics.ts
@@ -15,10 +15,12 @@ export interface UpgradeMetricEvent {
}
export const UPGRADE_METRIC_EVENTS = {
+ PRICING_VIEWED: 'pricing_viewed',
PAYWALL_VIEWED: 'paywall_viewed',
TRIAL_STARTED: 'trial_started',
LICENSE_ACTIVATED: 'license_activated',
UPGRADE_CLICKED: 'upgrade_clicked',
+ CHECKOUT_CLICKED: 'checkout_clicked',
LIMIT_WARNING_SHOWN: 'limit_warning_shown',
LIMIT_BLOCKED: 'limit_blocked',
AGENT_INSTALL_TOKEN_GENERATED: 'agent_install_token_generated',
@@ -99,6 +101,14 @@ export function trackPaywallViewed(capability: string, surface: string): void {
});
}
+export function trackPricingViewed(surface: string, capability?: string): void {
+ trackUpgradeMetricEvent({
+ type: UPGRADE_METRIC_EVENTS.PRICING_VIEWED,
+ surface,
+ capability,
+ });
+}
+
export function trackUpgradeClicked(surface: string, capability?: string): void {
trackUpgradeMetricEvent({
type: UPGRADE_METRIC_EVENTS.UPGRADE_CLICKED,
@@ -107,6 +117,14 @@ export function trackUpgradeClicked(surface: string, capability?: string): void
});
}
+export function trackCheckoutClicked(surface: string, capability?: string): void {
+ trackUpgradeMetricEvent({
+ type: UPGRADE_METRIC_EVENTS.CHECKOUT_CLICKED,
+ surface,
+ capability,
+ });
+}
+
export function trackAgentInstallTokenGenerated(surface: string, capability?: string): void {
trackUpgradeMetricEvent({
type: UPGRADE_METRIC_EVENTS.AGENT_INSTALL_TOKEN_GENERATED,
diff --git a/internal/api/conversion_handlers_test.go b/internal/api/conversion_handlers_test.go
index 0a2d4f02d2..c934d04e9c 100644
--- a/internal/api/conversion_handlers_test.go
+++ b/internal/api/conversion_handlers_test.go
@@ -542,10 +542,14 @@ func TestConversionHandleConversionFunnelAggregatesPerOrg(t *testing.T) {
}
}
+ post("org-a", fmt.Sprintf(`{"type":"pricing_viewed","capability":"self_hosted_plan","surface":"settings_self_hosted_billing_plan","timestamp":%d,"idempotency_key":"a:prv:1"}`, now.UnixMilli()))
post("org-a", fmt.Sprintf(`{"type":"paywall_viewed","capability":"long_term_metrics","surface":"history_chart","timestamp":%d,"idempotency_key":"a:pv:1"}`, now.UnixMilli()))
post("org-a", fmt.Sprintf(`{"type":"trial_started","surface":"license_panel","timestamp":%d,"idempotency_key":"a:ts:1"}`, now.UnixMilli()))
post("org-a", fmt.Sprintf(`{"type":"upgrade_clicked","capability":"relay","surface":"paywall_modal","timestamp":%d,"idempotency_key":"a:uc:1"}`, now.UnixMilli()))
+ post("org-a", fmt.Sprintf(`{"type":"checkout_clicked","capability":"self_hosted_plan","surface":"settings_self_hosted_billing_compare_prompt","timestamp":%d,"idempotency_key":"a:ck:1"}`, now.UnixMilli()))
+ post("org-a", fmt.Sprintf(`{"type":"checkout_started","surface":"license_api","timestamp":%d,"idempotency_key":"a:cs:1"}`, now.UnixMilli()))
post("org-a", fmt.Sprintf(`{"type":"checkout_completed","surface":"stripe_return","timestamp":%d,"idempotency_key":"a:cc:1"}`, now.UnixMilli()))
+ post("org-a", fmt.Sprintf(`{"type":"license_activated","surface":"license_api","timestamp":%d,"idempotency_key":"a:la:1"}`, now.UnixMilli()))
post("org-b", fmt.Sprintf(`{"type":"paywall_viewed","capability":"relay","surface":"mobile_onboarding","timestamp":%d,"idempotency_key":"b:pv:1"}`, now.UnixMilli()))
from := now.Add(-1 * time.Hour)
@@ -568,6 +572,9 @@ func TestConversionHandleConversionFunnelAggregatesPerOrg(t *testing.T) {
if err := json.NewDecoder(rec.Body).Decode(&summary); err != nil {
t.Fatalf("failed decoding response: %v", err)
}
+ if summary.PricingViewed != 1 {
+ t.Fatalf("PricingViewed = %d, want 1", summary.PricingViewed)
+ }
if summary.PaywallViewed != 1 {
t.Fatalf("PaywallViewed = %d, want 1", summary.PaywallViewed)
}
@@ -577,9 +584,18 @@ func TestConversionHandleConversionFunnelAggregatesPerOrg(t *testing.T) {
if summary.UpgradeClicked != 1 {
t.Fatalf("UpgradeClicked = %d, want 1", summary.UpgradeClicked)
}
+ if summary.CheckoutClicked != 1 {
+ t.Fatalf("CheckoutClicked = %d, want 1", summary.CheckoutClicked)
+ }
+ if summary.CheckoutStarted != 1 {
+ t.Fatalf("CheckoutStarted = %d, want 1", summary.CheckoutStarted)
+ }
if summary.CheckoutCompleted != 1 {
t.Fatalf("CheckoutCompleted = %d, want 1", summary.CheckoutCompleted)
}
+ if summary.LicenseActivated != 1 {
+ t.Fatalf("LicenseActivated = %d, want 1", summary.LicenseActivated)
+ }
reqAll := httptest.NewRequest(http.MethodGet, "/api/admin/upgrade-metrics-funnel", nil)
reqAll = reqAll.WithContext(context.WithValue(reqAll.Context(), OrgIDContextKey, "org-a"))
diff --git a/internal/license/conversion/events.go b/internal/license/conversion/events.go
index 0ca816ee1a..a748a97b86 100644
--- a/internal/license/conversion/events.go
+++ b/internal/license/conversion/events.go
@@ -3,11 +3,13 @@ package conversion
import pkglicensing "github.com/rcourtman/pulse-go-rewrite/pkg/licensing"
const (
+ EventPricingViewed = pkglicensing.EventPricingViewed
EventPaywallViewed = pkglicensing.EventPaywallViewed
EventTrialStarted = pkglicensing.EventTrialStarted
EventLicenseActivated = pkglicensing.EventLicenseActivated
EventLicenseActivationFailed = pkglicensing.EventLicenseActivationFailed
EventUpgradeClicked = pkglicensing.EventUpgradeClicked
+ EventCheckoutClicked = pkglicensing.EventCheckoutClicked
EventCheckoutStarted = pkglicensing.EventCheckoutStarted
EventCheckoutCompleted = pkglicensing.EventCheckoutCompleted
EventLimitWarningShown = pkglicensing.EventLimitWarningShown
diff --git a/internal/license/conversion/events_test.go b/internal/license/conversion/events_test.go
index 02cdae101e..d25575770d 100644
--- a/internal/license/conversion/events_test.go
+++ b/internal/license/conversion/events_test.go
@@ -49,6 +49,26 @@ func TestConversionEventValidate(t *testing.T) {
event: ConversionEvent{Type: EventPaywallViewed, Surface: "dashboard", Timestamp: now, IdempotencyKey: "id-1"},
wantError: "capability is required",
},
+ {
+ name: "valid pricing viewed event",
+ event: ConversionEvent{
+ Type: EventPricingViewed,
+ Surface: "settings_self_hosted_billing_plan",
+ Capability: "self_hosted_plan",
+ Timestamp: now,
+ IdempotencyKey: "id-pricing-viewed-1",
+ },
+ },
+ {
+ name: "valid checkout clicked event",
+ event: ConversionEvent{
+ Type: EventCheckoutClicked,
+ Surface: "settings_self_hosted_billing_compare_prompt",
+ Capability: "self_hosted_plan",
+ Timestamp: now,
+ IdempotencyKey: "id-checkout-clicked-1",
+ },
+ },
{
name: "limit warning requires limit key",
event: ConversionEvent{Type: EventLimitWarningShown, Surface: "dashboard", Timestamp: now, IdempotencyKey: "id-1"},
diff --git a/internal/license/conversion/store_test.go b/internal/license/conversion/store_test.go
index 70dbf359e9..ac6fb5a6ee 100644
--- a/internal/license/conversion/store_test.go
+++ b/internal/license/conversion/store_test.go
@@ -133,11 +133,16 @@ func TestConversionStoreFunnelSummaryAggregation(t *testing.T) {
to := from.Add(2 * time.Hour)
events := []StoredConversionEvent{
+ {OrgID: "org-a", EventType: EventPricingViewed, Surface: "s0", Capability: "self_hosted_plan", IdempotencyKey: "k0", CreatedAt: from.Add(30 * time.Second)},
{OrgID: "org-a", EventType: EventPaywallViewed, Surface: "s1", Capability: "c1", IdempotencyKey: "k1", CreatedAt: from.Add(1 * time.Minute)},
{OrgID: "org-a", EventType: EventPaywallViewed, Surface: "s1", Capability: "c1", IdempotencyKey: "k2", CreatedAt: from.Add(2 * time.Minute)},
{OrgID: "org-a", EventType: EventTrialStarted, Surface: "s2", Capability: "", IdempotencyKey: "k3", CreatedAt: from.Add(3 * time.Minute)},
{OrgID: "org-a", EventType: EventUpgradeClicked, Surface: "s3", Capability: "relay", IdempotencyKey: "k4", CreatedAt: from.Add(4 * time.Minute)},
- {OrgID: "org-a", EventType: EventCheckoutCompleted, Surface: "s4", Capability: "", IdempotencyKey: "k5", CreatedAt: from.Add(5 * time.Minute)},
+ {OrgID: "org-a", EventType: EventCheckoutClicked, Surface: "s4", Capability: "self_hosted_plan", IdempotencyKey: "k5", CreatedAt: from.Add(5 * time.Minute)},
+ {OrgID: "org-a", EventType: EventCheckoutStarted, Surface: "s5", Capability: "", IdempotencyKey: "k6", CreatedAt: from.Add(6 * time.Minute)},
+ {OrgID: "org-a", EventType: EventCheckoutCompleted, Surface: "s6", Capability: "", IdempotencyKey: "k7", CreatedAt: from.Add(7 * time.Minute)},
+ {OrgID: "org-a", EventType: EventLicenseActivated, Surface: "s7", Capability: "", IdempotencyKey: "k8", CreatedAt: from.Add(8 * time.Minute)},
+ {OrgID: "org-a", EventType: EventLicenseActivationFailed, Surface: "s8", Capability: "", IdempotencyKey: "k9", CreatedAt: from.Add(9 * time.Minute)},
}
for _, ev := range events {
if err := store.Record(ev); err != nil {
@@ -152,15 +157,30 @@ func TestConversionStoreFunnelSummaryAggregation(t *testing.T) {
if summary.PaywallViewed != 2 {
t.Fatalf("PaywallViewed = %d, want 2", summary.PaywallViewed)
}
+ if summary.PricingViewed != 1 {
+ t.Fatalf("PricingViewed = %d, want 1", summary.PricingViewed)
+ }
if summary.TrialStarted != 1 {
t.Fatalf("TrialStarted = %d, want 1", summary.TrialStarted)
}
if summary.UpgradeClicked != 1 {
t.Fatalf("UpgradeClicked = %d, want 1", summary.UpgradeClicked)
}
+ if summary.CheckoutClicked != 1 {
+ t.Fatalf("CheckoutClicked = %d, want 1", summary.CheckoutClicked)
+ }
+ if summary.CheckoutStarted != 1 {
+ t.Fatalf("CheckoutStarted = %d, want 1", summary.CheckoutStarted)
+ }
if summary.CheckoutCompleted != 1 {
t.Fatalf("CheckoutCompleted = %d, want 1", summary.CheckoutCompleted)
}
+ if summary.LicenseActivated != 1 {
+ t.Fatalf("LicenseActivated = %d, want 1", summary.LicenseActivated)
+ }
+ if summary.LicenseActivationFailed != 1 {
+ t.Fatalf("LicenseActivationFailed = %d, want 1", summary.LicenseActivationFailed)
+ }
if !summary.Period.From.Equal(from.UTC()) || !summary.Period.To.Equal(to.UTC()) {
t.Fatalf("Period = %v..%v, want %v..%v", summary.Period.From, summary.Period.To, from.UTC(), to.UTC())
}
diff --git a/pkg/licensing/conversion_events.go b/pkg/licensing/conversion_events.go
index 0711d47061..591c794111 100644
--- a/pkg/licensing/conversion_events.go
+++ b/pkg/licensing/conversion_events.go
@@ -6,11 +6,13 @@ import (
)
const (
+ EventPricingViewed = "pricing_viewed"
EventPaywallViewed = "paywall_viewed"
EventTrialStarted = "trial_started"
EventLicenseActivated = "license_activated"
EventLicenseActivationFailed = "license_activation_failed"
EventUpgradeClicked = "upgrade_clicked"
+ EventCheckoutClicked = "checkout_clicked"
EventCheckoutStarted = "checkout_started"
EventCheckoutCompleted = "checkout_completed"
EventLimitWarningShown = "limit_warning_shown"
@@ -22,11 +24,13 @@ const (
)
var supportedConversionEventTypes = map[string]struct{}{
+ EventPricingViewed: {},
EventPaywallViewed: {},
EventTrialStarted: {},
EventLicenseActivated: {},
EventLicenseActivationFailed: {},
EventUpgradeClicked: {},
+ EventCheckoutClicked: {},
EventCheckoutStarted: {},
EventCheckoutCompleted: {},
EventLimitWarningShown: {},
diff --git a/pkg/licensing/conversion_events_test.go b/pkg/licensing/conversion_events_test.go
index 95c5588f90..1fc2a8d44a 100644
--- a/pkg/licensing/conversion_events_test.go
+++ b/pkg/licensing/conversion_events_test.go
@@ -49,6 +49,26 @@ func TestConversionEventValidate(t *testing.T) {
event: ConversionEvent{Type: EventPaywallViewed, Surface: "dashboard", Timestamp: now, IdempotencyKey: "id-1"},
wantError: "capability is required",
},
+ {
+ name: "valid pricing viewed event",
+ event: ConversionEvent{
+ Type: EventPricingViewed,
+ Surface: "settings_self_hosted_billing_plan",
+ Capability: "self_hosted_plan",
+ Timestamp: now,
+ IdempotencyKey: "id-pricing-viewed-1",
+ },
+ },
+ {
+ name: "valid checkout clicked event",
+ event: ConversionEvent{
+ Type: EventCheckoutClicked,
+ Surface: "settings_self_hosted_billing_compare_prompt",
+ Capability: "self_hosted_plan",
+ Timestamp: now,
+ IdempotencyKey: "id-checkout-clicked-1",
+ },
+ },
{
name: "limit warning requires limit key",
event: ConversionEvent{Type: EventLimitWarningShown, Surface: "dashboard", Timestamp: now, IdempotencyKey: "id-1"},
diff --git a/pkg/licensing/conversion_store.go b/pkg/licensing/conversion_store.go
index 68ca2baff9..9d5f033560 100644
--- a/pkg/licensing/conversion_store.go
+++ b/pkg/licensing/conversion_store.go
@@ -34,11 +34,16 @@ type StoredConversionEvent struct {
}
type FunnelSummary struct {
- PaywallViewed int64 `json:"paywall_viewed"`
- TrialStarted int64 `json:"trial_started"`
- UpgradeClicked int64 `json:"upgrade_clicked"`
- CheckoutCompleted int64 `json:"checkout_completed"`
- Period struct {
+ PricingViewed int64 `json:"pricing_viewed"`
+ PaywallViewed int64 `json:"paywall_viewed"`
+ TrialStarted int64 `json:"trial_started"`
+ UpgradeClicked int64 `json:"upgrade_clicked"`
+ CheckoutClicked int64 `json:"checkout_clicked"`
+ CheckoutStarted int64 `json:"checkout_started"`
+ CheckoutCompleted int64 `json:"checkout_completed"`
+ LicenseActivated int64 `json:"license_activated"`
+ LicenseActivationFailed int64 `json:"license_activation_failed"`
+ Period struct {
From time.Time `json:"from"`
To time.Time `json:"to"`
} `json:"period"`
@@ -342,14 +347,24 @@ func (s *ConversionStore) FunnelSummary(orgID string, from, to time.Time) (summa
return nil, fmt.Errorf("failed to scan funnel summary row: %w", err)
}
switch strings.TrimSpace(eventType) {
+ case EventPricingViewed:
+ summary.PricingViewed = count
case EventPaywallViewed:
summary.PaywallViewed = count
case EventTrialStarted:
summary.TrialStarted = count
case EventUpgradeClicked:
summary.UpgradeClicked = count
+ case EventCheckoutClicked:
+ summary.CheckoutClicked = count
+ case EventCheckoutStarted:
+ summary.CheckoutStarted = count
case EventCheckoutCompleted:
summary.CheckoutCompleted = count
+ case EventLicenseActivated:
+ summary.LicenseActivated = count
+ case EventLicenseActivationFailed:
+ summary.LicenseActivationFailed = count
}
}
if err := rows.Err(); err != nil {