rampkit-expo-dev 0.0.18 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ /**
3
+ * RampKit Device Info Collector
4
+ * Collects device information using native modules for the /app-users endpoint
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.getSessionStartTime = getSessionStartTime;
11
+ exports.getSessionDurationSeconds = getSessionDurationSeconds;
12
+ exports.collectDeviceInfo = collectDeviceInfo;
13
+ exports.resetSession = resetSession;
14
+ const react_native_1 = require("react-native");
15
+ const RampKitNative_1 = __importDefault(require("./RampKitNative"));
16
+ const constants_1 = require("./constants");
17
+ // Session-level data (regenerated each app launch)
18
+ let sessionId = null;
19
+ let sessionStartTime = null;
20
+ /**
21
+ * Get session start time
22
+ */
23
+ function getSessionStartTime() {
24
+ return sessionStartTime;
25
+ }
26
+ /**
27
+ * Get the current session duration in seconds
28
+ */
29
+ function getSessionDurationSeconds() {
30
+ if (!sessionStartTime)
31
+ return 0;
32
+ return Math.floor((Date.now() - sessionStartTime.getTime()) / 1000);
33
+ }
34
+ /**
35
+ * Collect all device information using native module
36
+ */
37
+ async function collectDeviceInfo() {
38
+ try {
39
+ // Get device info from native module
40
+ const nativeInfo = await RampKitNative_1.default.getDeviceInfo();
41
+ // Initialize session
42
+ sessionId = nativeInfo.appSessionId;
43
+ sessionStartTime = new Date();
44
+ // Map native info to DeviceInfo type
45
+ const deviceInfo = {
46
+ // User & Session Identifiers
47
+ appUserId: nativeInfo.appUserId,
48
+ vendorId: nativeInfo.vendorId,
49
+ appSessionId: nativeInfo.appSessionId,
50
+ // Launch Tracking
51
+ installDate: nativeInfo.installDate,
52
+ isFirstLaunch: nativeInfo.isFirstLaunch,
53
+ launchCount: nativeInfo.launchCount,
54
+ lastLaunchAt: nativeInfo.lastLaunchAt,
55
+ // App Info
56
+ bundleId: nativeInfo.bundleId,
57
+ appName: nativeInfo.appName,
58
+ appVersion: nativeInfo.appVersion,
59
+ buildNumber: nativeInfo.buildNumber,
60
+ sdkVersion: constants_1.SDK_VERSION,
61
+ // Platform Info
62
+ platform: mapPlatform(nativeInfo.platform),
63
+ platformVersion: nativeInfo.platformVersion,
64
+ platformWrapper: "Expo",
65
+ // Device Info
66
+ deviceModel: nativeInfo.deviceModel,
67
+ deviceName: nativeInfo.deviceName,
68
+ isSimulator: nativeInfo.isSimulator,
69
+ // Locale & Language
70
+ deviceLanguageCode: nativeInfo.deviceLanguageCode,
71
+ deviceLocale: nativeInfo.deviceLocale,
72
+ regionCode: nativeInfo.regionCode,
73
+ preferredLanguage: nativeInfo.preferredLanguage,
74
+ preferredLanguages: nativeInfo.preferredLanguages,
75
+ // Currency
76
+ deviceCurrencyCode: nativeInfo.deviceCurrencyCode,
77
+ deviceCurrencySymbol: nativeInfo.deviceCurrencySymbol,
78
+ // Timezone
79
+ timezoneIdentifier: nativeInfo.timezoneIdentifier,
80
+ timezoneOffsetSeconds: nativeInfo.timezoneOffsetSeconds,
81
+ // UI
82
+ interfaceStyle: mapInterfaceStyle(nativeInfo.interfaceStyle),
83
+ // Screen
84
+ screenWidth: nativeInfo.screenWidth,
85
+ screenHeight: nativeInfo.screenHeight,
86
+ screenScale: nativeInfo.screenScale,
87
+ // Device Status
88
+ isLowPowerMode: nativeInfo.isLowPowerMode,
89
+ // Storage (skip for performance)
90
+ freeStorageBytes: null,
91
+ totalStorageBytes: null,
92
+ // Memory
93
+ totalMemoryBytes: nativeInfo.totalMemoryBytes,
94
+ // Apple Search Ads (skip for performance)
95
+ isAppleSearchAdsAttribution: false,
96
+ appleSearchAdsToken: null,
97
+ // SDK Capabilities
98
+ capabilities: [...constants_1.CAPABILITIES],
99
+ // Network (could add later)
100
+ connectionType: null,
101
+ // Timestamp
102
+ collectedAt: nativeInfo.collectedAt,
103
+ };
104
+ console.log("[RampKit] DeviceInfo: Collected from native module");
105
+ return deviceInfo;
106
+ }
107
+ catch (error) {
108
+ console.warn("[RampKit] DeviceInfo: Failed to collect from native module", error);
109
+ // Return minimal fallback
110
+ return getFallbackDeviceInfo();
111
+ }
112
+ }
113
+ /**
114
+ * Map platform string to typed platform
115
+ */
116
+ function mapPlatform(platform) {
117
+ if (platform === "iPadOS")
118
+ return "iPadOS";
119
+ if (platform === "iOS")
120
+ return "iOS";
121
+ return "Android";
122
+ }
123
+ /**
124
+ * Map interface style string to typed style
125
+ */
126
+ function mapInterfaceStyle(style) {
127
+ if (style === "light")
128
+ return "light";
129
+ if (style === "dark")
130
+ return "dark";
131
+ return "unspecified";
132
+ }
133
+ /**
134
+ * Get fallback device info when native module fails
135
+ */
136
+ function getFallbackDeviceInfo() {
137
+ const now = new Date().toISOString();
138
+ const fallbackUserId = generateFallbackUuid();
139
+ sessionId = generateFallbackUuid();
140
+ sessionStartTime = new Date();
141
+ return {
142
+ appUserId: fallbackUserId,
143
+ vendorId: null,
144
+ appSessionId: sessionId,
145
+ installDate: now,
146
+ isFirstLaunch: true,
147
+ launchCount: 1,
148
+ lastLaunchAt: null,
149
+ bundleId: null,
150
+ appName: null,
151
+ appVersion: null,
152
+ buildNumber: null,
153
+ sdkVersion: constants_1.SDK_VERSION,
154
+ platform: react_native_1.Platform.OS === "ios" ? "iOS" : "Android",
155
+ platformVersion: String(react_native_1.Platform.Version),
156
+ platformWrapper: "Expo",
157
+ deviceModel: "unknown",
158
+ deviceName: "unknown",
159
+ isSimulator: false,
160
+ deviceLanguageCode: null,
161
+ deviceLocale: "en_US",
162
+ regionCode: null,
163
+ preferredLanguage: null,
164
+ preferredLanguages: [],
165
+ deviceCurrencyCode: null,
166
+ deviceCurrencySymbol: null,
167
+ timezoneIdentifier: "UTC",
168
+ timezoneOffsetSeconds: new Date().getTimezoneOffset() * -60,
169
+ interfaceStyle: "unspecified",
170
+ screenWidth: 0,
171
+ screenHeight: 0,
172
+ screenScale: 1,
173
+ isLowPowerMode: false,
174
+ freeStorageBytes: null,
175
+ totalStorageBytes: null,
176
+ totalMemoryBytes: 0,
177
+ isAppleSearchAdsAttribution: false,
178
+ appleSearchAdsToken: null,
179
+ capabilities: [...constants_1.CAPABILITIES],
180
+ connectionType: null,
181
+ collectedAt: now,
182
+ };
183
+ }
184
+ /**
185
+ * Generate a fallback UUID
186
+ */
187
+ function generateFallbackUuid() {
188
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
189
+ const r = (Math.random() * 16) | 0;
190
+ const v = c === "x" ? r : (r & 0x3) | 0x8;
191
+ return v.toString(16);
192
+ });
193
+ }
194
+ /**
195
+ * Reset session (call when app is fully restarted)
196
+ */
197
+ function resetSession() {
198
+ sessionId = null;
199
+ sessionStartTime = null;
200
+ }
@@ -0,0 +1,155 @@
1
+ /**
2
+ * RampKit Event Manager
3
+ * Handles event tracking for the /app-user-events endpoint
4
+ */
5
+ import { DeviceInfo, EventContext, RampKitEventName } from "./types";
6
+ declare class EventManager {
7
+ private static _instance;
8
+ private appId;
9
+ private appUserId;
10
+ private sessionId;
11
+ private device;
12
+ private baseContext;
13
+ private currentScreenName;
14
+ private currentFlowId;
15
+ private currentVariantId;
16
+ private currentPaywallId;
17
+ private currentPlacement;
18
+ private onboardingStartTime;
19
+ private currentOnboardingId;
20
+ private initialized;
21
+ static get instance(): EventManager;
22
+ /**
23
+ * Initialize the event manager with device info
24
+ */
25
+ initialize(appId: string, deviceInfo: DeviceInfo): void;
26
+ /**
27
+ * Check if the event manager is initialized
28
+ */
29
+ isInitialized(): boolean;
30
+ /**
31
+ * Set current screen context
32
+ */
33
+ setCurrentScreen(screenName: string | null): void;
34
+ /**
35
+ * Set current flow context (e.g., onboarding flow ID)
36
+ */
37
+ setCurrentFlow(flowId: string | null, variantId?: string | null): void;
38
+ /**
39
+ * Set current paywall context
40
+ */
41
+ setCurrentPaywall(paywallId: string | null, placement?: string | null): void;
42
+ /**
43
+ * Start onboarding tracking
44
+ */
45
+ startOnboardingTracking(onboardingId: string): void;
46
+ /**
47
+ * Get onboarding duration in seconds
48
+ */
49
+ getOnboardingDurationSeconds(): number;
50
+ /**
51
+ * End onboarding tracking
52
+ */
53
+ endOnboardingTracking(): void;
54
+ /**
55
+ * Get current onboarding ID
56
+ */
57
+ getCurrentOnboardingId(): string | null;
58
+ /**
59
+ * Track an event
60
+ */
61
+ track(eventName: RampKitEventName | string, properties?: Record<string, any>, contextOverrides?: Partial<EventContext>): Promise<void>;
62
+ /**
63
+ * Send event to backend (fire and forget)
64
+ */
65
+ private sendEvent;
66
+ /**
67
+ * Track app session started
68
+ */
69
+ trackAppSessionStarted(isFirstLaunch: boolean, launchCount: number): void;
70
+ /**
71
+ * Track app backgrounded
72
+ */
73
+ trackAppBackgrounded(sessionDurationSeconds: number): void;
74
+ /**
75
+ * Track app foregrounded
76
+ */
77
+ trackAppForegrounded(): void;
78
+ /**
79
+ * Track screen view
80
+ */
81
+ trackScreenView(screenName: string, referrer?: string): void;
82
+ /**
83
+ * Track CTA tap
84
+ */
85
+ trackCtaTap(buttonId: string, buttonText?: string): void;
86
+ /**
87
+ * Track onboarding started
88
+ */
89
+ trackOnboardingStarted(onboardingId: string, totalSteps?: number): void;
90
+ /**
91
+ * Track onboarding screen viewed
92
+ */
93
+ trackOnboardingScreenViewed(screenName: string, screenIndex: number, totalScreens: number, onboardingId?: string): void;
94
+ /**
95
+ * Track onboarding question answered
96
+ */
97
+ trackOnboardingQuestionAnswered(questionId: string, answer: any, questionText?: string, onboardingId?: string): void;
98
+ /**
99
+ * Track onboarding completed
100
+ */
101
+ trackOnboardingCompleted(completedSteps: number, totalSteps: number, onboardingId?: string): void;
102
+ /**
103
+ * Track onboarding abandoned
104
+ */
105
+ trackOnboardingAbandoned(reason: string, lastScreenName?: string, onboardingId?: string): void;
106
+ /**
107
+ * Track notification prompt shown
108
+ */
109
+ trackNotificationsPromptShown(): void;
110
+ /**
111
+ * Track notification response
112
+ */
113
+ trackNotificationsResponse(status: "granted" | "denied" | "provisional"): void;
114
+ /**
115
+ * Track paywall shown
116
+ */
117
+ trackPaywallShown(paywallId: string, placement?: string, products?: Array<{
118
+ productId: string;
119
+ price?: number;
120
+ currency?: string;
121
+ }>): void;
122
+ /**
123
+ * Track paywall primary action tap
124
+ */
125
+ trackPaywallPrimaryActionTap(paywallId: string, productId?: string): void;
126
+ /**
127
+ * Track paywall closed
128
+ */
129
+ trackPaywallClosed(paywallId: string, reason: "dismissed" | "purchased" | "backgrounded"): void;
130
+ /**
131
+ * Track purchase started
132
+ */
133
+ trackPurchaseStarted(productId: string, amount?: number, currency?: string): void;
134
+ /**
135
+ * Track purchase completed
136
+ */
137
+ trackPurchaseCompleted(properties: {
138
+ productId: string;
139
+ amount: number;
140
+ currency: string;
141
+ transactionId: string;
142
+ originalTransactionId?: string;
143
+ purchaseDate?: string;
144
+ }): void;
145
+ /**
146
+ * Track purchase failed
147
+ */
148
+ trackPurchaseFailed(productId: string, errorCode: string, errorMessage: string): void;
149
+ /**
150
+ * Reset the event manager (e.g., on logout)
151
+ */
152
+ reset(): void;
153
+ }
154
+ export declare const eventManager: EventManager;
155
+ export { EventManager };