mobiqo-react-native 0.0.7 → 0.0.10
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 +7 -3
- package/dist/index.d.ts +29 -11
- package/dist/index.js +60 -12
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -52,6 +52,7 @@ await mobiqo.init({ mobiqoKey: 'your-mobiqo-api-key' });
|
|
|
52
52
|
// With additional data (optional)
|
|
53
53
|
await mobiqo.syncUser({
|
|
54
54
|
revenue_cat_user_id: 'user-123',
|
|
55
|
+
include_advanced_analysis: false,
|
|
55
56
|
additional_data: {
|
|
56
57
|
email: 'user@example.com',
|
|
57
58
|
plan: 'premium'
|
|
@@ -85,13 +86,14 @@ await mobiqo.trackEvent('screen_opened', MobiqoEvent.SCREEN_VIEW);
|
|
|
85
86
|
|
|
86
87
|
```typescript
|
|
87
88
|
const userInfo = await mobiqo.getUserInfo({
|
|
88
|
-
revenue_cat_user_id: 'user-123'
|
|
89
|
+
revenue_cat_user_id: 'user-123',
|
|
90
|
+
include_advanced_analysis: true
|
|
89
91
|
});
|
|
90
92
|
```
|
|
91
93
|
|
|
92
94
|
### Automatic Session Tracking
|
|
93
95
|
|
|
94
|
-
The SDK automatically sends heartbeats every
|
|
96
|
+
The SDK automatically sends heartbeats every 20 seconds after user sync to maintain session tracking. No manual intervention is required.
|
|
95
97
|
|
|
96
98
|
## API Reference
|
|
97
99
|
|
|
@@ -104,11 +106,13 @@ Initialize the Mobiqo service with your API key.
|
|
|
104
106
|
#### `syncUser(options)`
|
|
105
107
|
Sync user data with Mobiqo and start a session.
|
|
106
108
|
- `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)
|
|
107
110
|
- `options.additional_data` (Record<string, any>, optional): Additional user data
|
|
108
111
|
|
|
109
112
|
#### `getUserInfo(options)`
|
|
110
113
|
Retrieve user information from Mobiqo.
|
|
111
114
|
- `options.revenue_cat_user_id` (string): RevenueCat user ID
|
|
115
|
+
- `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)
|
|
112
116
|
|
|
113
117
|
#### `trackEvent(event, eventType, additionalData?)`
|
|
114
118
|
Track custom events.
|
|
@@ -176,7 +180,7 @@ interface AppUser {
|
|
|
176
180
|
```typescript
|
|
177
181
|
interface Statistics {
|
|
178
182
|
purchasing_power_parity: number;
|
|
179
|
-
|
|
183
|
+
purchase_intent: number;
|
|
180
184
|
avg_arpu: number;
|
|
181
185
|
avg_arppu: number;
|
|
182
186
|
avg_ltv: number;
|
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 */
|
|
@@ -35,8 +37,8 @@ export interface AppUser {
|
|
|
35
37
|
export interface Statistics {
|
|
36
38
|
/** Purchasing power parity score */
|
|
37
39
|
purchasing_power_parity: number;
|
|
38
|
-
/** Predicted
|
|
39
|
-
|
|
40
|
+
/** Predicted intent to make a purchase */
|
|
41
|
+
purchase_intent: number;
|
|
40
42
|
/** Average revenue per user */
|
|
41
43
|
avg_arpu: number;
|
|
42
44
|
/** Average revenue per paying user */
|
|
@@ -83,7 +85,7 @@ export interface GetUserInfoResponse {
|
|
|
83
85
|
* additional_data: { plan: 'premium' }
|
|
84
86
|
* });
|
|
85
87
|
* console.log('User OS:', result.appUser.os);
|
|
86
|
-
* console.log('Purchase
|
|
88
|
+
* console.log('Purchase intent:', result.statistics.purchase_intent);
|
|
87
89
|
*
|
|
88
90
|
* // Track events with optional additional data
|
|
89
91
|
* await mobiqo.trackEvent('button_clicked', MobiqoEvent.CLICK, { screen: 'home' });
|
|
@@ -112,23 +114,35 @@ export default class Mobiqo {
|
|
|
112
114
|
init({ mobiqoKey }: {
|
|
113
115
|
mobiqoKey: string;
|
|
114
116
|
}): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Get device model information
|
|
119
|
+
*
|
|
120
|
+
* Returns actual device model when possible. For best results, install react-native-device-info:
|
|
121
|
+
* npm install react-native-device-info
|
|
122
|
+
*
|
|
123
|
+
* @returns Device model string or 'unknown' if not available
|
|
124
|
+
* @private
|
|
125
|
+
*/
|
|
126
|
+
private getDeviceModel;
|
|
115
127
|
/**
|
|
116
128
|
* Sync user data with Mobiqo and start a tracking session
|
|
117
129
|
*
|
|
118
130
|
* This method links a RevenueCat user ID with Mobiqo analytics and starts
|
|
119
|
-
* automatic heartbeat tracking (every
|
|
131
|
+
* automatic heartbeat tracking (every 20 seconds). Call this after user login
|
|
120
132
|
* or when you want to start tracking a user's session.
|
|
121
133
|
*
|
|
122
134
|
* @param options - User sync options
|
|
123
135
|
* @param options.revenue_cat_user_id - The RevenueCat user identifier
|
|
136
|
+
* @param options.include_advanced_analysis - Whether to include advanced analysis in the response (purchase probability and other data, but request takes more time)
|
|
124
137
|
* @param options.additional_data - Optional extra user data to store (email, plan, etc.)
|
|
125
138
|
* @returns Promise that resolves with user sync response including user data and statistics
|
|
126
139
|
*
|
|
127
140
|
* @example
|
|
128
141
|
* ```typescript
|
|
129
|
-
* // With additional data
|
|
142
|
+
* // With additional data and advanced analysis
|
|
130
143
|
* await mobiqo.syncUser({
|
|
131
144
|
* revenue_cat_user_id: 'user-123',
|
|
145
|
+
* include_advanced_analysis: true,
|
|
132
146
|
* additional_data: {
|
|
133
147
|
* email: 'user@example.com',
|
|
134
148
|
* plan: 'premium',
|
|
@@ -136,14 +150,15 @@ export default class Mobiqo {
|
|
|
136
150
|
* }
|
|
137
151
|
* });
|
|
138
152
|
*
|
|
139
|
-
* // Without additional data
|
|
153
|
+
* // Without additional data and advanced analysis
|
|
140
154
|
* await mobiqo.syncUser({
|
|
141
155
|
* revenue_cat_user_id: 'user-123'
|
|
142
156
|
* });
|
|
143
157
|
* ```
|
|
144
158
|
*/
|
|
145
|
-
syncUser({ revenue_cat_user_id, additional_data }: {
|
|
159
|
+
syncUser({ revenue_cat_user_id, include_advanced_analysis, additional_data }: {
|
|
146
160
|
revenue_cat_user_id: string;
|
|
161
|
+
include_advanced_analysis?: boolean;
|
|
147
162
|
additional_data?: Record<string, any>;
|
|
148
163
|
}): Promise<SyncUserResponse | undefined>;
|
|
149
164
|
/**
|
|
@@ -154,19 +169,22 @@ export default class Mobiqo {
|
|
|
154
169
|
*
|
|
155
170
|
* @param options - User lookup options
|
|
156
171
|
* @param options.revenue_cat_user_id - The RevenueCat user identifier to look up
|
|
172
|
+
* @param options.include_advanced_analysis - Whether to include advanced analysis in the response (purchase probability and other data, but request takes more time)
|
|
157
173
|
* @returns Promise that resolves with user information including user data and statistics
|
|
158
174
|
*
|
|
159
175
|
* @example
|
|
160
176
|
* ```typescript
|
|
161
177
|
* const userInfo = await mobiqo.getUserInfo({
|
|
162
|
-
* revenue_cat_user_id: 'user-123'
|
|
178
|
+
* revenue_cat_user_id: 'user-123',
|
|
179
|
+
* include_advanced_analysis: true
|
|
163
180
|
* });
|
|
164
181
|
* console.log('User OS:', userInfo.appUser.os);
|
|
165
|
-
* console.log('Purchase
|
|
182
|
+
* console.log('Purchase intent:', userInfo.statistics.purchase_intent);
|
|
166
183
|
* ```
|
|
167
184
|
*/
|
|
168
|
-
getUserInfo({ revenue_cat_user_id }: {
|
|
185
|
+
getUserInfo({ revenue_cat_user_id, include_advanced_analysis }: {
|
|
169
186
|
revenue_cat_user_id: string;
|
|
187
|
+
include_advanced_analysis?: boolean;
|
|
170
188
|
}): Promise<GetUserInfoResponse | undefined>;
|
|
171
189
|
/**
|
|
172
190
|
* Track a custom event with Mobiqo analytics
|
|
@@ -199,7 +217,7 @@ export default class Mobiqo {
|
|
|
199
217
|
/**
|
|
200
218
|
* Send a heartbeat to maintain the user session
|
|
201
219
|
*
|
|
202
|
-
* Heartbeats are automatically sent every
|
|
220
|
+
* Heartbeats are automatically sent every 20 seconds after syncUser() is called.
|
|
203
221
|
* This helps track active session duration and is handled internally by the SDK.
|
|
204
222
|
*
|
|
205
223
|
* @returns Promise that resolves with heartbeat confirmation
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ 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
|
/**
|
|
@@ -35,7 +36,7 @@ Object.defineProperty(exports, "MobiqoEvent", { enumerable: true, get: function
|
|
|
35
36
|
* additional_data: { plan: 'premium' }
|
|
36
37
|
* });
|
|
37
38
|
* console.log('User OS:', result.appUser.os);
|
|
38
|
-
* console.log('Purchase
|
|
39
|
+
* console.log('Purchase intent:', result.statistics.purchase_intent);
|
|
39
40
|
*
|
|
40
41
|
* // Track events with optional additional data
|
|
41
42
|
* await mobiqo.trackEvent('button_clicked', MobiqoEvent.CLICK, { screen: 'home' });
|
|
@@ -87,23 +88,67 @@ class Mobiqo {
|
|
|
87
88
|
}
|
|
88
89
|
});
|
|
89
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Get device model information
|
|
93
|
+
*
|
|
94
|
+
* Returns actual device model when possible. For best results, install react-native-device-info:
|
|
95
|
+
* npm install react-native-device-info
|
|
96
|
+
*
|
|
97
|
+
* @returns Device model string or 'unknown' if not available
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
getDeviceModel() {
|
|
101
|
+
var _a, _b, _c;
|
|
102
|
+
try {
|
|
103
|
+
// Try to use react-native-device-info if available (optional peer dependency)
|
|
104
|
+
try {
|
|
105
|
+
const DeviceInfo = require('react-native-device-info');
|
|
106
|
+
// getModel() returns actual device model like "iPhone13,2" on iOS or "SM-G991B" on Android
|
|
107
|
+
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));
|
|
108
|
+
if (model) {
|
|
109
|
+
return model;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
// react-native-device-info not installed, fall back to Platform API
|
|
114
|
+
}
|
|
115
|
+
// Fallback: Use Platform constants
|
|
116
|
+
const constants = react_native_1.Platform.constants;
|
|
117
|
+
if (react_native_1.Platform.OS === 'ios') {
|
|
118
|
+
// iOS: Try to get device info from constants
|
|
119
|
+
// Note: This won't give hardware identifier without device-info package
|
|
120
|
+
return constants.systemName || constants.model || react_native_1.Platform.OS;
|
|
121
|
+
}
|
|
122
|
+
else if (react_native_1.Platform.OS === 'android') {
|
|
123
|
+
// Android: Try to extract model from constants
|
|
124
|
+
return constants.Model || constants.Brand || react_native_1.Platform.OS;
|
|
125
|
+
}
|
|
126
|
+
return react_native_1.Platform.OS || 'unknown';
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
console.error('Error getting device model:', error);
|
|
130
|
+
return 'unknown';
|
|
131
|
+
}
|
|
132
|
+
}
|
|
90
133
|
/**
|
|
91
134
|
* Sync user data with Mobiqo and start a tracking session
|
|
92
135
|
*
|
|
93
136
|
* This method links a RevenueCat user ID with Mobiqo analytics and starts
|
|
94
|
-
* automatic heartbeat tracking (every
|
|
137
|
+
* automatic heartbeat tracking (every 20 seconds). Call this after user login
|
|
95
138
|
* or when you want to start tracking a user's session.
|
|
96
139
|
*
|
|
97
140
|
* @param options - User sync options
|
|
98
141
|
* @param options.revenue_cat_user_id - The RevenueCat user identifier
|
|
142
|
+
* @param options.include_advanced_analysis - Whether to include advanced analysis in the response (purchase probability and other data, but request takes more time)
|
|
99
143
|
* @param options.additional_data - Optional extra user data to store (email, plan, etc.)
|
|
100
144
|
* @returns Promise that resolves with user sync response including user data and statistics
|
|
101
145
|
*
|
|
102
146
|
* @example
|
|
103
147
|
* ```typescript
|
|
104
|
-
* // With additional data
|
|
148
|
+
* // With additional data and advanced analysis
|
|
105
149
|
* await mobiqo.syncUser({
|
|
106
150
|
* revenue_cat_user_id: 'user-123',
|
|
151
|
+
* include_advanced_analysis: true,
|
|
107
152
|
* additional_data: {
|
|
108
153
|
* email: 'user@example.com',
|
|
109
154
|
* plan: 'premium',
|
|
@@ -111,26 +156,27 @@ class Mobiqo {
|
|
|
111
156
|
* }
|
|
112
157
|
* });
|
|
113
158
|
*
|
|
114
|
-
* // Without additional data
|
|
159
|
+
* // Without additional data and advanced analysis
|
|
115
160
|
* await mobiqo.syncUser({
|
|
116
161
|
* revenue_cat_user_id: 'user-123'
|
|
117
162
|
* });
|
|
118
163
|
* ```
|
|
119
164
|
*/
|
|
120
165
|
syncUser(_a) {
|
|
121
|
-
return __awaiter(this, arguments, void 0, function* ({ revenue_cat_user_id, additional_data }) {
|
|
166
|
+
return __awaiter(this, arguments, void 0, function* ({ revenue_cat_user_id, include_advanced_analysis, additional_data }) {
|
|
122
167
|
try {
|
|
123
168
|
const project_id = yield async_storage_1.default.getItem('mobiqo_project_id');
|
|
124
169
|
if (!project_id) {
|
|
125
170
|
console.error('Project ID not found');
|
|
126
171
|
return;
|
|
127
172
|
}
|
|
173
|
+
const device_model = this.getDeviceModel();
|
|
128
174
|
const response = yield fetch(this.API_URL + "/linkUser", {
|
|
129
175
|
method: "POST",
|
|
130
176
|
headers: {
|
|
131
177
|
"Content-Type": "application/json"
|
|
132
178
|
},
|
|
133
|
-
body: JSON.stringify({ revenue_cat_user_id, project_id, additional_data, local_timestamp: new Date().getTime() })
|
|
179
|
+
body: JSON.stringify({ revenue_cat_user_id, project_id, include_advanced_analysis, additional_data, device_model, local_timestamp: new Date().getTime() })
|
|
134
180
|
});
|
|
135
181
|
const responseData = yield response.json();
|
|
136
182
|
yield async_storage_1.default.setItem('mobiqo_session_id', responseData.sessionId);
|
|
@@ -138,7 +184,7 @@ class Mobiqo {
|
|
|
138
184
|
if (!this.heartbeatInterval) {
|
|
139
185
|
this.heartbeatInterval = setInterval(() => {
|
|
140
186
|
this.sendHeartbeat();
|
|
141
|
-
},
|
|
187
|
+
}, 20000); // 20 seconds
|
|
142
188
|
}
|
|
143
189
|
return responseData;
|
|
144
190
|
}
|
|
@@ -156,19 +202,21 @@ class Mobiqo {
|
|
|
156
202
|
*
|
|
157
203
|
* @param options - User lookup options
|
|
158
204
|
* @param options.revenue_cat_user_id - The RevenueCat user identifier to look up
|
|
205
|
+
* @param options.include_advanced_analysis - Whether to include advanced analysis in the response (purchase probability and other data, but request takes more time)
|
|
159
206
|
* @returns Promise that resolves with user information including user data and statistics
|
|
160
207
|
*
|
|
161
208
|
* @example
|
|
162
209
|
* ```typescript
|
|
163
210
|
* const userInfo = await mobiqo.getUserInfo({
|
|
164
|
-
* revenue_cat_user_id: 'user-123'
|
|
211
|
+
* revenue_cat_user_id: 'user-123',
|
|
212
|
+
* include_advanced_analysis: true
|
|
165
213
|
* });
|
|
166
214
|
* console.log('User OS:', userInfo.appUser.os);
|
|
167
|
-
* console.log('Purchase
|
|
215
|
+
* console.log('Purchase intent:', userInfo.statistics.purchase_intent);
|
|
168
216
|
* ```
|
|
169
217
|
*/
|
|
170
218
|
getUserInfo(_a) {
|
|
171
|
-
return __awaiter(this, arguments, void 0, function* ({ revenue_cat_user_id }) {
|
|
219
|
+
return __awaiter(this, arguments, void 0, function* ({ revenue_cat_user_id, include_advanced_analysis }) {
|
|
172
220
|
try {
|
|
173
221
|
const project_id = yield async_storage_1.default.getItem('mobiqo_project_id');
|
|
174
222
|
if (!project_id) {
|
|
@@ -180,7 +228,7 @@ class Mobiqo {
|
|
|
180
228
|
headers: {
|
|
181
229
|
"Content-Type": "application/json"
|
|
182
230
|
},
|
|
183
|
-
body: JSON.stringify({ revenue_cat_user_id })
|
|
231
|
+
body: JSON.stringify({ revenue_cat_user_id, project_id, include_advanced_analysis })
|
|
184
232
|
});
|
|
185
233
|
const responseData = yield response.json();
|
|
186
234
|
return responseData;
|
|
@@ -251,7 +299,7 @@ class Mobiqo {
|
|
|
251
299
|
/**
|
|
252
300
|
* Send a heartbeat to maintain the user session
|
|
253
301
|
*
|
|
254
|
-
* Heartbeats are automatically sent every
|
|
302
|
+
* Heartbeats are automatically sent every 20 seconds after syncUser() is called.
|
|
255
303
|
* This helps track active session duration and is handled internally by the SDK.
|
|
256
304
|
*
|
|
257
305
|
* @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.
|
|
3
|
+
"version": "0.0.10",
|
|
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
|
}
|