mobiqo-react-native 0.0.8 → 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 +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.js +48 -4
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -93,7 +93,7 @@ const userInfo = await mobiqo.getUserInfo({
|
|
|
93
93
|
|
|
94
94
|
### Automatic Session Tracking
|
|
95
95
|
|
|
96
|
-
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.
|
|
97
97
|
|
|
98
98
|
## API Reference
|
|
99
99
|
|
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 */
|
|
@@ -112,11 +114,21 @@ 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
|
|
@@ -205,7 +217,7 @@ export default class Mobiqo {
|
|
|
205
217
|
/**
|
|
206
218
|
* Send a heartbeat to maintain the user session
|
|
207
219
|
*
|
|
208
|
-
* Heartbeats are automatically sent every
|
|
220
|
+
* Heartbeats are automatically sent every 20 seconds after syncUser() is called.
|
|
209
221
|
* This helps track active session duration and is handled internally by the SDK.
|
|
210
222
|
*
|
|
211
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
|
/**
|
|
@@ -87,11 +88,53 @@ 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
|
|
@@ -127,12 +170,13 @@ class Mobiqo {
|
|
|
127
170
|
console.error('Project ID not found');
|
|
128
171
|
return;
|
|
129
172
|
}
|
|
173
|
+
const device_model = this.getDeviceModel();
|
|
130
174
|
const response = yield fetch(this.API_URL + "/linkUser", {
|
|
131
175
|
method: "POST",
|
|
132
176
|
headers: {
|
|
133
177
|
"Content-Type": "application/json"
|
|
134
178
|
},
|
|
135
|
-
body: JSON.stringify({ revenue_cat_user_id, project_id, include_advanced_analysis, 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() })
|
|
136
180
|
});
|
|
137
181
|
const responseData = yield response.json();
|
|
138
182
|
yield async_storage_1.default.setItem('mobiqo_session_id', responseData.sessionId);
|
|
@@ -140,7 +184,7 @@ class Mobiqo {
|
|
|
140
184
|
if (!this.heartbeatInterval) {
|
|
141
185
|
this.heartbeatInterval = setInterval(() => {
|
|
142
186
|
this.sendHeartbeat();
|
|
143
|
-
},
|
|
187
|
+
}, 20000); // 20 seconds
|
|
144
188
|
}
|
|
145
189
|
return responseData;
|
|
146
190
|
}
|
|
@@ -255,7 +299,7 @@ class Mobiqo {
|
|
|
255
299
|
/**
|
|
256
300
|
* Send a heartbeat to maintain the user session
|
|
257
301
|
*
|
|
258
|
-
* Heartbeats are automatically sent every
|
|
302
|
+
* Heartbeats are automatically sent every 20 seconds after syncUser() is called.
|
|
259
303
|
* This helps track active session duration and is handled internally by the SDK.
|
|
260
304
|
*
|
|
261
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
|
}
|