Skip to main content

Overview

Subscription tracking helps you monitor your SaaS revenue metrics, understand user subscription behavior, and predict churn. The SDK provides automatic payment provider detection (Stripe, Paddle, Chargebee) and comprehensive subscription lifecycle tracking.

Quick Start

1

Identify Users with Subscription Data

When users sign up or subscribe, identify them with subscription properties:
2

Track Subscription Events

Track lifecycle events as they happen:
3

Monitor Churn Risk

Use built-in churn prediction to identify at-risk users:

Subscription Properties

PCI Compliance: Never store full credit card numbers. Only use payment_method_last4 (last 4 digits). The SDK automatically validates and truncates card data.

Automatic Provider Detection

The SDK can auto-detect subscription data from Stripe, Paddle, and Chargebee by scanning browser globals and localStorage.

How It Works

From src/subscription-detection.ts:412-431:

Detection Confidence

Each provider detection returns a confidence score (0-100):
  • 30+: Provider SDK loaded (e.g., window.Stripe)
  • 50+: Found provider-specific localStorage keys
  • 70+: Extracted subscription data from localStorage
  • 100: Full subscription details including pricing

Stripe Detection

From src/subscription-detection.ts:29-166, the SDK checks:
  1. window.Stripe object present (+30 confidence)
  2. LocalStorage keys containing “stripe”, “customer_id”, “subscription_id” (+20)
  3. Subscription object with plan data (+30)
  4. Valid customer ID starting with cus_ (+10)

When Detection Runs

From src/analytics.ts:1377-1434, auto-detection runs:
  • 1 second after SDK initialization (allows provider SDKs to load)
  • Only in browser environments (window exists)
  • Results merged with manually-set subscription data (manual takes precedence)

Subscription Lifecycle Events

Track Subscription Started

Track Trial Started

Track Upgrades

Track Downgrades

Track Cancellations

Track Payment Events

Churn Risk Prediction

The SDK calculates churn risk based on user behavior:

Churn Risk Factors

From src/analytics.ts:630-720, risk is calculated using:

Risk Calculation

  • Engagement Score < 20: +30 risk points
  • Inactive > 30 days: +40 risk points
  • Feature Adoption < 20%: +15 risk points
  • Support Tickets > 5: +10 risk points
  • Negative Feedback > 3: +20 risk points
  • Payment Failures > 2: +30 risk points
Risk Categories:
  • Low: 0-24 (healthy user)
  • Medium: 25-49 (monitor)
  • High: 50-74 (intervention needed)
  • Critical: 75-100 (immediate action)

Revenue Metrics

Track MRR/ARR

The SDK automatically calculates ARR from MRR and vice versa:

Get Current Subscription

Auto-Enrichment

All events are automatically enriched with subscription context: From src/analytics.ts:1141-1166:
This means every event automatically includes:
  • subscription_status
  • subscription_plan
  • subscription_mrr
  • subscription_provider
  • is_paid_user

Use Cases

Stripe Integration

Retention Campaigns

Best Practices

Subscription Tracking Tips:
  • Always use cents for monetary amounts (9900 = $99.00)
  • Track all lifecycle events (start, upgrade, downgrade, cancel)
  • Include cancellation reasons for analysis
  • Monitor churn risk and intervene early
  • Segment users by plan tier for targeted campaigns
  • Never log full credit card numbers (PCI compliance)
  • Use auto-detection for faster integration

Troubleshooting

Auto-Detection Not Working

  1. Check payment provider SDK is loaded (e.g., window.Stripe)
  2. Verify subscription data is in localStorage
  3. Enable debug mode: config.debug = true
  4. Wait 1 second after page load for detection to run

Subscription Data Not Persisting

Subscription data is stored in localStorage. If not persisting:
  1. Check browser allows localStorage
  2. Verify you’re calling identify() with subscription data
  3. Check for localStorage quota errors

Revenue Metrics Incorrect

Ensure you’re using cents, not dollars: