Analyticscli ts sdk

From LeoYeAI/openclaw-master-skills · View interactive version

Analyticscli ts sdk is an AI agent skill from the GitHub repository LeoYeAI/openclaw-master-skills. Use when integrating or upgrading the AnalyticsCLI TypeScript SDK in web, TypeScript, React Native, or Expo apps.

How to use this skill

Skill file

AnalyticsCLI TypeScript SDK

Use This Skill When

Supported Versions

See Versioning Notes.

Core Rules

RevenueCat: offering identifier; Adapty: paywall/placement identifier; Superwall: placement/paywall identifier.

Use one memoized createPaywallTracker(...) per screen/context and route lifecycle callbacks to tracker methods:

shown (visible), purchaseStarted, one terminal event (purchaseSuccess/purchaseFailed/purchaseCancel), and skip (dismiss/close/back).

createOnboardingTracker(...), trackOnboardingEvent(...), trackOnboardingSurveyResponse(...),

plus step helpers (step(...).view(), step(...).complete(), step(...).surveyResponse(...)).

Host App Minimalism Guardrails

When this skill writes host-app code, optimize for low boilerplate by default.

Hard Fail Patterns

Do not generate these patterns:

If such a pattern already exists in the target codebase:

Pre-Ship Self-Check

Before finishing, verify the generated integration code meets all checks:

  1. bootstrap uses init({ ... }) (no initFromEnv(...))
  2. no explicit endpoint env var in host app templates
  3. no large event translation layer added
  4. SDK APIs used directly at call sites for onboarding/paywall/purchase milestones
  5. identity uses SDK methods directly (identify/setUser/clearUser) without extra wrappers
  6. platform is web/ios/android/mac/windows or omitted (never framework labels)
  7. generated bootstrap sets identityTrackingMode explicitly (default 'consent_gated')
  8. paywall flow reuses a tracker instance per stable paywall context (no per-event tracker re-creation)
  9. host-app snippets only use publishable API key env names (no *WRITE_KEY* fallback)
  10. if provider exposes offering/paywall id, createPaywallTracker(...) defaults include offering
  11. exactly one screen-tracking owner exists per route transition
  12. touched onboarding/paywall/purchase call sites emit canonical AnalyticsCLI events only (no legacy aliases, no dual-write)
  13. every touched hosted paywall screen emits paywall:shown via tracker when shown becomes visible (not only screen-view events)
  14. every touched hosted paywall screen maps purchase lifecycle callbacks to tracker methods (purchaseStarted + exactly one terminal outcome)
  15. every touched paywall dismissal path (close/back/skip) emits tracker skip(...)
  16. touched onboarding step milestones use dedicated onboarding APIs (tracker step helpers or trackOnboardingEvent(...)) instead of generic track(...)
  17. touched onboarding survey milestones use trackOnboardingSurveyResponse(...) (or tracker survey helpers), not ad-hoc generic track(...) payloads
  18. touched React Native / Expo non-onboarding screens use useFocusEffect(...) + analytics.screen(...) with one owner per route transition
  19. touched onboarding flows do not force onboarding:step_complete on every step; default to onboarding:step_view and add step_complete only where completion semantics are explicit

Dashboard Credentials Checklist

Before SDK bootstrap, collect the required values from your dashboard:

Minimal Web Setup

import { init } from '@analyticscli/sdk';

const analytics = init({
  apiKey: process.env.NEXT_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY ?? '',
  platform: 'web',
  identityTrackingMode: 'consent_gated', // default
});

init(...) is preferred for host apps.

Resolve env values in app code and pass apiKey explicitly.

React Native Setup

import AsyncStorage from '@react-native-async-storage/async-storage';
import * as Application from 'expo-application';
import { Platform } from 'react-native';
import { init } from '@analyticscli/sdk';

const analytics = init({
  apiKey: process.env.EXPO_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY,
  debug: __DEV__,
  platform: Platform.OS,
  appVersion: Application.nativeApplicationVersion,
  identityTrackingMode: 'consent_gated', // default
  storage: AsyncStorage, // optional for RN if you want persistent IDs after consent
});

Consent gate for full tracking:

// user accepts full tracking
analytics.setFullTrackingConsent(true);

// user declines full tracking (strict analytics can continue)
analytics.setFullTrackingConsent(false);

There is no "do not start yet" init flag. Tracking starts on init(...); ready() (or initAsync(...)) is only for explicitly blocking first-flow logic until async storage hydration is done.

React Native Screen Tracking Pattern (Non-Onboarding)

Use useFocusEffect(...) for non-onboarding screens so screen views fire on route focus and not only on mount:

import { useFocusEffect } from '@react-navigation/native';
import { useCallback } from 'react';
import { analytics } from '@/utils/analytics';

export function SettingsScreen() {
  useFocusEffect(
    useCallback(() => {
      analytics.screen('settings', {
        screen_class: 'SettingsScreen',
        source: 'tabs',
      });
    }, []),
  );

  return null;
}

Notes:

Integration Depth Checklist

The integration should cover more than SDK bootstrap:

  1. onboarding flow boundaries and step progression
  2. paywall exposure, skip, purchase start, success, fail, cancel
  3. screen views for core routes/screens
  4. key product actions tied to user value (for example: first calibration complete, first result generated, export/share, restore purchases)
  5. stable context properties (appVersion, platform, source, flow identifiers)
  6. if using RevenueCat, correlate client-side paywall/purchase intent with server-side subscription lifecycle updates

RevenueCat + Analytics Sync (Trials & Subscriptions)

You can include trial/purchase/cancel lifecycle data inside user flows, but "perfectly synced in real time"

is not realistic because app callbacks, store billing events, retries, and webhook delivery are eventually consistent.

Use this pattern for near-lossless correlation:

  1. Single identity key across both systems
  1. Dual event streams
  1. Correlation keys on every relevant event
  1. Webhook idempotency is mandatory
  1. Model cancellation reasons explicitly

Recommended custom lifecycle events (in addition to canonical purchase:* journey events):

This split lets funnels answer both questions:

Instrumentation Rules

No-Legacy Policy

For pre-production integrations, do not preserve legacy compatibility by default:

  1. Remove legacy analytics providers from touched flows instead of dual-writing.
  2. Replace legacy/alias milestone names with canonical AnalyticsCLI events in the same change.
  3. Prefer dedicated SDK helpers (createOnboardingTracker(...), trackOnboardingSurveyResponse(...), createPaywallTracker(...)) over ad-hoc generic tracking wrappers.

Validation Loop

After integration or upgrade, verify ingestion with stable CLI checks:

analyticscli schema events
analyticscli goal-completion --start onboarding:start --complete onboarding:complete --last 30d
analyticscli get onboarding-journey --last 30d --format text

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.