react-native-edgee 1.0.7 → 1.0.9
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 +83 -143
- package/dist/core/queue.js +22 -9
- package/dist/index.js +3 -0
- package/dist/native-context.js +4 -1
- package/dist/types.d.ts +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Edgee data collection sdk for React Native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
For React Native applications, we provide a comprehensive SDK that enables
|
|
4
|
+
seamless data collection with rich native context. This SDK automatically
|
|
5
|
+
collects 30+ device and app data points while maintaining privacy compliance
|
|
6
|
+
and optimal performance.
|
|
4
7
|
|
|
5
|
-
##
|
|
8
|
+
## Installation
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
- **🔒 Privacy-First**: GDPR/CCPA compliant with optional device ID collection
|
|
9
|
-
- **📶 Offline Queue**: Events are persisted and retried when network is available
|
|
10
|
-
- **⚡ Lightweight**: Minimal impact on app size (~100KB total)
|
|
11
|
-
- **🎯 Type-Safe**: Full TypeScript support with comprehensive type definitions
|
|
12
|
-
- **📍 Auto Screen Tracking**: Optional helpers for Expo Router and React Navigation
|
|
13
|
-
- **🔄 Graceful Fallback**: Works without native modules (Expo Go compatible)
|
|
14
|
-
|
|
15
|
-
## 📦 Installation
|
|
16
|
-
|
|
17
|
-
### Step 1: Install Package & Dependencies
|
|
10
|
+
### Step 1: Install Package and Dependencies
|
|
18
11
|
|
|
19
12
|
```bash
|
|
20
13
|
# npm
|
|
@@ -29,10 +22,9 @@ npx expo install react-native-edgee @react-native-async-storage/async-storage @r
|
|
|
29
22
|
|
|
30
23
|
### Step 2: Platform Setup
|
|
31
24
|
|
|
32
|
-
Choose your platform setup:
|
|
25
|
+
Choose your platform setup based on your React Native environment:
|
|
33
26
|
|
|
34
|
-
|
|
35
|
-
<summary><strong>📱 React Native CLI (Full Native Context)</strong></summary>
|
|
27
|
+
#### React Native CLI
|
|
36
28
|
|
|
37
29
|
**iOS:**
|
|
38
30
|
```bash
|
|
@@ -54,7 +46,7 @@ public class MainApplication extends Application implements ReactApplication {
|
|
|
54
46
|
@SuppressWarnings("UnnecessaryLocalVariable")
|
|
55
47
|
List<ReactPackage> packages = new PackageList(this).getPackages();
|
|
56
48
|
|
|
57
|
-
packages.add(new EdgeeReactNativePackage()); //
|
|
49
|
+
packages.add(new EdgeeReactNativePackage()); // Add this line
|
|
58
50
|
|
|
59
51
|
return packages;
|
|
60
52
|
}
|
|
@@ -75,10 +67,7 @@ public class MainApplication extends Application implements ReactApplication {
|
|
|
75
67
|
npx react-native run-android
|
|
76
68
|
```
|
|
77
69
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
<details>
|
|
81
|
-
<summary><strong>⚡ Expo Development Build (Full Native Context)</strong></summary>
|
|
70
|
+
#### Expo Development Build
|
|
82
71
|
|
|
83
72
|
```bash
|
|
84
73
|
# Install the package
|
|
@@ -89,20 +78,16 @@ npx expo run:ios # For iOS
|
|
|
89
78
|
npx expo run:android # For Android
|
|
90
79
|
```
|
|
91
80
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
</details>
|
|
81
|
+
Note: Native modules require a development build, not Expo Go.
|
|
95
82
|
|
|
96
|
-
|
|
97
|
-
<summary><strong>📱 Expo Go (JavaScript Context Only)</strong></summary>
|
|
83
|
+
#### Expo Go
|
|
98
84
|
|
|
99
85
|
```bash
|
|
100
86
|
npx expo install react-native-edgee @react-native-async-storage/async-storage @react-native-community/netinfo
|
|
101
87
|
```
|
|
102
88
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
</details>
|
|
89
|
+
Limitations: Native context collection is disabled. Only basic JavaScript
|
|
90
|
+
context (screen size, platform, locale) will be available.
|
|
106
91
|
|
|
107
92
|
### Step 3: Verify Installation
|
|
108
93
|
|
|
@@ -116,9 +101,7 @@ console.log('Native modules available:', isNativeModuleAvailable());
|
|
|
116
101
|
// Should log: false (Expo Go)
|
|
117
102
|
```
|
|
118
103
|
|
|
119
|
-
##
|
|
120
|
-
|
|
121
|
-
### Basic Setup
|
|
104
|
+
## Quick Start
|
|
122
105
|
|
|
123
106
|
```typescript
|
|
124
107
|
import { EdgeeClient } from 'react-native-edgee';
|
|
@@ -126,12 +109,26 @@ import { EdgeeClient } from 'react-native-edgee';
|
|
|
126
109
|
// Create client instance
|
|
127
110
|
export const edgee = new EdgeeClient({
|
|
128
111
|
host: "https://your-edgee-host.com",
|
|
129
|
-
debug: false, // Set to true
|
|
112
|
+
debug: false, // Set to true to enable debug logging and debugger in the Edgee console
|
|
130
113
|
collectDeviceId: false, // Set to true if you need unique device tracking
|
|
131
114
|
});
|
|
132
115
|
```
|
|
133
116
|
|
|
134
|
-
|
|
117
|
+
Replace `https://your-edgee-host.com` with the URL provided in the Edgee
|
|
118
|
+
console, in the project overview section.
|
|
119
|
+
|
|
120
|
+
## Events
|
|
121
|
+
|
|
122
|
+
### Screen event
|
|
123
|
+
|
|
124
|
+
The `edgee.screen()` method expects the following parameters:
|
|
125
|
+
|
|
126
|
+
field | type | description
|
|
127
|
+
----- | ---- | ---
|
|
128
|
+
`screen_obj` (required) | object | A free-form dictionary object containing properties of the `screen` event. This object has to include the `screen_name` field, and can include the `screen_class` and `properties` fields.
|
|
129
|
+
`components` (optional) | object | Specifies which analytics components should receive the event data. This allows for targeted data sending based on your configured components within the Edgee platform.
|
|
130
|
+
|
|
131
|
+
Example:
|
|
135
132
|
|
|
136
133
|
```typescript
|
|
137
134
|
// Track screen views
|
|
@@ -143,16 +140,44 @@ edgee.screen({
|
|
|
143
140
|
loaded_time: Date.now()
|
|
144
141
|
}
|
|
145
142
|
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Track event
|
|
146
|
+
|
|
147
|
+
The `edgee.track()` method expects the following parameters:
|
|
146
148
|
|
|
147
|
-
|
|
149
|
+
field | type | description
|
|
150
|
+
----- | ---- | ---
|
|
151
|
+
`track_obj` (required) | object | A free-form dictionary object containing properties of the `track` event. This object has to include the `name` field, and can include the `screen_name` and `screen_class` fields, and the `properties` field.
|
|
152
|
+
`components` (optional) | object | Specifies which analytics components should receive the event data. This allows for targeted data sending based on your configured components within the Edgee platform.
|
|
153
|
+
|
|
154
|
+
Example:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
// Track events (automatically includes rich native context)
|
|
148
158
|
edgee.track({
|
|
149
|
-
name: 'App Launched',
|
|
159
|
+
name: 'App Launched',
|
|
160
|
+
screen_name: 'Home Screen',
|
|
161
|
+
screen_class: '/',
|
|
150
162
|
properties: {
|
|
151
163
|
source: 'cold_start',
|
|
152
164
|
version: '1.0.0'
|
|
153
165
|
}
|
|
154
166
|
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### User event
|
|
155
170
|
|
|
171
|
+
The `edgee.user()` method expects the following parameters:
|
|
172
|
+
|
|
173
|
+
field | type | description
|
|
174
|
+
----- | ---- | ---
|
|
175
|
+
`user_obj` (required) | object | A free-form dictionary object containing properties of the `user` event. This object has to include the `user_id` field, and can include the `properties` field.
|
|
176
|
+
`components` (optional) | object | Specifies which analytics components should receive the event data. This allows for targeted data sending based on your configured components within the Edgee platform.
|
|
177
|
+
|
|
178
|
+
Example:
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
156
181
|
// Track user information
|
|
157
182
|
edgee.user({
|
|
158
183
|
user_id: '123',
|
|
@@ -163,11 +188,14 @@ edgee.user({
|
|
|
163
188
|
});
|
|
164
189
|
```
|
|
165
190
|
|
|
166
|
-
### Consent
|
|
191
|
+
### Consent (Optional)
|
|
192
|
+
|
|
193
|
+
To define the consent status, you can use the `edgee.consent()` method.
|
|
167
194
|
|
|
168
195
|
```typescript
|
|
169
196
|
// Set consent - all tracking calls automatically respect this setting
|
|
170
|
-
|
|
197
|
+
// 'granted', 'denied', or 'pending'
|
|
198
|
+
await edgee.consent('granted');
|
|
171
199
|
|
|
172
200
|
// Check consent status
|
|
173
201
|
console.log('Current consent:', edgee.getConsent());
|
|
@@ -181,34 +209,7 @@ const unsubscribe = edgee.onConsentChange((status) => {
|
|
|
181
209
|
await edgee.resetConsent();
|
|
182
210
|
```
|
|
183
211
|
|
|
184
|
-
|
|
185
|
-
- 🔒 **Transparent**: No need to check consent before each tracking call
|
|
186
|
-
- 📡 **Auto-sync**: Consent events automatically sent to your Edgee server
|
|
187
|
-
- 💾 **Persistent**: Consent preference stored locally and remembered
|
|
188
|
-
- 🎯 **Compliant**: GDPR/CCPA ready with proper consent management
|
|
189
|
-
|
|
190
|
-
## 📱 Rich Native Context
|
|
191
|
-
|
|
192
|
-
With native modules enabled, each event automatically includes comprehensive context:
|
|
193
|
-
|
|
194
|
-
### App Information
|
|
195
|
-
- App name, version, build number
|
|
196
|
-
- Bundle/package identifier
|
|
197
|
-
- Installation and update timestamps
|
|
198
|
-
|
|
199
|
-
### Device Information
|
|
200
|
-
- Device model, manufacturer, brand
|
|
201
|
-
- Screen dimensions, density, scale
|
|
202
|
-
- Hardware capabilities (tablet, simulator/emulator detection)
|
|
203
|
-
|
|
204
|
-
### System Information
|
|
205
|
-
- OS name and version
|
|
206
|
-
- Locale, language, country, timezone
|
|
207
|
-
- Memory usage, storage info
|
|
208
|
-
- Battery level and state (iOS)
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
## ⚙️ Configuration
|
|
212
|
+
## Configuration
|
|
212
213
|
|
|
213
214
|
```typescript
|
|
214
215
|
interface EdgeeConfig {
|
|
@@ -219,59 +220,7 @@ interface EdgeeConfig {
|
|
|
219
220
|
}
|
|
220
221
|
```
|
|
221
222
|
|
|
222
|
-
|
|
223
|
-
## 🧪 Testing with EdgeeTestApp
|
|
224
|
-
|
|
225
|
-
The repository includes a test app (`EdgeeTestApp/`) that allows you to quickly test the SDK functionality without integrating it into your own app.
|
|
226
|
-
|
|
227
|
-
### Running the Test App
|
|
228
|
-
|
|
229
|
-
1. **Navigate to the test app directory:**
|
|
230
|
-
```bash
|
|
231
|
-
cd EdgeeTestApp
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
2. **Install dependencies:**
|
|
235
|
-
```bash
|
|
236
|
-
npm install
|
|
237
|
-
# or
|
|
238
|
-
yarn install
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
3. **For iOS - Install pods:**
|
|
242
|
-
```bash
|
|
243
|
-
cd ios && pod install && cd ..
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
4. **Start Metro bundler:**
|
|
247
|
-
```bash
|
|
248
|
-
npm start
|
|
249
|
-
# or
|
|
250
|
-
yarn start
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
Then type i to launch an iOS app, or a for Android
|
|
254
|
-
|
|
255
|
-
### Using the Test App
|
|
256
|
-
|
|
257
|
-
The test app provides a simple UI to test all SDK features:
|
|
258
|
-
|
|
259
|
-
1. **Set Edgee Host**: Enter your Edgee endpoint URL (defaults to `https://demo.edgee.app`)
|
|
260
|
-
- Click "Init" to initialize the SDK with your host
|
|
261
|
-
|
|
262
|
-
2. **Test Events**:
|
|
263
|
-
- **Track Event**: Enter an event name and click "Track Event" to send a track event
|
|
264
|
-
- **Screen Event**: Click "Screen Event" to track a screen view
|
|
265
|
-
- **User Event**: Click "User Event" to send user identification data
|
|
266
|
-
|
|
267
|
-
3. **Test Consent Management**:
|
|
268
|
-
- Click "Pending", "Granted", or "Denied" to set consent status
|
|
269
|
-
- Click "Get Consent" to view the current consent status
|
|
270
|
-
|
|
271
|
-
4. **Monitor Status**: The status bar at the bottom shows the result of each action
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
### Debug Mode
|
|
223
|
+
## Debug Mode
|
|
275
224
|
|
|
276
225
|
Enable debug logging to see what's happening:
|
|
277
226
|
|
|
@@ -282,33 +231,24 @@ const edgee = new EdgeeClient({
|
|
|
282
231
|
});
|
|
283
232
|
```
|
|
284
233
|
|
|
285
|
-
##
|
|
234
|
+
## Compatibility
|
|
286
235
|
|
|
287
236
|
| Platform | Version | Native Context | Auto-Linking |
|
|
288
237
|
|----------|---------|----------------|--------------|
|
|
289
|
-
|
|
|
290
|
-
|
|
|
291
|
-
|
|
|
292
|
-
|
|
|
293
|
-
|
|
|
294
|
-
|
|
295
|
-
## 📚 TypeScript Support
|
|
296
|
-
|
|
297
|
-
Full TypeScript support with comprehensive type definitions:
|
|
298
|
-
|
|
299
|
-
```typescript
|
|
300
|
-
import type {
|
|
301
|
-
EdgeeNativeContext,
|
|
302
|
-
EdgeeClientContext,
|
|
303
|
-
EdgeeConfig
|
|
304
|
-
} from 'react-native-edgee';
|
|
305
|
-
```
|
|
238
|
+
| React Native | 0.72+ | Full | iOS: Yes, Android: Manual |
|
|
239
|
+
| iOS | 11.0+ | Full | CocoaPods |
|
|
240
|
+
| Android | API 21+ | Full | Manual setup |
|
|
241
|
+
| Expo Dev Build | Latest | Full | Automatic |
|
|
242
|
+
| Expo Go | Latest | Fallback | N/A |
|
|
306
243
|
|
|
307
|
-
##
|
|
244
|
+
## Next Steps
|
|
308
245
|
|
|
309
|
-
|
|
246
|
+
After integrating the React Native SDK, you are ready to start using Edgee's
|
|
247
|
+
services.
|
|
310
248
|
|
|
311
|
-
|
|
249
|
+
In the Services section, you will find guides on activating and customizing
|
|
250
|
+
features such as advanced analytics, A/B testing, security, and more:
|
|
251
|
+
https://www.edgee.cloud/docs/proxy/services/overview
|
|
312
252
|
|
|
313
|
-
|
|
314
|
-
|
|
253
|
+
For more details about the React Native SDK, visit:
|
|
254
|
+
https://github.com/edgee-cloud/react-native-edgee
|
package/dist/core/queue.js
CHANGED
|
@@ -25,8 +25,14 @@ class EventQueue {
|
|
|
25
25
|
this.online = !!state.isConnected && !!state.isInternetReachable;
|
|
26
26
|
});
|
|
27
27
|
void edgee_store_1.edgeeStore.getPendingEvents().then((events) => {
|
|
28
|
-
|
|
28
|
+
// Merge persisted events with any events that were added during initialization
|
|
29
|
+
// to avoid losing events due to race conditions
|
|
30
|
+
const existingEvents = this.q;
|
|
31
|
+
this.q = [...events, ...existingEvents];
|
|
29
32
|
this.ready = true;
|
|
33
|
+
// Trigger flush now that we're ready
|
|
34
|
+
if (this.shouldFlush())
|
|
35
|
+
void this.flush();
|
|
30
36
|
});
|
|
31
37
|
}
|
|
32
38
|
destroy() {
|
|
@@ -41,8 +47,9 @@ class EventQueue {
|
|
|
41
47
|
enqueue(item) {
|
|
42
48
|
this.q.push(item);
|
|
43
49
|
void edgee_store_1.edgeeStore.addEvent(item);
|
|
44
|
-
if (this.shouldFlush())
|
|
50
|
+
if (this.shouldFlush()) {
|
|
45
51
|
void this.flush();
|
|
52
|
+
}
|
|
46
53
|
}
|
|
47
54
|
/**
|
|
48
55
|
* Send a direct payload (used for consent events)
|
|
@@ -66,26 +73,32 @@ class EventQueue {
|
|
|
66
73
|
return this.ready && this.online && this.q.length > 0;
|
|
67
74
|
}
|
|
68
75
|
async flush() {
|
|
69
|
-
if (this.flushing || !this.shouldFlush())
|
|
76
|
+
if (this.flushing || !this.shouldFlush()) {
|
|
70
77
|
return;
|
|
78
|
+
}
|
|
71
79
|
this.flushing = true;
|
|
72
|
-
|
|
80
|
+
// Take items from the queue atomically using splice
|
|
81
|
+
// This prevents losing events that are added during flush
|
|
82
|
+
const itemsToFlush = this.q.splice(0, this.q.length);
|
|
83
|
+
(0, utils_1.log)(this.config, `Flushing ${itemsToFlush.length} event(s)...`);
|
|
73
84
|
try {
|
|
74
|
-
for (const item of
|
|
85
|
+
for (const item of itemsToFlush) {
|
|
75
86
|
await (0, api_1.uploadEvent)(this.config, item);
|
|
87
|
+
(0, utils_1.log)(this.config, `Event sent: ${item.type} - ${item.data.name || 'user'}`);
|
|
76
88
|
}
|
|
77
|
-
|
|
89
|
+
// Only clear persisted events after successful send
|
|
78
90
|
await edgee_store_1.edgeeStore.clearEvents();
|
|
79
91
|
}
|
|
80
92
|
catch (error) {
|
|
81
93
|
(0, utils_1.logError)("Error processing event batch.", error);
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
// On error, re-add failed items to the front of the queue for retry
|
|
95
|
+
this.q.unshift(...itemsToFlush);
|
|
84
96
|
}
|
|
85
97
|
finally {
|
|
86
98
|
this.flushing = false;
|
|
99
|
+
// Drain any events that were added during flush
|
|
87
100
|
if (this.shouldFlush())
|
|
88
|
-
void this.flush();
|
|
101
|
+
void this.flush();
|
|
89
102
|
}
|
|
90
103
|
}
|
|
91
104
|
}
|
package/dist/index.js
CHANGED
|
@@ -64,6 +64,7 @@ class EdgeeClient {
|
|
|
64
64
|
}
|
|
65
65
|
const event = (0, api_1.createScreenEvent)(restData, components, context);
|
|
66
66
|
this.queue.enqueue(event);
|
|
67
|
+
(0, utils_1.log)(this.config, "SCREEN event queued:", screen_name);
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
70
|
* Track a custom event
|
|
@@ -83,6 +84,7 @@ class EdgeeClient {
|
|
|
83
84
|
}
|
|
84
85
|
const event = (0, api_1.createTrackEvent)(restData, components, context);
|
|
85
86
|
this.queue.enqueue(event);
|
|
87
|
+
(0, utils_1.log)(this.config, "TRACK event queued:", data.name);
|
|
86
88
|
}
|
|
87
89
|
/**
|
|
88
90
|
* Track a user event
|
|
@@ -91,6 +93,7 @@ class EdgeeClient {
|
|
|
91
93
|
const context = await (0, context_1.getContext)(this.config);
|
|
92
94
|
const event = (0, api_1.createUserEvent)(data, components, context);
|
|
93
95
|
this.queue.enqueue(event);
|
|
96
|
+
(0, utils_1.log)(this.config, "USER event queued:", data.user_id || data.anonymous_id || "anonymous");
|
|
94
97
|
}
|
|
95
98
|
/**
|
|
96
99
|
* Send consent event directly to Edgee (matches web SDK format)
|
package/dist/native-context.js
CHANGED
|
@@ -37,7 +37,10 @@ async function getNativeContext(collectDeviceId) {
|
|
|
37
37
|
if (contextPromise) {
|
|
38
38
|
return contextPromise;
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
const config = {
|
|
41
|
+
collectDeviceId: collectDeviceId,
|
|
42
|
+
};
|
|
43
|
+
contextPromise = EdgeeReactNative.getContextInfo(config)
|
|
41
44
|
.then((context) => {
|
|
42
45
|
cachedContext = context;
|
|
43
46
|
contextPromise = null;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { NativeModule } from "react-native";
|
|
2
|
+
export interface EdgeeNativeContextConfig {
|
|
3
|
+
collectDeviceId?: boolean;
|
|
4
|
+
}
|
|
2
5
|
export interface EdgeeNativeContext {
|
|
3
6
|
appName: string;
|
|
4
7
|
appVersion: string;
|
|
@@ -57,5 +60,5 @@ export interface EdgeeNativeContext {
|
|
|
57
60
|
lastUpdateTime?: number;
|
|
58
61
|
}
|
|
59
62
|
export interface EdgeeReactNativeModule extends NativeModule {
|
|
60
|
-
getContextInfo(
|
|
63
|
+
getContextInfo(config: EdgeeNativeContextConfig): Promise<EdgeeNativeContext>;
|
|
61
64
|
}
|