mobiqo-react-native 0.0.5

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Mobiqo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,196 @@
1
+ # Mobiqo React Native SDK
2
+
3
+ **⚠️ THIS PLUGIN HAS TO BE USED ALONG WITH THE ANALYTICS SERVICE MOBIQO ⚠️**
4
+
5
+ **👉 CREATE AN ACCOUNT HERE: https://getmobiqo.com?utm_source=npm**
6
+
7
+ ---
8
+
9
+ A React Native library for integrating Mobiqo analytics into your mobile applications.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install mobiqo-react-native
15
+ ```
16
+
17
+ ### Peer Dependencies
18
+
19
+ This library requires `@react-native-async-storage/async-storage` as a peer dependency. Install it separately:
20
+
21
+ ```bash
22
+ npm install @react-native-async-storage/async-storage
23
+ ```
24
+
25
+ For iOS, you'll also need to run:
26
+
27
+ ```bash
28
+ cd ios && pod install
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ### Import the SDK
34
+
35
+ ```typescript
36
+ import Mobiqo from 'mobiqo-react-native';
37
+ import { EventType } from 'mobiqo-react-native';
38
+ ```
39
+
40
+ ### Initialize the service
41
+
42
+ ```typescript
43
+ const mobiqo = new Mobiqo();
44
+
45
+ // Initialize with your Mobiqo API key
46
+ await mobiqo.init({ mobiqoKey: 'your-mobiqo-api-key' });
47
+ ```
48
+
49
+ ### Sync user data
50
+
51
+ ```typescript
52
+ // With additional data (optional)
53
+ await mobiqo.syncUser({
54
+ revenue_cat_user_id: 'user-123',
55
+ additional_data: {
56
+ email: 'user@example.com',
57
+ plan: 'premium'
58
+ }
59
+ });
60
+
61
+ // Without additional data
62
+ await mobiqo.syncUser({
63
+ revenue_cat_user_id: 'user-123'
64
+ });
65
+ ```
66
+
67
+ ### Track events
68
+
69
+ ```typescript
70
+ // Track an event with additional data (optional)
71
+ await mobiqo.trackEvent(
72
+ 'button_clicked',
73
+ EventType.CLICK,
74
+ {
75
+ button_name: 'subscribe',
76
+ screen: 'home'
77
+ }
78
+ );
79
+
80
+ // Track an event without additional data
81
+ await mobiqo.trackEvent('screen_opened', EventType.SCREEN_VIEW);
82
+ ```
83
+
84
+ ### Get user information
85
+
86
+ ```typescript
87
+ const userInfo = await mobiqo.getUserInfo({
88
+ revenue_cat_user_id: 'user-123'
89
+ });
90
+ ```
91
+
92
+ ### Automatic Session Tracking
93
+
94
+ The SDK automatically sends heartbeats every 30 seconds after user sync to maintain session tracking. No manual intervention is required.
95
+
96
+ ## API Reference
97
+
98
+ ### Methods
99
+
100
+ #### `init(options)`
101
+ Initialize the Mobiqo service with your API key.
102
+ - `options.mobiqoKey` (string): Your Mobiqo API key
103
+
104
+ #### `syncUser(options)`
105
+ Sync user data with Mobiqo and start a session.
106
+ - `options.revenue_cat_user_id` (string): RevenueCat user ID
107
+ - `options.additional_data` (Record<string, any>, optional): Additional user data
108
+
109
+ #### `getUserInfo(options)`
110
+ Retrieve user information from Mobiqo.
111
+ - `options.revenue_cat_user_id` (string): RevenueCat user ID
112
+
113
+ #### `trackEvent(event, eventType, additionalData?)`
114
+ Track custom events.
115
+ - `event` (string): Event name
116
+ - `eventType` (EventType): Event type from the EventType enum
117
+ - `additionalData` (Record<string, any>, optional): Additional event data
118
+
119
+ ### Event Types
120
+
121
+ ```typescript
122
+ enum EventType {
123
+ CLICK = 'click',
124
+ ACTION = 'action',
125
+ SCREEN_VIEW = 'screen_view',
126
+ PAYWALL_VIEW = 'paywall_view',
127
+ PAYWALL_DISMISS = 'paywall_dismiss',
128
+ PURCHASE_ATTEMPT = 'purchase_attempt',
129
+ PURCHASE_SUCCESS = 'purchase_success',
130
+ FORM_SUBMIT = 'form_submit',
131
+ NAVIGATION = 'navigation',
132
+ ERROR = 'error',
133
+ CUSTOM = 'custom'
134
+ }
135
+ ```
136
+
137
+ ### Response Interfaces
138
+
139
+ #### `SyncUserResponse`
140
+ ```typescript
141
+ interface SyncUserResponse {
142
+ isNewUser: boolean;
143
+ appUser: AppUser;
144
+ statistics: Statistics;
145
+ }
146
+ ```
147
+
148
+ #### `GetUserInfoResponse`
149
+ ```typescript
150
+ interface GetUserInfoResponse {
151
+ appUser: AppUser;
152
+ statistics: Statistics;
153
+ }
154
+ ```
155
+
156
+ #### `AppUser`
157
+ ```typescript
158
+ interface AppUser {
159
+ id: string;
160
+ project_id: string;
161
+ revenue_cat_user_id?: string;
162
+ mobiqo_username: string;
163
+ os: 'ios' | 'android';
164
+ os_version: string;
165
+ app_version: string;
166
+ country?: string;
167
+ language?: string;
168
+ first_seen_at: string;
169
+ last_seen_at: string;
170
+ active_entitlements: string[];
171
+ }
172
+ ```
173
+
174
+ #### `Statistics`
175
+ ```typescript
176
+ interface Statistics {
177
+ purchasing_power_parity: number;
178
+ purchase_probability: number;
179
+ avg_arpu: number;
180
+ avg_arppu: number;
181
+ avg_ltv: number;
182
+ }
183
+ ```
184
+
185
+ ## Requirements
186
+
187
+ - React Native
188
+ - TypeScript 4.0+
189
+
190
+ ## License
191
+
192
+ MIT
193
+
194
+ ## Support
195
+
196
+ For support and questions, please contact the Mobiqo team.
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Event types for Mobiqo analytics tracking
3
+ *
4
+ * Use these predefined event types to categorize user interactions and behaviors.
5
+ * This helps with analytics reporting and filtering in the Mobiqo dashboard.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { EventType } from 'mobiqo-capacitor';
10
+ *
11
+ * // Track different types of events
12
+ * await mobiqo.trackEvent('subscribe_button', EventType.CLICK, { location: 'home' });
13
+ * await mobiqo.trackEvent('paywall_shown', EventType.PAYWALL_VIEW);
14
+ * ```
15
+ */
16
+ export declare enum EventType {
17
+ /** Button or UI element tapped/clicked */
18
+ CLICK = "click",
19
+ /** User performs an action */
20
+ ACTION = "action",
21
+ /** A screen/page is displayed to the user */
22
+ SCREEN_VIEW = "screen_view",
23
+ /** Paywall or subscription screen is shown */
24
+ PAYWALL_VIEW = "paywall_view",
25
+ /** User closes or dismisses paywall */
26
+ PAYWALL_DISMISS = "paywall_dismiss",
27
+ /** User initiates a purchase flow */
28
+ PURCHASE_ATTEMPT = "purchase_attempt",
29
+ /** In-app purchase completed successfully (if not using RevenueCat webhook) */
30
+ PURCHASE_SUCCESS = "purchase_success",
31
+ /** Form or input field submitted */
32
+ FORM_SUBMIT = "form_submit",
33
+ /** User navigates to another screen/section */
34
+ NAVIGATION = "navigation",
35
+ /** A handled error or issue occurred */
36
+ ERROR = "error",
37
+ /** Custom event type for user-defined cases */
38
+ CUSTOM = "custom"
39
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventType = void 0;
4
+ /**
5
+ * Event types for Mobiqo analytics tracking
6
+ *
7
+ * Use these predefined event types to categorize user interactions and behaviors.
8
+ * This helps with analytics reporting and filtering in the Mobiqo dashboard.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { EventType } from 'mobiqo-capacitor';
13
+ *
14
+ * // Track different types of events
15
+ * await mobiqo.trackEvent('subscribe_button', EventType.CLICK, { location: 'home' });
16
+ * await mobiqo.trackEvent('paywall_shown', EventType.PAYWALL_VIEW);
17
+ * ```
18
+ */
19
+ var EventType;
20
+ (function (EventType) {
21
+ /** Button or UI element tapped/clicked */
22
+ EventType["CLICK"] = "click";
23
+ /** User performs an action */
24
+ EventType["ACTION"] = "action";
25
+ /** A screen/page is displayed to the user */
26
+ EventType["SCREEN_VIEW"] = "screen_view";
27
+ /** Paywall or subscription screen is shown */
28
+ EventType["PAYWALL_VIEW"] = "paywall_view";
29
+ /** User closes or dismisses paywall */
30
+ EventType["PAYWALL_DISMISS"] = "paywall_dismiss";
31
+ /** User initiates a purchase flow */
32
+ EventType["PURCHASE_ATTEMPT"] = "purchase_attempt";
33
+ /** In-app purchase completed successfully (if not using RevenueCat webhook) */
34
+ EventType["PURCHASE_SUCCESS"] = "purchase_success";
35
+ /** Form or input field submitted */
36
+ EventType["FORM_SUBMIT"] = "form_submit";
37
+ /** User navigates to another screen/section */
38
+ EventType["NAVIGATION"] = "navigation";
39
+ /** A handled error or issue occurred */
40
+ EventType["ERROR"] = "error";
41
+ /** Custom event type for user-defined cases */
42
+ EventType["CUSTOM"] = "custom";
43
+ })(EventType || (exports.EventType = EventType = {}));
@@ -0,0 +1,209 @@
1
+ import { EventType } from "./EventType";
2
+ export { EventType } from "./EventType";
3
+ /**
4
+ * Mobiqo app user data structure
5
+ */
6
+ export interface AppUser {
7
+ /** Internal Mobiqo user ID */
8
+ id: string;
9
+ /** Project ID this user belongs to */
10
+ project_id: string;
11
+ /** RevenueCat user identifier */
12
+ revenue_cat_user_id?: string;
13
+ /** Mobiqo-generated username */
14
+ mobiqo_username: string;
15
+ /** User's operating system */
16
+ os: 'ios' | 'android';
17
+ /** Operating system version */
18
+ os_version: string;
19
+ /** Application version */
20
+ app_version: string;
21
+ /** User's country code */
22
+ country?: string;
23
+ /** User's language preference */
24
+ language?: string;
25
+ /** Timestamp when user was first seen */
26
+ first_seen_at: string;
27
+ /** Timestamp when user was last seen */
28
+ last_seen_at: string;
29
+ /** Currently active entitlements/subscriptions */
30
+ active_entitlements: string[];
31
+ }
32
+ /**
33
+ * User analytics and prediction statistics
34
+ */
35
+ export interface Statistics {
36
+ /** Purchasing power parity score */
37
+ purchasing_power_parity: number;
38
+ /** Predicted probability of making a purchase */
39
+ purchase_probability: number;
40
+ /** Average revenue per user */
41
+ avg_arpu: number;
42
+ /** Average revenue per paying user */
43
+ avg_arppu: number;
44
+ /** Average lifetime value */
45
+ avg_ltv: number;
46
+ }
47
+ /**
48
+ * Response from syncUser method
49
+ */
50
+ export interface SyncUserResponse {
51
+ /** Whether this is a new user (first time syncing) */
52
+ isNewUser: boolean;
53
+ /** Complete user data */
54
+ appUser: AppUser;
55
+ /** User analytics and predictions */
56
+ statistics: Statistics;
57
+ }
58
+ /**
59
+ * Response from getUserInfo method
60
+ */
61
+ export interface GetUserInfoResponse {
62
+ /** Complete user data */
63
+ appUser: AppUser;
64
+ /** User analytics and predictions */
65
+ statistics: Statistics;
66
+ }
67
+ /**
68
+ * Mobiqo Analytics Service for Capacitor apps
69
+ *
70
+ * This service provides analytics tracking, user management, and session handling
71
+ * for mobile applications using the Mobiqo platform.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * import Mobiqo, { EventType, SyncUserResponse, AppUser } from 'mobiqo-capacitor';
76
+ *
77
+ * const mobiqo = new Mobiqo();
78
+ * await mobiqo.init({ mobiqoKey: 'your-api-key' });
79
+ *
80
+ * // Sync user with optional additional data
81
+ * const result: SyncUserResponse = await mobiqo.syncUser({
82
+ * revenue_cat_user_id: 'user-123',
83
+ * additional_data: { plan: 'premium' }
84
+ * });
85
+ * console.log('User OS:', result.appUser.os);
86
+ * console.log('Purchase probability:', result.statistics.purchase_probability);
87
+ *
88
+ * // Track events with optional additional data
89
+ * await mobiqo.trackEvent('button_clicked', EventType.CLICK, { screen: 'home' });
90
+ * await mobiqo.trackEvent('screen_viewed', EventType.SCREEN_VIEW);
91
+ * ```
92
+ */
93
+ export default class Mobiqo {
94
+ private API_URL;
95
+ private heartbeatInterval;
96
+ /**
97
+ * Initialize the Mobiqo service with your API key
98
+ *
99
+ * This method must be called before using any other Mobiqo features.
100
+ * It validates your API key and stores the project ID for subsequent requests.
101
+ *
102
+ * @param options - Configuration options
103
+ * @param options.mobiqoKey - Your Mobiqo API key from the dashboard
104
+ * @returns Promise that resolves when initialization is complete
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const mobiqo = new Mobiqo();
109
+ * await mobiqo.init({ mobiqoKey: 'your-mobiqo-api-key' });
110
+ * ```
111
+ */
112
+ init({ mobiqoKey }: {
113
+ mobiqoKey: string;
114
+ }): Promise<void>;
115
+ /**
116
+ * Sync user data with Mobiqo and start a tracking session
117
+ *
118
+ * This method links a RevenueCat user ID with Mobiqo analytics and starts
119
+ * automatic heartbeat tracking (every 30 seconds). Call this after user login
120
+ * or when you want to start tracking a user's session.
121
+ *
122
+ * @param options - User sync options
123
+ * @param options.revenue_cat_user_id - The RevenueCat user identifier
124
+ * @param options.additional_data - Optional extra user data to store (email, plan, etc.)
125
+ * @returns Promise that resolves with user sync response including user data and statistics
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * // With additional data
130
+ * await mobiqo.syncUser({
131
+ * revenue_cat_user_id: 'user-123',
132
+ * additional_data: {
133
+ * email: 'user@example.com',
134
+ * plan: 'premium',
135
+ * signupDate: '2024-01-01'
136
+ * }
137
+ * });
138
+ *
139
+ * // Without additional data
140
+ * await mobiqo.syncUser({
141
+ * revenue_cat_user_id: 'user-123'
142
+ * });
143
+ * ```
144
+ */
145
+ syncUser({ revenue_cat_user_id, additional_data }: {
146
+ revenue_cat_user_id: string;
147
+ additional_data?: Record<string, any>;
148
+ }): Promise<SyncUserResponse | undefined>;
149
+ /**
150
+ * Retrieve user information from Mobiqo
151
+ *
152
+ * Fetches stored user data and analytics information for a specific user.
153
+ * Useful for displaying user stats or personalizing the app experience.
154
+ *
155
+ * @param options - User lookup options
156
+ * @param options.revenue_cat_user_id - The RevenueCat user identifier to look up
157
+ * @returns Promise that resolves with user information including user data and statistics
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * const userInfo = await mobiqo.getUserInfo({
162
+ * revenue_cat_user_id: 'user-123'
163
+ * });
164
+ * console.log('User OS:', userInfo.appUser.os);
165
+ * console.log('Purchase probability:', userInfo.statistics.purchase_probability);
166
+ * ```
167
+ */
168
+ getUserInfo({ revenue_cat_user_id }: {
169
+ revenue_cat_user_id: string;
170
+ }): Promise<GetUserInfoResponse | undefined>;
171
+ /**
172
+ * Track a custom event with Mobiqo analytics
173
+ *
174
+ * Records user interactions, behaviors, and custom events for analytics.
175
+ * Events are automatically timestamped and associated with the current user session.
176
+ *
177
+ * @param event - Name/identifier for the event (e.g., 'button_clicked', 'screen_viewed')
178
+ * @param eventType - Type of event from EventType enum (CLICK, SCREEN_VIEW, etc.)
179
+ * @param additionalData - Optional custom data to attach to the event
180
+ * @returns Promise that resolves with tracking confirmation
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * // Track a button click with additional data
185
+ * await mobiqo.trackEvent(
186
+ * 'subscribe_button_clicked',
187
+ * EventType.CLICK,
188
+ * {
189
+ * button_location: 'home_screen',
190
+ * user_plan: 'free'
191
+ * }
192
+ * );
193
+ *
194
+ * // Track a screen view without additional data
195
+ * await mobiqo.trackEvent('settings_screen', EventType.SCREEN_VIEW);
196
+ * ```
197
+ */
198
+ trackEvent(event: string, eventType: EventType, additionalData?: Record<string, any>): Promise<any>;
199
+ /**
200
+ * Send a heartbeat to maintain the user session
201
+ *
202
+ * Heartbeats are automatically sent every 30 seconds after syncUser() is called.
203
+ * This helps track active session duration and is handled internally by the SDK.
204
+ *
205
+ * @returns Promise that resolves with heartbeat confirmation
206
+ * @private
207
+ */
208
+ private sendHeartbeat;
209
+ }
package/dist/index.js ADDED
@@ -0,0 +1,288 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.EventType = void 0;
16
+ const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
17
+ var EventType_1 = require("./EventType");
18
+ Object.defineProperty(exports, "EventType", { enumerable: true, get: function () { return EventType_1.EventType; } });
19
+ /**
20
+ * Mobiqo Analytics Service for Capacitor apps
21
+ *
22
+ * This service provides analytics tracking, user management, and session handling
23
+ * for mobile applications using the Mobiqo platform.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * import Mobiqo, { EventType, SyncUserResponse, AppUser } from 'mobiqo-capacitor';
28
+ *
29
+ * const mobiqo = new Mobiqo();
30
+ * await mobiqo.init({ mobiqoKey: 'your-api-key' });
31
+ *
32
+ * // Sync user with optional additional data
33
+ * const result: SyncUserResponse = await mobiqo.syncUser({
34
+ * revenue_cat_user_id: 'user-123',
35
+ * additional_data: { plan: 'premium' }
36
+ * });
37
+ * console.log('User OS:', result.appUser.os);
38
+ * console.log('Purchase probability:', result.statistics.purchase_probability);
39
+ *
40
+ * // Track events with optional additional data
41
+ * await mobiqo.trackEvent('button_clicked', EventType.CLICK, { screen: 'home' });
42
+ * await mobiqo.trackEvent('screen_viewed', EventType.SCREEN_VIEW);
43
+ * ```
44
+ */
45
+ class Mobiqo {
46
+ constructor() {
47
+ this.API_URL = "https://us-central1-mobiqo-582b4.cloudfunctions.net";
48
+ this.heartbeatInterval = null;
49
+ }
50
+ /**
51
+ * Initialize the Mobiqo service with your API key
52
+ *
53
+ * This method must be called before using any other Mobiqo features.
54
+ * It validates your API key and stores the project ID for subsequent requests.
55
+ *
56
+ * @param options - Configuration options
57
+ * @param options.mobiqoKey - Your Mobiqo API key from the dashboard
58
+ * @returns Promise that resolves when initialization is complete
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const mobiqo = new Mobiqo();
63
+ * await mobiqo.init({ mobiqoKey: 'your-mobiqo-api-key' });
64
+ * ```
65
+ */
66
+ init(_a) {
67
+ return __awaiter(this, arguments, void 0, function* ({ mobiqoKey }) {
68
+ try {
69
+ const response = yield fetch(this.API_URL + "/init", {
70
+ method: "POST",
71
+ headers: {
72
+ "Content-Type": "application/json"
73
+ },
74
+ body: JSON.stringify({ mobiqoKey })
75
+ });
76
+ const responseData = yield response.json();
77
+ if (!responseData.authorized) {
78
+ yield async_storage_1.default.removeItem('mobiqo_project_id');
79
+ console.error('Project not found or not authorized');
80
+ return;
81
+ }
82
+ yield async_storage_1.default.setItem('mobiqo_project_id', responseData.project.id);
83
+ }
84
+ catch (error) {
85
+ console.error('Error initializing Mobiqo', error);
86
+ return;
87
+ }
88
+ });
89
+ }
90
+ /**
91
+ * Sync user data with Mobiqo and start a tracking session
92
+ *
93
+ * This method links a RevenueCat user ID with Mobiqo analytics and starts
94
+ * automatic heartbeat tracking (every 30 seconds). Call this after user login
95
+ * or when you want to start tracking a user's session.
96
+ *
97
+ * @param options - User sync options
98
+ * @param options.revenue_cat_user_id - The RevenueCat user identifier
99
+ * @param options.additional_data - Optional extra user data to store (email, plan, etc.)
100
+ * @returns Promise that resolves with user sync response including user data and statistics
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * // With additional data
105
+ * await mobiqo.syncUser({
106
+ * revenue_cat_user_id: 'user-123',
107
+ * additional_data: {
108
+ * email: 'user@example.com',
109
+ * plan: 'premium',
110
+ * signupDate: '2024-01-01'
111
+ * }
112
+ * });
113
+ *
114
+ * // Without additional data
115
+ * await mobiqo.syncUser({
116
+ * revenue_cat_user_id: 'user-123'
117
+ * });
118
+ * ```
119
+ */
120
+ syncUser(_a) {
121
+ return __awaiter(this, arguments, void 0, function* ({ revenue_cat_user_id, additional_data }) {
122
+ try {
123
+ const project_id = yield async_storage_1.default.getItem('mobiqo_project_id');
124
+ if (!project_id) {
125
+ console.error('Project ID not found');
126
+ return;
127
+ }
128
+ const response = yield fetch(this.API_URL + "/linkUser", {
129
+ method: "POST",
130
+ headers: {
131
+ "Content-Type": "application/json"
132
+ },
133
+ body: JSON.stringify({ revenue_cat_user_id, project_id, additional_data, local_timestamp: new Date().getTime() })
134
+ });
135
+ const responseData = yield response.json();
136
+ yield async_storage_1.default.setItem('mobiqo_session_id', responseData.sessionId);
137
+ // Initialize heartbeat interval if not already running
138
+ if (!this.heartbeatInterval) {
139
+ this.heartbeatInterval = setInterval(() => {
140
+ this.sendHeartbeat();
141
+ }, 30000); // 30 seconds
142
+ }
143
+ return responseData;
144
+ }
145
+ catch (error) {
146
+ console.error('Error linking user to Mobiqo', error);
147
+ return;
148
+ }
149
+ });
150
+ }
151
+ /**
152
+ * Retrieve user information from Mobiqo
153
+ *
154
+ * Fetches stored user data and analytics information for a specific user.
155
+ * Useful for displaying user stats or personalizing the app experience.
156
+ *
157
+ * @param options - User lookup options
158
+ * @param options.revenue_cat_user_id - The RevenueCat user identifier to look up
159
+ * @returns Promise that resolves with user information including user data and statistics
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * const userInfo = await mobiqo.getUserInfo({
164
+ * revenue_cat_user_id: 'user-123'
165
+ * });
166
+ * console.log('User OS:', userInfo.appUser.os);
167
+ * console.log('Purchase probability:', userInfo.statistics.purchase_probability);
168
+ * ```
169
+ */
170
+ getUserInfo(_a) {
171
+ return __awaiter(this, arguments, void 0, function* ({ revenue_cat_user_id }) {
172
+ try {
173
+ const project_id = yield async_storage_1.default.getItem('mobiqo_project_id');
174
+ if (!project_id) {
175
+ console.error('Project ID not found');
176
+ return;
177
+ }
178
+ const response = yield fetch(this.API_URL + "/getAppUser", {
179
+ method: "POST",
180
+ headers: {
181
+ "Content-Type": "application/json"
182
+ },
183
+ body: JSON.stringify({ revenue_cat_user_id })
184
+ });
185
+ const responseData = yield response.json();
186
+ return responseData;
187
+ }
188
+ catch (error) {
189
+ console.error('Error getting user info', error);
190
+ return;
191
+ }
192
+ });
193
+ }
194
+ /**
195
+ * Track a custom event with Mobiqo analytics
196
+ *
197
+ * Records user interactions, behaviors, and custom events for analytics.
198
+ * Events are automatically timestamped and associated with the current user session.
199
+ *
200
+ * @param event - Name/identifier for the event (e.g., 'button_clicked', 'screen_viewed')
201
+ * @param eventType - Type of event from EventType enum (CLICK, SCREEN_VIEW, etc.)
202
+ * @param additionalData - Optional custom data to attach to the event
203
+ * @returns Promise that resolves with tracking confirmation
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * // Track a button click with additional data
208
+ * await mobiqo.trackEvent(
209
+ * 'subscribe_button_clicked',
210
+ * EventType.CLICK,
211
+ * {
212
+ * button_location: 'home_screen',
213
+ * user_plan: 'free'
214
+ * }
215
+ * );
216
+ *
217
+ * // Track a screen view without additional data
218
+ * await mobiqo.trackEvent('settings_screen', EventType.SCREEN_VIEW);
219
+ * ```
220
+ */
221
+ trackEvent(event, eventType, additionalData) {
222
+ return __awaiter(this, void 0, void 0, function* () {
223
+ try {
224
+ additionalData = additionalData || {};
225
+ const session_id = yield async_storage_1.default.getItem('mobiqo_session_id');
226
+ if (!session_id) {
227
+ console.error('Session ID not found');
228
+ return;
229
+ }
230
+ additionalData.local_timestamp = new Date().getTime();
231
+ const response = yield fetch(this.API_URL + "/trackEvent", {
232
+ method: "POST",
233
+ headers: {
234
+ "Content-Type": "application/json"
235
+ },
236
+ body: JSON.stringify({ event_name: event, event_type: eventType, session_id, additional_data: additionalData })
237
+ });
238
+ const responseData = yield response.json();
239
+ return responseData;
240
+ // send event
241
+ // additionalData is a dictionary of key-value pairs that will be sent to the Mobiqo API
242
+ // additionalData will be sent to the Mobiqo API as a JSON object
243
+ // additionalData will be sent to the Mobiqo API as a JSON object
244
+ }
245
+ catch (error) {
246
+ console.error('Error tracking event', error);
247
+ return;
248
+ }
249
+ });
250
+ }
251
+ /**
252
+ * Send a heartbeat to maintain the user session
253
+ *
254
+ * Heartbeats are automatically sent every 30 seconds after syncUser() is called.
255
+ * This helps track active session duration and is handled internally by the SDK.
256
+ *
257
+ * @returns Promise that resolves with heartbeat confirmation
258
+ * @private
259
+ */
260
+ sendHeartbeat() {
261
+ return __awaiter(this, void 0, void 0, function* () {
262
+ try {
263
+ const session_id = yield async_storage_1.default.getItem('mobiqo_session_id');
264
+ if (!session_id) {
265
+ console.error('Session ID not found');
266
+ return;
267
+ }
268
+ const response = yield fetch(this.API_URL + "/heartbeat", {
269
+ method: "POST",
270
+ headers: {
271
+ "Content-Type": "application/json"
272
+ },
273
+ body: JSON.stringify({ session_id })
274
+ });
275
+ const responseData = yield response.json();
276
+ // Update session ID if a new one is provided
277
+ if (responseData.sessionId) {
278
+ yield async_storage_1.default.setItem('mobiqo_session_id', responseData.sessionId);
279
+ }
280
+ return responseData;
281
+ }
282
+ catch (error) {
283
+ console.error('Error sending heartbeat:', error);
284
+ }
285
+ });
286
+ }
287
+ }
288
+ exports.default = Mobiqo;
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "mobiqo-react-native",
3
+ "version": "0.0.5",
4
+ "description": "Mobiqo SDK for Capacitor apps - Mobile analytics and user tracking",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist/**/*",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "clean": "rm -rf dist",
15
+ "prepublishOnly": "npm run clean && npm run build",
16
+ "test": "echo \"No tests specified\" && exit 0",
17
+ "publish": "npm run prepublishOnly && npm publish"
18
+ },
19
+ "keywords": [
20
+ "typescript",
21
+ "capacitor",
22
+ "mobiqo",
23
+ "analytics",
24
+ "mobile",
25
+ "tracking",
26
+ "sdk",
27
+ "revenueCat",
28
+ "user-analytics"
29
+ ],
30
+ "author": "Mobiqo",
31
+ "license": "MIT",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/mobiqo/mobiqo-capacitor.git"
35
+ },
36
+ "homepage": "https://github.com/mobiqo/mobiqo-capacitor#readme",
37
+ "bugs": {
38
+ "url": "https://github.com/mobiqo/mobiqo-capacitor/issues"
39
+ },
40
+ "engines": {
41
+ "node": ">=14.0.0"
42
+ },
43
+ "devDependencies": {
44
+ "typescript": "^5.8.3",
45
+ "@react-native-async-storage/async-storage": "^1.19.0"
46
+ },
47
+ "peerDependencies": {
48
+ "@react-native-async-storage/async-storage": ">=1.19.0"
49
+ },
50
+ "dependencies": {}
51
+ }