mobiqo-react-native 0.0.8 → 1.0.0

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/README.md CHANGED
@@ -54,8 +54,10 @@ await mobiqo.syncUser({
54
54
  revenue_cat_user_id: 'user-123',
55
55
  include_advanced_analysis: false,
56
56
  additional_data: {
57
- email: 'user@example.com',
58
- plan: 'premium'
57
+ user_id: 'user-123',
58
+ user_name: 'John Doe',
59
+ user_email: 'user@example.com',
60
+ referrer: 'google'
59
61
  }
60
62
  });
61
63
 
@@ -82,6 +84,21 @@ await mobiqo.trackEvent(
82
84
  await mobiqo.trackEvent('screen_opened', MobiqoEvent.SCREEN_VIEW);
83
85
  ```
84
86
 
87
+ ### Update user data
88
+
89
+ ```typescript
90
+ // Update user information without creating a new session
91
+ await mobiqo.updateUser({
92
+ revenue_cat_user_id: 'user-123',
93
+ additional_data: {
94
+ user_id: 'user-123',
95
+ user_name: 'John Doe Updated',
96
+ user_email: 'newemail@example.com',
97
+ referrer: 'facebook'
98
+ }
99
+ });
100
+ ```
101
+
85
102
  ### Get user information
86
103
 
87
104
  ```typescript
@@ -93,7 +110,7 @@ const userInfo = await mobiqo.getUserInfo({
93
110
 
94
111
  ### Automatic Session Tracking
95
112
 
96
- The SDK automatically sends heartbeats every 30 seconds after user sync to maintain session tracking. No manual intervention is required.
113
+ The SDK automatically sends heartbeats every 20 seconds after user sync to maintain session tracking. No manual intervention is required.
97
114
 
98
115
  ## API Reference
99
116
 
@@ -106,8 +123,13 @@ Initialize the Mobiqo service with your API key.
106
123
  #### `syncUser(options)`
107
124
  Sync user data with Mobiqo and start a session.
108
125
  - `options.revenue_cat_user_id` (string): RevenueCat user ID
109
- - `options.include_advanced_analysis` (boolean): whether or not to include advanced analysis in the response (to get the purchase probability and other data, but the request will take more time)
110
- - `options.additional_data` (Record<string, any>, optional): Additional user data
126
+ - `options.include_advanced_analysis` (boolean, optional): whether or not to include advanced analysis in the response (to get the purchase probability and other data, but the request will take more time)
127
+ - `options.additional_data` (AdditionalData, optional): Additional user data (user_id, user_name, user_email, referrer)
128
+
129
+ #### `updateUser(options)`
130
+ Update user information without creating a new session.
131
+ - `options.revenue_cat_user_id` (string): RevenueCat user ID
132
+ - `options.additional_data` (AdditionalData, optional): Additional user data to update (user_id, user_name, user_email, referrer)
111
133
 
112
134
  #### `getUserInfo(options)`
113
135
  Retrieve user information from Mobiqo.
@@ -187,6 +209,16 @@ interface Statistics {
187
209
  }
188
210
  ```
189
211
 
212
+ #### `AdditionalData`
213
+ ```typescript
214
+ interface AdditionalData {
215
+ user_id?: string;
216
+ user_name?: string;
217
+ user_email?: string;
218
+ referrer?: string;
219
+ }
220
+ ```
221
+
190
222
  ## Requirements
191
223
 
192
224
  - React Native
package/dist/index.d.ts CHANGED
@@ -22,6 +22,8 @@ export interface AppUser {
22
22
  country?: string;
23
23
  /** User's language preference */
24
24
  language?: string;
25
+ /** A/B testing group assignment */
26
+ group: 'red' | 'blue';
25
27
  /** Timestamp when user was first seen */
26
28
  first_seen_at: string;
27
29
  /** Timestamp when user was last seen */
@@ -29,6 +31,12 @@ export interface AppUser {
29
31
  /** Currently active entitlements/subscriptions */
30
32
  active_entitlements: string[];
31
33
  }
34
+ export interface AdditionalData {
35
+ user_id?: string;
36
+ user_name?: string;
37
+ user_email?: string;
38
+ referrer?: string;
39
+ }
32
40
  /**
33
41
  * User analytics and prediction statistics
34
42
  */
@@ -65,14 +73,14 @@ export interface GetUserInfoResponse {
65
73
  statistics: Statistics;
66
74
  }
67
75
  /**
68
- * Mobiqo Analytics Service for Capacitor apps
76
+ * Mobiqo Analytics Service for React Native apps
69
77
  *
70
78
  * This service provides analytics tracking, user management, and session handling
71
79
  * for mobile applications using the Mobiqo platform.
72
80
  *
73
81
  * @example
74
82
  * ```typescript
75
- * import Mobiqo, { MobiqoEvent, SyncUserResponse, AppUser } from 'mobiqo-capacitor';
83
+ * import Mobiqo, { MobiqoEvent, SyncUserResponse, AppUser } from 'mobiqo-react-native';
76
84
  *
77
85
  * const mobiqo = new Mobiqo();
78
86
  * await mobiqo.init({ mobiqoKey: 'your-api-key' });
@@ -80,7 +88,8 @@ export interface GetUserInfoResponse {
80
88
  * // Sync user with optional additional data
81
89
  * const result: SyncUserResponse = await mobiqo.syncUser({
82
90
  * revenue_cat_user_id: 'user-123',
83
- * additional_data: { plan: 'premium' }
91
+ * include_advanced_analysis: true,
92
+ * additional_data: { user_id: 'user-123', user_name: 'John Doe', user_email: 'john.doe@example.com', referrer: 'google' }
84
93
  * });
85
94
  * console.log('User OS:', result.appUser.os);
86
95
  * console.log('Purchase intent:', result.statistics.purchase_intent);
@@ -112,17 +121,27 @@ export default class Mobiqo {
112
121
  init({ mobiqoKey }: {
113
122
  mobiqoKey: string;
114
123
  }): Promise<void>;
124
+ /**
125
+ * Get device model information
126
+ *
127
+ * Returns actual device model when possible. For best results, install react-native-device-info:
128
+ * npm install --save react-native-device-info
129
+ *
130
+ * @returns Device model string or 'unknown' if not available
131
+ * @private
132
+ */
133
+ private getDeviceModel;
115
134
  /**
116
135
  * Sync user data with Mobiqo and start a tracking session
117
136
  *
118
137
  * This method links a RevenueCat user ID with Mobiqo analytics and starts
119
- * automatic heartbeat tracking (every 30 seconds). Call this after user login
138
+ * automatic heartbeat tracking (every 20 seconds). Call this after user login
120
139
  * or when you want to start tracking a user's session.
121
140
  *
122
141
  * @param options - User sync options
123
142
  * @param options.revenue_cat_user_id - The RevenueCat user identifier
124
143
  * @param options.include_advanced_analysis - Whether to include advanced analysis in the response (purchase probability and other data, but request takes more time)
125
- * @param options.additional_data - Optional extra user data to store (email, plan, etc.)
144
+ * @param options.additional_data - Optional extra user data to store (email, name, etc.)
126
145
  * @returns Promise that resolves with user sync response including user data and statistics
127
146
  *
128
147
  * @example
@@ -132,9 +151,10 @@ export default class Mobiqo {
132
151
  * revenue_cat_user_id: 'user-123',
133
152
  * include_advanced_analysis: true,
134
153
  * additional_data: {
135
- * email: 'user@example.com',
136
- * plan: 'premium',
137
- * signupDate: '2024-01-01'
154
+ * user_id: 'user-123',
155
+ * user_name: 'John Doe',
156
+ * user_email: 'user@example.com',
157
+ * referrer: 'google',
138
158
  * }
139
159
  * });
140
160
  *
@@ -147,8 +167,37 @@ export default class Mobiqo {
147
167
  syncUser({ revenue_cat_user_id, include_advanced_analysis, additional_data }: {
148
168
  revenue_cat_user_id: string;
149
169
  include_advanced_analysis?: boolean;
150
- additional_data?: Record<string, any>;
170
+ additional_data?: AdditionalData;
151
171
  }): Promise<SyncUserResponse | undefined>;
172
+ /**
173
+ * Update user data in Mobiqo
174
+ *
175
+ * This method allows you to update additional user data for an existing user.
176
+ * Use this when you want to update user information without creating a new session.
177
+ *
178
+ * @param options - User update options
179
+ * @param options.revenue_cat_user_id - The RevenueCat user identifier
180
+ * @param options.additional_data - Optional extra user data to update (email, name, etc.)
181
+ * @returns Promise that resolves when the update is complete
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * // Update user data
186
+ * await mobiqo.updateUser({
187
+ * revenue_cat_user_id: 'user-123',
188
+ * additional_data: {
189
+ * user_id: 'user-123',
190
+ * user_name: 'John Doe',
191
+ * user_email: 'john.doe@example.com',
192
+ * referrer: 'google',
193
+ * }
194
+ * });
195
+ * ```
196
+ */
197
+ updateUser({ revenue_cat_user_id, additional_data }: {
198
+ revenue_cat_user_id: string;
199
+ additional_data?: AdditionalData;
200
+ }): Promise<void>;
152
201
  /**
153
202
  * Retrieve user information from Mobiqo
154
203
  *
@@ -205,7 +254,7 @@ export default class Mobiqo {
205
254
  /**
206
255
  * Send a heartbeat to maintain the user session
207
256
  *
208
- * Heartbeats are automatically sent every 30 seconds after syncUser() is called.
257
+ * Heartbeats are automatically sent every 20 seconds after syncUser() is called.
209
258
  * This helps track active session duration and is handled internally by the SDK.
210
259
  *
211
260
  * @returns Promise that resolves with heartbeat confirmation
package/dist/index.js CHANGED
@@ -14,17 +14,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.MobiqoEvent = void 0;
16
16
  const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
17
+ const react_native_1 = require("react-native");
17
18
  var MobiqoEvent_1 = require("./MobiqoEvent");
18
19
  Object.defineProperty(exports, "MobiqoEvent", { enumerable: true, get: function () { return MobiqoEvent_1.MobiqoEvent; } });
19
20
  /**
20
- * Mobiqo Analytics Service for Capacitor apps
21
+ * Mobiqo Analytics Service for React Native apps
21
22
  *
22
23
  * This service provides analytics tracking, user management, and session handling
23
24
  * for mobile applications using the Mobiqo platform.
24
25
  *
25
26
  * @example
26
27
  * ```typescript
27
- * import Mobiqo, { MobiqoEvent, SyncUserResponse, AppUser } from 'mobiqo-capacitor';
28
+ * import Mobiqo, { MobiqoEvent, SyncUserResponse, AppUser } from 'mobiqo-react-native';
28
29
  *
29
30
  * const mobiqo = new Mobiqo();
30
31
  * await mobiqo.init({ mobiqoKey: 'your-api-key' });
@@ -32,7 +33,8 @@ Object.defineProperty(exports, "MobiqoEvent", { enumerable: true, get: function
32
33
  * // Sync user with optional additional data
33
34
  * const result: SyncUserResponse = await mobiqo.syncUser({
34
35
  * revenue_cat_user_id: 'user-123',
35
- * additional_data: { plan: 'premium' }
36
+ * include_advanced_analysis: true,
37
+ * additional_data: { user_id: 'user-123', user_name: 'John Doe', user_email: 'john.doe@example.com', referrer: 'google' }
36
38
  * });
37
39
  * console.log('User OS:', result.appUser.os);
38
40
  * console.log('Purchase intent:', result.statistics.purchase_intent);
@@ -87,17 +89,59 @@ class Mobiqo {
87
89
  }
88
90
  });
89
91
  }
92
+ /**
93
+ * Get device model information
94
+ *
95
+ * Returns actual device model when possible. For best results, install react-native-device-info:
96
+ * npm install --save react-native-device-info
97
+ *
98
+ * @returns Device model string or 'unknown' if not available
99
+ * @private
100
+ */
101
+ getDeviceModel() {
102
+ var _a, _b, _c;
103
+ try {
104
+ // Try to use react-native-device-info if available (optional peer dependency)
105
+ try {
106
+ const DeviceInfo = require('react-native-device-info');
107
+ // getModel() returns actual device model like "iPhone13,2" on iOS or "SM-G991B" on Android
108
+ const model = ((_b = (_a = DeviceInfo.default) === null || _a === void 0 ? void 0 : _a.getModel) === null || _b === void 0 ? void 0 : _b.call(_a)) || ((_c = DeviceInfo.getModel) === null || _c === void 0 ? void 0 : _c.call(DeviceInfo));
109
+ if (model) {
110
+ return model;
111
+ }
112
+ }
113
+ catch (e) {
114
+ // react-native-device-info not installed, fall back to Platform API
115
+ }
116
+ // Fallback: Use Platform constants
117
+ const constants = react_native_1.Platform.constants;
118
+ if (react_native_1.Platform.OS === 'ios') {
119
+ // iOS: Try to get device info from constants
120
+ // Note: This won't give hardware identifier without device-info package
121
+ return constants.systemName || constants.model || react_native_1.Platform.OS;
122
+ }
123
+ else if (react_native_1.Platform.OS === 'android') {
124
+ // Android: Try to extract model from constants
125
+ return constants.Model || constants.Brand || react_native_1.Platform.OS;
126
+ }
127
+ return react_native_1.Platform.OS || 'unknown';
128
+ }
129
+ catch (error) {
130
+ console.error('Error getting device model:', error);
131
+ return 'unknown';
132
+ }
133
+ }
90
134
  /**
91
135
  * Sync user data with Mobiqo and start a tracking session
92
136
  *
93
137
  * This method links a RevenueCat user ID with Mobiqo analytics and starts
94
- * automatic heartbeat tracking (every 30 seconds). Call this after user login
138
+ * automatic heartbeat tracking (every 20 seconds). Call this after user login
95
139
  * or when you want to start tracking a user's session.
96
140
  *
97
141
  * @param options - User sync options
98
142
  * @param options.revenue_cat_user_id - The RevenueCat user identifier
99
143
  * @param options.include_advanced_analysis - Whether to include advanced analysis in the response (purchase probability and other data, but request takes more time)
100
- * @param options.additional_data - Optional extra user data to store (email, plan, etc.)
144
+ * @param options.additional_data - Optional extra user data to store (email, name, etc.)
101
145
  * @returns Promise that resolves with user sync response including user data and statistics
102
146
  *
103
147
  * @example
@@ -107,9 +151,10 @@ class Mobiqo {
107
151
  * revenue_cat_user_id: 'user-123',
108
152
  * include_advanced_analysis: true,
109
153
  * additional_data: {
110
- * email: 'user@example.com',
111
- * plan: 'premium',
112
- * signupDate: '2024-01-01'
154
+ * user_id: 'user-123',
155
+ * user_name: 'John Doe',
156
+ * user_email: 'user@example.com',
157
+ * referrer: 'google',
113
158
  * }
114
159
  * });
115
160
  *
@@ -127,12 +172,19 @@ class Mobiqo {
127
172
  console.error('Project ID not found');
128
173
  return;
129
174
  }
175
+ const device_model = this.getDeviceModel();
176
+ const additionalData = {
177
+ id: additional_data === null || additional_data === void 0 ? void 0 : additional_data.user_id,
178
+ name: additional_data === null || additional_data === void 0 ? void 0 : additional_data.user_name,
179
+ email: additional_data === null || additional_data === void 0 ? void 0 : additional_data.user_email,
180
+ referrer: additional_data === null || additional_data === void 0 ? void 0 : additional_data.referrer,
181
+ };
130
182
  const response = yield fetch(this.API_URL + "/linkUser", {
131
183
  method: "POST",
132
184
  headers: {
133
185
  "Content-Type": "application/json"
134
186
  },
135
- body: JSON.stringify({ revenue_cat_user_id, project_id, include_advanced_analysis, additional_data, local_timestamp: new Date().getTime() })
187
+ body: JSON.stringify({ revenue_cat_user_id, project_id, include_advanced_analysis, personal_data: additionalData || {}, device_model, local_timestamp: new Date().getTime() })
136
188
  });
137
189
  const responseData = yield response.json();
138
190
  yield async_storage_1.default.setItem('mobiqo_session_id', responseData.sessionId);
@@ -140,7 +192,7 @@ class Mobiqo {
140
192
  if (!this.heartbeatInterval) {
141
193
  this.heartbeatInterval = setInterval(() => {
142
194
  this.sendHeartbeat();
143
- }, 30000); // 30 seconds
195
+ }, 20000); // 20 seconds
144
196
  }
145
197
  return responseData;
146
198
  }
@@ -150,6 +202,59 @@ class Mobiqo {
150
202
  }
151
203
  });
152
204
  }
205
+ /**
206
+ * Update user data in Mobiqo
207
+ *
208
+ * This method allows you to update additional user data for an existing user.
209
+ * Use this when you want to update user information without creating a new session.
210
+ *
211
+ * @param options - User update options
212
+ * @param options.revenue_cat_user_id - The RevenueCat user identifier
213
+ * @param options.additional_data - Optional extra user data to update (email, name, etc.)
214
+ * @returns Promise that resolves when the update is complete
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * // Update user data
219
+ * await mobiqo.updateUser({
220
+ * revenue_cat_user_id: 'user-123',
221
+ * additional_data: {
222
+ * user_id: 'user-123',
223
+ * user_name: 'John Doe',
224
+ * user_email: 'john.doe@example.com',
225
+ * referrer: 'google',
226
+ * }
227
+ * });
228
+ * ```
229
+ */
230
+ updateUser(_a) {
231
+ return __awaiter(this, arguments, void 0, function* ({ revenue_cat_user_id, additional_data }) {
232
+ try {
233
+ const project_id = yield async_storage_1.default.getItem('mobiqo_project_id');
234
+ if (!project_id) {
235
+ console.error('Project ID not found');
236
+ return;
237
+ }
238
+ const additionalData = {
239
+ id: additional_data === null || additional_data === void 0 ? void 0 : additional_data.user_id,
240
+ name: additional_data === null || additional_data === void 0 ? void 0 : additional_data.user_name,
241
+ email: additional_data === null || additional_data === void 0 ? void 0 : additional_data.user_email,
242
+ referrer: additional_data === null || additional_data === void 0 ? void 0 : additional_data.referrer,
243
+ };
244
+ const response = yield fetch(this.API_URL + "/updateUser", {
245
+ method: "POST",
246
+ headers: {
247
+ "Content-Type": "application/json"
248
+ },
249
+ body: JSON.stringify({ revenue_cat_user_id, project_id, personal_data: additionalData || {} })
250
+ });
251
+ yield response.json();
252
+ }
253
+ catch (error) {
254
+ console.error('Error updating user', error);
255
+ }
256
+ });
257
+ }
153
258
  /**
154
259
  * Retrieve user information from Mobiqo
155
260
  *
@@ -255,7 +360,7 @@ class Mobiqo {
255
360
  /**
256
361
  * Send a heartbeat to maintain the user session
257
362
  *
258
- * Heartbeats are automatically sent every 30 seconds after syncUser() is called.
363
+ * Heartbeats are automatically sent every 20 seconds after syncUser() is called.
259
364
  * This helps track active session duration and is handled internally by the SDK.
260
365
  *
261
366
  * @returns Promise that resolves with heartbeat confirmation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobiqo-react-native",
3
- "version": "0.0.8",
3
+ "version": "1.0.0",
4
4
  "description": "Mobiqo SDK for Capacitor apps - Mobile analytics and user tracking",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -47,5 +47,10 @@
47
47
  "peerDependencies": {
48
48
  "@react-native-async-storage/async-storage": ">=1.19.0"
49
49
  },
50
+ "peerDependenciesMeta": {
51
+ "react-native-device-info": {
52
+ "optional": true
53
+ }
54
+ },
50
55
  "dependencies": {}
51
56
  }