react-native-edgee 1.0.6 → 1.0.8
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 +99 -354
- package/dist/api.d.ts +15 -13
- package/dist/api.js +29 -43
- package/dist/core/context.d.ts +4 -1
- package/dist/core/context.js +7 -5
- package/dist/core/edgee-store.d.ts +3 -2
- package/dist/core/edgee-store.js +16 -2
- package/dist/index.d.ts +7 -6
- package/dist/index.js +41 -143
- package/dist/native-context.d.ts +2 -2
- package/dist/native-context.js +20 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
# react-native-edgee
|
|
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,347 +109,118 @@ 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:
|
|
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.
|
|
135
119
|
|
|
136
|
-
|
|
137
|
-
// Track events (automatically includes rich native context)
|
|
138
|
-
// Consent is handled transparently - no need to check before each call!
|
|
139
|
-
edgee.track('App Launched', {
|
|
140
|
-
source: 'cold_start',
|
|
141
|
-
version: '1.0.0'
|
|
142
|
-
});
|
|
120
|
+
## Events
|
|
143
121
|
|
|
144
|
-
|
|
145
|
-
edgee.user({
|
|
146
|
-
id: '123',
|
|
147
|
-
email: 'user@example.com',
|
|
148
|
-
plan: 'premium'
|
|
149
|
-
});
|
|
122
|
+
### Screen event
|
|
150
123
|
|
|
151
|
-
|
|
152
|
-
edgee.screen('Home Screen', {
|
|
153
|
-
category: 'main',
|
|
154
|
-
loaded_time: Date.now()
|
|
155
|
-
});
|
|
156
|
-
```
|
|
124
|
+
The `edgee.screen()` method expects the following parameters:
|
|
157
125
|
|
|
158
|
-
|
|
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.
|
|
159
130
|
|
|
160
|
-
|
|
161
|
-
// Set consent - all tracking calls automatically respect this setting
|
|
162
|
-
await edgee.setConsent('granted'); // 'granted', 'denied', or 'pending'
|
|
131
|
+
Example:
|
|
163
132
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
133
|
+
```typescript
|
|
134
|
+
// Track screen views
|
|
135
|
+
edgee.screen({
|
|
136
|
+
screen_name: 'Home Screen',
|
|
137
|
+
screen_class: '/',
|
|
138
|
+
properties: {
|
|
139
|
+
category: 'main',
|
|
140
|
+
loaded_time: Date.now()
|
|
141
|
+
}
|
|
171
142
|
});
|
|
172
|
-
|
|
173
|
-
// Reset consent
|
|
174
|
-
await edgee.resetConsent();
|
|
175
143
|
```
|
|
176
144
|
|
|
177
|
-
|
|
178
|
-
- 🔒 **Transparent**: No need to check consent before each tracking call
|
|
179
|
-
- 📡 **Auto-sync**: Consent events automatically sent to your Edgee server
|
|
180
|
-
- 💾 **Persistent**: Consent preference stored locally and remembered
|
|
181
|
-
- 🎯 **Compliant**: GDPR/CCPA ready with proper consent management
|
|
145
|
+
### Track event
|
|
182
146
|
|
|
183
|
-
|
|
147
|
+
The `edgee.track()` method expects the following parameters:
|
|
184
148
|
|
|
185
|
-
|
|
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.
|
|
186
153
|
|
|
187
|
-
|
|
188
|
-
- App name, version, build number
|
|
189
|
-
- Bundle/package identifier
|
|
190
|
-
- Installation and update timestamps
|
|
154
|
+
Example:
|
|
191
155
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
156
|
+
```typescript
|
|
157
|
+
// Track events (automatically includes rich native context)
|
|
158
|
+
edgee.track({
|
|
159
|
+
name: 'App Launched',
|
|
160
|
+
screen_name: 'Home Screen',
|
|
161
|
+
screen_class: '/',
|
|
162
|
+
properties: {
|
|
163
|
+
source: 'cold_start',
|
|
164
|
+
version: '1.0.0'
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
```
|
|
202
168
|
|
|
203
|
-
###
|
|
204
|
-
- Connection type (WiFi, cellular, ethernet)
|
|
205
|
-
- Carrier name and network codes
|
|
206
|
-
- Radio technology (3G, 4G, 5G)
|
|
169
|
+
### User event
|
|
207
170
|
|
|
208
|
-
|
|
209
|
-
- Advertising ID (with proper consent on iOS 14+)
|
|
210
|
-
- Device ID (privacy-compliant, opt-in only)
|
|
211
|
-
- Tracking authorization status
|
|
171
|
+
The `edgee.user()` method expects the following parameters:
|
|
212
172
|
|
|
213
|
-
|
|
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.
|
|
214
177
|
|
|
215
|
-
|
|
178
|
+
Example:
|
|
216
179
|
|
|
217
180
|
```typescript
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Use in components
|
|
230
|
-
function SomeComponent() {
|
|
231
|
-
const edgee = useEdgee();
|
|
232
|
-
|
|
233
|
-
const handleButtonPress = () => {
|
|
234
|
-
// Tracking automatically respects consent - no need to check!
|
|
235
|
-
edgee.track('Button Pressed', { button_id: 'cta_main' });
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
const handleConsentGrant = async () => {
|
|
239
|
-
await edgee.setConsent('granted');
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
return (
|
|
243
|
-
<View>
|
|
244
|
-
<Button onPress={handleButtonPress} title="Track Me" />
|
|
245
|
-
<Button onPress={handleConsentGrant} title="Grant Consent" />
|
|
246
|
-
</View>
|
|
247
|
-
);
|
|
248
|
-
}
|
|
181
|
+
// Track user information
|
|
182
|
+
edgee.user({
|
|
183
|
+
user_id: '123',
|
|
184
|
+
properties: {
|
|
185
|
+
email: 'user@example.com',
|
|
186
|
+
plan: 'premium'
|
|
187
|
+
}
|
|
188
|
+
});
|
|
249
189
|
```
|
|
250
190
|
|
|
251
|
-
###
|
|
191
|
+
### Consent (Optional)
|
|
252
192
|
|
|
253
|
-
|
|
254
|
-
<summary><strong>Expo Router</strong></summary>
|
|
193
|
+
To define the consent status, you can use the `edgee.consent()` method.
|
|
255
194
|
|
|
256
195
|
```typescript
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return (
|
|
261
|
-
<>
|
|
262
|
-
<EdgeeAutoTracker edgee={edgee} />
|
|
263
|
-
<Stack>
|
|
264
|
-
<Stack.Screen name="index" />
|
|
265
|
-
<Stack.Screen name="profile" />
|
|
266
|
-
</Stack>
|
|
267
|
-
</>
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
```
|
|
196
|
+
// Set consent - all tracking calls automatically respect this setting
|
|
197
|
+
// 'granted', 'denied', or 'pending'
|
|
198
|
+
await edgee.consent('granted');
|
|
271
199
|
|
|
272
|
-
|
|
200
|
+
// Check consent status
|
|
201
|
+
console.log('Current consent:', edgee.getConsent());
|
|
273
202
|
|
|
274
|
-
|
|
275
|
-
|
|
203
|
+
// Listen for consent changes
|
|
204
|
+
const unsubscribe = edgee.onConsentChange((status) => {
|
|
205
|
+
console.log('Consent changed to:', status);
|
|
206
|
+
});
|
|
276
207
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const navigationRef = useRef();
|
|
281
|
-
|
|
282
|
-
return (
|
|
283
|
-
<NavigationContainer
|
|
284
|
-
ref={navigationRef}
|
|
285
|
-
onStateChange={() => {
|
|
286
|
-
navigation.trackScreenChange(navigationRef, edgee);
|
|
287
|
-
}}
|
|
288
|
-
>
|
|
289
|
-
{/* Your navigation structure */}
|
|
290
|
-
</NavigationContainer>
|
|
291
|
-
);
|
|
208
|
+
// Reset consent
|
|
209
|
+
await edgee.resetConsent();
|
|
292
210
|
```
|
|
293
211
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
## ⚙️ Configuration
|
|
212
|
+
## Configuration
|
|
297
213
|
|
|
298
214
|
```typescript
|
|
299
215
|
interface EdgeeConfig {
|
|
300
216
|
host: string; // Your Edgee endpoint URL (required)
|
|
301
217
|
debug?: boolean; // Enable debug logging (default: false)
|
|
302
218
|
collectDeviceId?: boolean; // Collect unique device ID (default: false)
|
|
219
|
+
cookieName?: string // Name of the cookie used by Edgee (it must be identical to the one on the console. Do not change it if you are unsure).
|
|
303
220
|
}
|
|
304
221
|
```
|
|
305
222
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
- **Device ID Collection**: Only enable `collectDeviceId: true` if you need persistent device tracking
|
|
309
|
-
- **iOS Advertising ID**: Automatically respects App Tracking Transparency (iOS 14+)
|
|
310
|
-
- **GDPR/CCPA Compliance**: All sensitive data collection is optional and clearly documented
|
|
311
|
-
|
|
312
|
-
## 🔧 Advanced Usage
|
|
313
|
-
|
|
314
|
-
### Manual Native Context Access
|
|
315
|
-
|
|
316
|
-
```typescript
|
|
317
|
-
import { getNativeContext, isNativeModuleAvailable } from 'react-native-edgee';
|
|
318
|
-
|
|
319
|
-
// Check if native modules are available
|
|
320
|
-
if (isNativeModuleAvailable()) {
|
|
321
|
-
const context = await getNativeContext({ collectDeviceId: false });
|
|
322
|
-
console.log('Device model:', context.model);
|
|
323
|
-
console.log('Is tablet:', context.isTablet);
|
|
324
|
-
console.log('Network type:', context.networkType);
|
|
325
|
-
console.log('Total memory:', context.totalMemoryMB);
|
|
326
|
-
}
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
### Context Caching
|
|
330
|
-
|
|
331
|
-
```typescript
|
|
332
|
-
import { clearContextCache } from 'react-native-edgee';
|
|
333
|
-
|
|
334
|
-
// Clear cached context (useful for testing or when context might change)
|
|
335
|
-
clearContextCache();
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
## 🧪 Testing with EdgeeTestApp
|
|
339
|
-
|
|
340
|
-
The repository includes a test app (`EdgeeTestApp/`) that allows you to quickly test the SDK functionality without integrating it into your own app.
|
|
341
|
-
|
|
342
|
-
### Running the Test App
|
|
343
|
-
|
|
344
|
-
1. **Navigate to the test app directory:**
|
|
345
|
-
```bash
|
|
346
|
-
cd EdgeeTestApp
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
2. **Install dependencies:**
|
|
350
|
-
```bash
|
|
351
|
-
npm install
|
|
352
|
-
# or
|
|
353
|
-
yarn install
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
3. **For iOS - Install pods:**
|
|
357
|
-
```bash
|
|
358
|
-
cd ios && pod install && cd ..
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
4. **Start Metro bundler:**
|
|
362
|
-
```bash
|
|
363
|
-
npm start
|
|
364
|
-
# or
|
|
365
|
-
yarn start
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
5. **Run the app:**
|
|
369
|
-
```bash
|
|
370
|
-
# iOS
|
|
371
|
-
npm run ios
|
|
372
|
-
# or
|
|
373
|
-
yarn ios
|
|
374
|
-
|
|
375
|
-
# Android
|
|
376
|
-
npm run android
|
|
377
|
-
# or
|
|
378
|
-
yarn android
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
### Using the Test App
|
|
382
|
-
|
|
383
|
-
The test app provides a simple UI to test all SDK features:
|
|
384
|
-
|
|
385
|
-
1. **Set Edgee Host**: Enter your Edgee endpoint URL (defaults to `https://demo.edgee.app`)
|
|
386
|
-
- Click "Init" to initialize the SDK with your host
|
|
387
|
-
|
|
388
|
-
2. **Test Events**:
|
|
389
|
-
- **Track Event**: Enter an event name and click "Track Event" to send a track event
|
|
390
|
-
- **Screen Event**: Click "Screen Event" to track a screen view
|
|
391
|
-
- **User Event**: Click "User Event" to send user identification data
|
|
392
|
-
|
|
393
|
-
3. **Test Consent Management**:
|
|
394
|
-
- Click "Pending", "Granted", or "Denied" to set consent status
|
|
395
|
-
- Click "Get Consent" to view the current consent status
|
|
396
|
-
|
|
397
|
-
4. **Monitor Status**: The status bar at the bottom shows the result of each action
|
|
398
|
-
|
|
399
|
-
### Features Demonstrated
|
|
400
|
-
|
|
401
|
-
- ✅ SDK initialization with custom host
|
|
402
|
-
- ✅ Event tracking (track, screen, user)
|
|
403
|
-
- ✅ Consent management (pending, granted, denied)
|
|
404
|
-
- ✅ Native module availability detection
|
|
405
|
-
- ✅ Debug logging (enabled by default in test app)
|
|
406
|
-
|
|
407
|
-
### Debug Mode
|
|
408
|
-
|
|
409
|
-
The test app has debug mode enabled by default, so you'll see detailed logs in Metro CLI:
|
|
410
|
-
- Event tracking logs
|
|
411
|
-
- Consent status changes
|
|
412
|
-
- Native context collection
|
|
413
|
-
- API request/response details
|
|
414
|
-
|
|
415
|
-
### Notes
|
|
416
|
-
|
|
417
|
-
- The test app uses the local `react-native-edgee` package via `file:..` in `package.json`
|
|
418
|
-
- Make sure you've built the SDK (`npm run build` in the root directory) before running the test app
|
|
419
|
-
- Native modules are automatically available if you've set up the platform correctly
|
|
420
|
-
|
|
421
|
-
## 🔍 Troubleshooting
|
|
422
|
-
|
|
423
|
-
### Common Issues
|
|
424
|
-
|
|
425
|
-
<details>
|
|
426
|
-
<summary><strong>"Module not found" Error</strong></summary>
|
|
427
|
-
|
|
428
|
-
**iOS:**
|
|
429
|
-
```bash
|
|
430
|
-
cd ios && rm -rf build && pod install && cd ..
|
|
431
|
-
npx react-native run-ios
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
**Android:**
|
|
435
|
-
- Ensure `EdgeeReactNativePackage` is added to `MainApplication.java`
|
|
436
|
-
- Clean build: `cd android && ./gradlew clean && cd ..`
|
|
437
|
-
|
|
438
|
-
</details>
|
|
439
|
-
|
|
440
|
-
<details>
|
|
441
|
-
<summary><strong>No Native Context in Events</strong></summary>
|
|
442
|
-
|
|
443
|
-
1. Check if native modules are available:
|
|
444
|
-
```typescript
|
|
445
|
-
console.log('Available:', isNativeModuleAvailable());
|
|
446
|
-
```
|
|
447
|
-
|
|
448
|
-
2. If `false`, verify platform setup above
|
|
449
|
-
3. In Expo Go, this is expected (use Expo Development Build)
|
|
450
|
-
|
|
451
|
-
</details>
|
|
452
|
-
|
|
453
|
-
<details>
|
|
454
|
-
<summary><strong>Build Errors</strong></summary>
|
|
455
|
-
|
|
456
|
-
**Clean everything:**
|
|
457
|
-
```bash
|
|
458
|
-
# React Native CLI
|
|
459
|
-
cd ios && rm -rf build && cd ..
|
|
460
|
-
cd android && ./gradlew clean && cd ..
|
|
461
|
-
npx react-native start --reset-cache
|
|
462
|
-
|
|
463
|
-
# Expo
|
|
464
|
-
npx expo run:ios --clear-cache
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
</details>
|
|
468
|
-
|
|
469
|
-
### Debug Mode
|
|
223
|
+
## Debug Mode
|
|
470
224
|
|
|
471
225
|
Enable debug logging to see what's happening:
|
|
472
226
|
|
|
@@ -477,33 +231,24 @@ const edgee = new EdgeeClient({
|
|
|
477
231
|
});
|
|
478
232
|
```
|
|
479
233
|
|
|
480
|
-
##
|
|
234
|
+
## Compatibility
|
|
481
235
|
|
|
482
236
|
| Platform | Version | Native Context | Auto-Linking |
|
|
483
237
|
|----------|---------|----------------|--------------|
|
|
484
|
-
|
|
|
485
|
-
|
|
|
486
|
-
|
|
|
487
|
-
|
|
|
488
|
-
|
|
|
489
|
-
|
|
490
|
-
## 📚 TypeScript Support
|
|
491
|
-
|
|
492
|
-
Full TypeScript support with comprehensive type definitions:
|
|
493
|
-
|
|
494
|
-
```typescript
|
|
495
|
-
import type {
|
|
496
|
-
EdgeeNativeContext,
|
|
497
|
-
EdgeeClientContext,
|
|
498
|
-
EdgeeConfig
|
|
499
|
-
} from 'react-native-edgee';
|
|
500
|
-
```
|
|
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 |
|
|
501
243
|
|
|
502
|
-
##
|
|
244
|
+
## Next Steps
|
|
503
245
|
|
|
504
|
-
|
|
246
|
+
After integrating the React Native SDK, you are ready to start using Edgee's
|
|
247
|
+
services.
|
|
505
248
|
|
|
506
|
-
|
|
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
|
|
507
252
|
|
|
508
|
-
|
|
509
|
-
|
|
253
|
+
For more details about the React Native SDK, visit:
|
|
254
|
+
https://github.com/edgee-cloud/react-native-edgee
|
package/dist/api.d.ts
CHANGED
|
@@ -6,28 +6,30 @@ declare enum EventType {
|
|
|
6
6
|
Screen = "screen"
|
|
7
7
|
}
|
|
8
8
|
export type EdgeeTrackEvent = {
|
|
9
|
-
type: EventType.Track;
|
|
10
9
|
name: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
screen_name?: string;
|
|
11
|
+
screen_class?: string;
|
|
12
|
+
properties?: object;
|
|
14
13
|
};
|
|
15
14
|
export type EdgeeUserEvent = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
context: EdgeeFullContext;
|
|
15
|
+
user_id?: string;
|
|
16
|
+
anonymous_id?: string;
|
|
17
|
+
properties?: object;
|
|
20
18
|
};
|
|
21
19
|
export type EdgeeScreenEvent = {
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
screen_name: string;
|
|
21
|
+
screen_class?: string;
|
|
22
|
+
properties?: object;
|
|
23
|
+
};
|
|
24
|
+
export type EdgeeEvent = {
|
|
25
|
+
type: EventType.Track | EventType.User | EventType.Screen;
|
|
24
26
|
data: object;
|
|
25
27
|
components: Record<string, boolean> | undefined;
|
|
26
28
|
context: EdgeeFullContext;
|
|
27
29
|
};
|
|
28
|
-
export
|
|
29
|
-
export declare const createTrackEvent: (
|
|
30
|
-
export declare const createUserEvent: (
|
|
30
|
+
export declare const createScreenEvent: (data: EdgeeScreenEvent, components: Record<string, boolean> | undefined, context: EdgeeFullContext) => EdgeeEvent;
|
|
31
|
+
export declare const createTrackEvent: (data: EdgeeTrackEvent, components: Record<string, boolean> | undefined, context: EdgeeFullContext) => EdgeeEvent;
|
|
32
|
+
export declare const createUserEvent: (data: EdgeeUserEvent, components: Record<string, boolean> | undefined, context: EdgeeFullContext) => EdgeeEvent;
|
|
31
33
|
/**
|
|
32
34
|
* Sends a payload to the Edgee API with proper headers and handles the response
|
|
33
35
|
*/
|
package/dist/api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uploadEvent = exports.sendPayload = exports.createUserEvent = exports.createTrackEvent = void 0;
|
|
3
|
+
exports.uploadEvent = exports.sendPayload = exports.createUserEvent = exports.createTrackEvent = exports.createScreenEvent = void 0;
|
|
4
4
|
const edgee_store_1 = require("./core/edgee-store");
|
|
5
5
|
const utils_1 = require("./core/utils");
|
|
6
6
|
var EventType;
|
|
@@ -9,17 +9,33 @@ var EventType;
|
|
|
9
9
|
EventType["User"] = "user";
|
|
10
10
|
EventType["Screen"] = "screen";
|
|
11
11
|
})(EventType || (EventType = {}));
|
|
12
|
-
const
|
|
12
|
+
const createScreenEvent = (data, components, context) => {
|
|
13
13
|
return {
|
|
14
14
|
type: EventType.Track,
|
|
15
|
-
|
|
15
|
+
data: {
|
|
16
|
+
name: "screen_view",
|
|
17
|
+
...data,
|
|
18
|
+
},
|
|
19
|
+
components,
|
|
20
|
+
context: context,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.createScreenEvent = createScreenEvent;
|
|
24
|
+
const createTrackEvent = (data, components, context) => {
|
|
25
|
+
return {
|
|
26
|
+
type: EventType.Track,
|
|
27
|
+
data,
|
|
28
|
+
components,
|
|
29
|
+
context: context,
|
|
16
30
|
};
|
|
17
31
|
};
|
|
18
32
|
exports.createTrackEvent = createTrackEvent;
|
|
19
|
-
const createUserEvent = (
|
|
33
|
+
const createUserEvent = (data, components, context) => {
|
|
20
34
|
return {
|
|
21
35
|
type: EventType.User,
|
|
22
|
-
|
|
36
|
+
data,
|
|
37
|
+
components,
|
|
38
|
+
context: context,
|
|
23
39
|
};
|
|
24
40
|
};
|
|
25
41
|
exports.createUserEvent = createUserEvent;
|
|
@@ -33,33 +49,11 @@ const buildEventPayload = (event) => {
|
|
|
33
49
|
events: [],
|
|
34
50
|
},
|
|
35
51
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
properties: event.data,
|
|
42
|
-
},
|
|
43
|
-
components: event.components,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
else if (event.type === EventType.User) {
|
|
47
|
-
basePayload.data_collection.events.push({
|
|
48
|
-
type: "user",
|
|
49
|
-
data: event.data,
|
|
50
|
-
components: event.components,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
else if (event.type === EventType.Screen) {
|
|
54
|
-
basePayload.data_collection.events.push({
|
|
55
|
-
type: "track",
|
|
56
|
-
data: { ...event.data, screen_name: event.name },
|
|
57
|
-
components: event.components,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
throw new Error(`Invalid event type: ${event.type}`);
|
|
62
|
-
}
|
|
52
|
+
basePayload.data_collection.events.push({
|
|
53
|
+
type: event.type,
|
|
54
|
+
data: event.data,
|
|
55
|
+
components: event.components,
|
|
56
|
+
});
|
|
63
57
|
return basePayload;
|
|
64
58
|
};
|
|
65
59
|
/**
|
|
@@ -92,6 +86,9 @@ const buildHeaders = async (config) => {
|
|
|
92
86
|
if (cookieHeader) {
|
|
93
87
|
headers["Edgee-Cookie"] = cookieHeader;
|
|
94
88
|
}
|
|
89
|
+
else {
|
|
90
|
+
headers["Edgee-Cookie"] = "";
|
|
91
|
+
}
|
|
95
92
|
return headers;
|
|
96
93
|
};
|
|
97
94
|
/**
|
|
@@ -154,17 +151,6 @@ const handleResponse = async (data, config) => {
|
|
|
154
151
|
(0, utils_1.log)(config, `Set userId: ${userId}`);
|
|
155
152
|
}
|
|
156
153
|
}
|
|
157
|
-
// Handle cookies array (data.c)
|
|
158
|
-
// Note: In React Native, we don't have browser cookies, but we log them if debug is enabled
|
|
159
|
-
if (data.c && Array.isArray(data.c) && data.c.length > 0) {
|
|
160
|
-
for (const cookie of data.c) {
|
|
161
|
-
if (cookie.name && cookie.value) {
|
|
162
|
-
(0, utils_1.log)(config, "○ Set cookie: " + cookie.name + "=" + cookie.value);
|
|
163
|
-
}
|
|
164
|
-
// In React Native, cookies are typically handled by the app's cookie store
|
|
165
|
-
// If needed, you could store them in AsyncStorage or another storage mechanism
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
154
|
// Extract events if present
|
|
169
155
|
if (data.events) {
|
|
170
156
|
events = data.events;
|
package/dist/core/context.d.ts
CHANGED
|
@@ -29,8 +29,11 @@ export interface EdgeeClientContext {
|
|
|
29
29
|
}
|
|
30
30
|
export interface EdgeePageContext {
|
|
31
31
|
title: string;
|
|
32
|
+
category: string;
|
|
32
33
|
path: string;
|
|
33
|
-
url: string
|
|
34
|
+
url: string;
|
|
35
|
+
search: string;
|
|
36
|
+
referrer: string;
|
|
34
37
|
}
|
|
35
38
|
export interface EdgeeFullContext {
|
|
36
39
|
client: EdgeeClientContext;
|
package/dist/core/context.js
CHANGED
|
@@ -9,12 +9,11 @@ const utils_1 = require("./utils");
|
|
|
9
9
|
*/
|
|
10
10
|
const getContext = async (config) => {
|
|
11
11
|
const initialUrl = await react_native_1.Linking.getInitialURL();
|
|
12
|
-
const nativeContext = await (0, native_context_1.getNativeContext)();
|
|
12
|
+
const nativeContext = await (0, native_context_1.getNativeContext)(config.collectDeviceId || false);
|
|
13
13
|
const url = initialUrl || `${(nativeContext === null || nativeContext === void 0 ? void 0 : nativeContext.bundleId) || "app"}://`;
|
|
14
14
|
let clientContext;
|
|
15
15
|
if ((0, native_context_1.isNativeModuleAvailable)()) {
|
|
16
16
|
try {
|
|
17
|
-
const nativeContext = await (0, native_context_1.getNativeContext)({ collectDeviceId: config.collectDeviceId });
|
|
18
17
|
clientContext = buildClientContextFromNative(nativeContext);
|
|
19
18
|
}
|
|
20
19
|
catch (error) {
|
|
@@ -28,9 +27,12 @@ const getContext = async (config) => {
|
|
|
28
27
|
return {
|
|
29
28
|
client: clientContext,
|
|
30
29
|
page: {
|
|
31
|
-
title: "
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
title: nativeContext.appName || "",
|
|
31
|
+
category: "",
|
|
32
|
+
path: "",
|
|
33
|
+
url: url,
|
|
34
|
+
search: "",
|
|
35
|
+
referrer: "",
|
|
34
36
|
},
|
|
35
37
|
};
|
|
36
38
|
};
|
|
@@ -6,8 +6,8 @@ export declare class EdgeeStore {
|
|
|
6
6
|
initialized: boolean;
|
|
7
7
|
constructor();
|
|
8
8
|
init(): Promise<void>;
|
|
9
|
-
getEdgeeId():
|
|
10
|
-
getUserId():
|
|
9
|
+
getEdgeeId(): string | null;
|
|
10
|
+
getUserId(): string | null;
|
|
11
11
|
setEdgeeId(edgeeId: string): Promise<void>;
|
|
12
12
|
setUserId(userId: string): Promise<void>;
|
|
13
13
|
getContext(): Promise<{
|
|
@@ -17,6 +17,7 @@ export declare class EdgeeStore {
|
|
|
17
17
|
addEvent(event: EdgeeEvent): Promise<void>;
|
|
18
18
|
getPendingEvents(): Promise<EdgeeEvent[]>;
|
|
19
19
|
clearEvents(): Promise<void>;
|
|
20
|
+
reset(): Promise<void>;
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
* Global edgee store instance
|
package/dist/core/edgee-store.js
CHANGED
|
@@ -38,10 +38,10 @@ class EdgeeStore {
|
|
|
38
38
|
this.initialized = true;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
getEdgeeId() {
|
|
42
42
|
return this.edgeeId;
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
getUserId() {
|
|
45
45
|
return this.userId;
|
|
46
46
|
}
|
|
47
47
|
async setEdgeeId(edgeeId) {
|
|
@@ -73,6 +73,20 @@ class EdgeeStore {
|
|
|
73
73
|
this.pendingEvents = [];
|
|
74
74
|
await async_storage_1.default.removeItem(STORAGE_KEYS.pendingEvents);
|
|
75
75
|
}
|
|
76
|
+
async reset() {
|
|
77
|
+
this.edgeeId = null;
|
|
78
|
+
this.userId = null;
|
|
79
|
+
this.pendingEvents = [];
|
|
80
|
+
try {
|
|
81
|
+
await async_storage_1.default.removeItem(STORAGE_KEYS.edgeeId);
|
|
82
|
+
await async_storage_1.default.removeItem(STORAGE_KEYS.userId);
|
|
83
|
+
await async_storage_1.default.removeItem(STORAGE_KEYS.pendingEvents);
|
|
84
|
+
this.initialized = false;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
(0, utils_1.logError)("Failed to reset Edgee store", error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
76
90
|
}
|
|
77
91
|
exports.EdgeeStore = EdgeeStore;
|
|
78
92
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EdgeeScreenEvent, EdgeeTrackEvent, EdgeeUserEvent } from "./api";
|
|
1
2
|
import { ConsentStatus } from "./consent";
|
|
2
3
|
export type EdgeeConfig = {
|
|
3
4
|
host: string;
|
|
@@ -16,15 +17,15 @@ export declare class EdgeeClient {
|
|
|
16
17
|
/**
|
|
17
18
|
* Track a screen view event
|
|
18
19
|
*/
|
|
19
|
-
screen(
|
|
20
|
+
screen(data: EdgeeScreenEvent, components?: Components): Promise<void>;
|
|
20
21
|
/**
|
|
21
22
|
* Track a custom event
|
|
22
23
|
*/
|
|
23
|
-
track(
|
|
24
|
+
track(data: EdgeeTrackEvent, components?: Components): Promise<void>;
|
|
24
25
|
/**
|
|
25
26
|
* Track a user event
|
|
26
27
|
*/
|
|
27
|
-
user(data:
|
|
28
|
+
user(data: EdgeeUserEvent, components?: Components): Promise<void>;
|
|
28
29
|
/**
|
|
29
30
|
* Send consent event directly to Edgee (matches web SDK format)
|
|
30
31
|
*/
|
|
@@ -33,10 +34,10 @@ export declare class EdgeeClient {
|
|
|
33
34
|
getConsent(): ConsentStatus | null;
|
|
34
35
|
hasConsent(): boolean;
|
|
35
36
|
resetConsent(): Promise<void>;
|
|
37
|
+
reset(): Promise<void>;
|
|
36
38
|
onConsentChange(callback: (status: ConsentStatus | null) => void): () => void;
|
|
37
39
|
}
|
|
38
40
|
export { EdgeeProvider, useEdgee, } from "./react";
|
|
39
|
-
export
|
|
40
|
-
export {
|
|
41
|
-
export type { EdgeeNativeContext, EdgeeNativeContextConfig, EdgeeReactNativeModule, } from "./types";
|
|
41
|
+
export { clearContextCache, isNativeModuleAvailable, } from "./native-context";
|
|
42
|
+
export type { EdgeeNativeContext, EdgeeReactNativeModule, } from "./types";
|
|
42
43
|
export type { ConsentStatus, } from "./consent";
|
package/dist/index.js
CHANGED
|
@@ -1,76 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNativeModuleAvailable = exports.
|
|
3
|
+
exports.isNativeModuleAvailable = exports.clearContextCache = exports.useEdgee = exports.EdgeeProvider = exports.EdgeeClient = void 0;
|
|
4
4
|
const react_native_1 = require("react-native");
|
|
5
5
|
const api_1 = require("./api");
|
|
6
6
|
const consent_1 = require("./consent");
|
|
7
|
-
const context_1 = require("./core/context");
|
|
8
7
|
const edgee_store_1 = require("./core/edgee-store");
|
|
8
|
+
const context_1 = require("./core/context");
|
|
9
9
|
const queue_1 = require("./core/queue");
|
|
10
10
|
const utils_1 = require("./core/utils");
|
|
11
|
-
const native_context_1 = require("./native-context");
|
|
12
11
|
const DEFAULT_COOKIE_NAME = "edgee";
|
|
13
|
-
/**
|
|
14
|
-
* Extract native context properties to include in event data under a sub-object
|
|
15
|
-
*/
|
|
16
|
-
const extractNativeProperties = (nativeContext) => {
|
|
17
|
-
if (!nativeContext)
|
|
18
|
-
return {};
|
|
19
|
-
return {
|
|
20
|
-
native_context: {
|
|
21
|
-
// Device information
|
|
22
|
-
device_id: nativeContext.deviceId,
|
|
23
|
-
device_name: nativeContext.deviceName,
|
|
24
|
-
device_type: nativeContext.deviceType,
|
|
25
|
-
manufacturer: nativeContext.manufacturer,
|
|
26
|
-
model: nativeContext.model,
|
|
27
|
-
// System information
|
|
28
|
-
os_name: nativeContext.osName,
|
|
29
|
-
os_version: nativeContext.osVersion,
|
|
30
|
-
// App information
|
|
31
|
-
app_name: nativeContext.appName,
|
|
32
|
-
app_version: nativeContext.appVersion,
|
|
33
|
-
build_number: nativeContext.buildNumber,
|
|
34
|
-
bundle_id: nativeContext.bundleId,
|
|
35
|
-
// Hardware capabilities
|
|
36
|
-
is_tablet: nativeContext.isTablet,
|
|
37
|
-
is_simulator: nativeContext.isSimulator,
|
|
38
|
-
is_emulator: nativeContext.isEmulator,
|
|
39
|
-
is_rooted: nativeContext.isRooted,
|
|
40
|
-
is_jailbroken: nativeContext.isJailbroken,
|
|
41
|
-
// System metrics
|
|
42
|
-
total_memory_mb: nativeContext.totalMemoryMB,
|
|
43
|
-
free_memory_mb: nativeContext.freeMemoryMB,
|
|
44
|
-
max_memory_mb: nativeContext.maxMemoryMB,
|
|
45
|
-
used_memory_mb: nativeContext.usedMemoryMB,
|
|
46
|
-
available_memory_mb: nativeContext.availableMemoryMB,
|
|
47
|
-
free_storage_mb: nativeContext.freeStorageMB,
|
|
48
|
-
total_storage_mb: nativeContext.totalStorageMB,
|
|
49
|
-
used_storage_mb: nativeContext.usedStorageMB,
|
|
50
|
-
battery_level: nativeContext.batteryLevel,
|
|
51
|
-
battery_state: nativeContext.batteryState,
|
|
52
|
-
system_uptime: nativeContext.systemUptime,
|
|
53
|
-
low_power_mode: nativeContext.lowPowerMode,
|
|
54
|
-
// Network information
|
|
55
|
-
network_type: nativeContext.networkType,
|
|
56
|
-
carrier_name: nativeContext.carrierName,
|
|
57
|
-
radio_technology: nativeContext.radioTechnology,
|
|
58
|
-
// Locale information
|
|
59
|
-
locale: nativeContext.locale,
|
|
60
|
-
language: nativeContext.language,
|
|
61
|
-
country: nativeContext.country,
|
|
62
|
-
timezone: nativeContext.timezone,
|
|
63
|
-
// Privacy information
|
|
64
|
-
advertising_id: nativeContext.advertisingId,
|
|
65
|
-
ad_tracking_enabled: nativeContext.adTrackingEnabled,
|
|
66
|
-
tracking_status: nativeContext.trackingStatus,
|
|
67
|
-
// Additional information
|
|
68
|
-
user_agent: nativeContext.userAgent,
|
|
69
|
-
first_install_time: nativeContext.firstInstallTime,
|
|
70
|
-
last_update_time: nativeContext.lastUpdateTime,
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
12
|
class EdgeeClient {
|
|
75
13
|
constructor(config) {
|
|
76
14
|
// current app state
|
|
@@ -79,14 +17,19 @@ class EdgeeClient {
|
|
|
79
17
|
this.handleAppStateChange = (nextAppState) => {
|
|
80
18
|
if (["inactive", "background"].includes(this.appState) &&
|
|
81
19
|
nextAppState === "active") {
|
|
82
|
-
this.track(
|
|
83
|
-
|
|
20
|
+
this.track({
|
|
21
|
+
name: "application_opened",
|
|
22
|
+
properties: {
|
|
23
|
+
from_background: true,
|
|
24
|
+
},
|
|
84
25
|
});
|
|
85
26
|
}
|
|
86
27
|
else if ((this.appState === "active" || this.appState === "unknown") && // Check if appState is 'active' or 'unknown'
|
|
87
28
|
["inactive", "background"].includes(nextAppState)) {
|
|
88
29
|
// Check if next app state is 'inactive' or 'background'
|
|
89
|
-
this.track(
|
|
30
|
+
this.track({
|
|
31
|
+
name: "application_backgrounded",
|
|
32
|
+
});
|
|
90
33
|
}
|
|
91
34
|
this.appState = nextAppState;
|
|
92
35
|
};
|
|
@@ -108,64 +51,37 @@ class EdgeeClient {
|
|
|
108
51
|
/**
|
|
109
52
|
* Track a screen view event
|
|
110
53
|
*/
|
|
111
|
-
async screen(
|
|
54
|
+
async screen(data, components) {
|
|
55
|
+
// if screen_name or title is not in data, throw an error
|
|
56
|
+
if (!("screen_name" in data)) {
|
|
57
|
+
throw new Error("screen_name or title is required to track a screen event");
|
|
58
|
+
}
|
|
112
59
|
const context = await (0, context_1.getContext)(this.config);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
const nativeContext = await (0, native_context_1.getNativeContext)({
|
|
118
|
-
collectDeviceId: this.config.collectDeviceId,
|
|
119
|
-
});
|
|
120
|
-
nativeProperties = extractNativeProperties(nativeContext);
|
|
121
|
-
}
|
|
122
|
-
catch (error) {
|
|
123
|
-
(0, utils_1.logError)("Error collecting page event", error);
|
|
124
|
-
}
|
|
60
|
+
const { screen_name, screen_class, ...restData } = data;
|
|
61
|
+
context.page.title = screen_name;
|
|
62
|
+
if (screen_class) {
|
|
63
|
+
context.page.url = screen_class;
|
|
125
64
|
}
|
|
126
|
-
|
|
127
|
-
const enhancedData = {
|
|
128
|
-
...data,
|
|
129
|
-
screen_name: screenName,
|
|
130
|
-
...nativeProperties,
|
|
131
|
-
};
|
|
132
|
-
const event = (0, api_1.createTrackEvent)({
|
|
133
|
-
name: "screen",
|
|
134
|
-
data: enhancedData,
|
|
135
|
-
components,
|
|
136
|
-
context,
|
|
137
|
-
});
|
|
65
|
+
const event = (0, api_1.createScreenEvent)(restData, components, context);
|
|
138
66
|
this.queue.enqueue(event);
|
|
139
67
|
}
|
|
140
68
|
/**
|
|
141
69
|
* Track a custom event
|
|
142
70
|
*/
|
|
143
|
-
async track(
|
|
71
|
+
async track(data, components) {
|
|
72
|
+
// if name is not in data, throw an error
|
|
73
|
+
if (!("name" in data)) {
|
|
74
|
+
throw new Error("Name is required to track an event");
|
|
75
|
+
}
|
|
144
76
|
const context = await (0, context_1.getContext)(this.config);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
try {
|
|
149
|
-
const nativeContext = await (0, native_context_1.getNativeContext)({
|
|
150
|
-
collectDeviceId: this.config.collectDeviceId,
|
|
151
|
-
});
|
|
152
|
-
nativeProperties = extractNativeProperties(nativeContext);
|
|
153
|
-
}
|
|
154
|
-
catch (error) {
|
|
155
|
-
(0, utils_1.logError)("Error collecting track event", error);
|
|
156
|
-
}
|
|
77
|
+
const { screen_name, screen_class, ...restData } = data;
|
|
78
|
+
if (screen_name) {
|
|
79
|
+
context.page.title = screen_name;
|
|
157
80
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
};
|
|
163
|
-
const event = (0, api_1.createTrackEvent)({
|
|
164
|
-
name,
|
|
165
|
-
data: enhancedData,
|
|
166
|
-
components,
|
|
167
|
-
context,
|
|
168
|
-
});
|
|
81
|
+
if (screen_class) {
|
|
82
|
+
context.page.url = screen_class;
|
|
83
|
+
}
|
|
84
|
+
const event = (0, api_1.createTrackEvent)(restData, components, context);
|
|
169
85
|
this.queue.enqueue(event);
|
|
170
86
|
}
|
|
171
87
|
/**
|
|
@@ -173,29 +89,7 @@ class EdgeeClient {
|
|
|
173
89
|
*/
|
|
174
90
|
async user(data, components) {
|
|
175
91
|
const context = await (0, context_1.getContext)(this.config);
|
|
176
|
-
|
|
177
|
-
let nativeProperties = {};
|
|
178
|
-
if (this.config.collectDeviceId && (0, native_context_1.isNativeModuleAvailable)()) {
|
|
179
|
-
try {
|
|
180
|
-
const nativeContext = await (0, native_context_1.getNativeContext)({
|
|
181
|
-
collectDeviceId: this.config.collectDeviceId,
|
|
182
|
-
});
|
|
183
|
-
nativeProperties = extractNativeProperties(nativeContext);
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
(0, utils_1.logError)("Error collecting user event", error);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
// Merge native properties with user data
|
|
190
|
-
const enhancedData = {
|
|
191
|
-
...data,
|
|
192
|
-
...nativeProperties,
|
|
193
|
-
};
|
|
194
|
-
const event = (0, api_1.createUserEvent)({
|
|
195
|
-
data: enhancedData,
|
|
196
|
-
components,
|
|
197
|
-
context,
|
|
198
|
-
});
|
|
92
|
+
const event = (0, api_1.createUserEvent)(data, components, context);
|
|
199
93
|
this.queue.enqueue(event);
|
|
200
94
|
}
|
|
201
95
|
/**
|
|
@@ -237,6 +131,10 @@ class EdgeeClient {
|
|
|
237
131
|
async resetConsent() {
|
|
238
132
|
await consent_1.edgeeConsent.reset();
|
|
239
133
|
}
|
|
134
|
+
async reset() {
|
|
135
|
+
await edgee_store_1.edgeeStore.reset();
|
|
136
|
+
await this.resetConsent();
|
|
137
|
+
}
|
|
240
138
|
onConsentChange(callback) {
|
|
241
139
|
return consent_1.edgeeConsent.onChange(callback);
|
|
242
140
|
}
|
|
@@ -245,7 +143,7 @@ exports.EdgeeClient = EdgeeClient;
|
|
|
245
143
|
var react_1 = require("./react");
|
|
246
144
|
Object.defineProperty(exports, "EdgeeProvider", { enumerable: true, get: function () { return react_1.EdgeeProvider; } });
|
|
247
145
|
Object.defineProperty(exports, "useEdgee", { enumerable: true, get: function () { return react_1.useEdgee; } });
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
Object.defineProperty(exports, "
|
|
251
|
-
Object.defineProperty(exports, "isNativeModuleAvailable", { enumerable: true, get: function () { return
|
|
146
|
+
// Export types and native context functions
|
|
147
|
+
var native_context_1 = require("./native-context");
|
|
148
|
+
Object.defineProperty(exports, "clearContextCache", { enumerable: true, get: function () { return native_context_1.clearContextCache; } });
|
|
149
|
+
Object.defineProperty(exports, "isNativeModuleAvailable", { enumerable: true, get: function () { return native_context_1.isNativeModuleAvailable; } });
|
package/dist/native-context.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { EdgeeNativeContext
|
|
1
|
+
import type { EdgeeNativeContext } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Get comprehensive device and app context from native modules
|
|
4
4
|
*/
|
|
5
|
-
export declare function getNativeContext(
|
|
5
|
+
export declare function getNativeContext(collectDeviceId: boolean): Promise<EdgeeNativeContext>;
|
|
6
6
|
/**
|
|
7
7
|
* Clear cached context (useful for testing or when context might change)
|
|
8
8
|
*/
|
package/dist/native-context.js
CHANGED
|
@@ -21,22 +21,36 @@ let contextPromise = null;
|
|
|
21
21
|
/**
|
|
22
22
|
* Get comprehensive device and app context from native modules
|
|
23
23
|
*/
|
|
24
|
-
async function getNativeContext(
|
|
24
|
+
async function getNativeContext(collectDeviceId) {
|
|
25
25
|
// Return cached context if available and no device ID collection requested
|
|
26
|
-
if (cachedContext
|
|
26
|
+
if (cachedContext) {
|
|
27
|
+
// if collectDeviceId is false, return the cached context without device ID
|
|
28
|
+
if (!collectDeviceId) {
|
|
29
|
+
return {
|
|
30
|
+
...cachedContext,
|
|
31
|
+
deviceId: undefined,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
27
34
|
return cachedContext;
|
|
28
35
|
}
|
|
29
36
|
// Return ongoing promise if one exists
|
|
30
37
|
if (contextPromise) {
|
|
31
38
|
return contextPromise;
|
|
32
39
|
}
|
|
40
|
+
const config = {
|
|
41
|
+
collectDeviceId: collectDeviceId,
|
|
42
|
+
};
|
|
33
43
|
contextPromise = EdgeeReactNative.getContextInfo(config)
|
|
34
44
|
.then((context) => {
|
|
35
|
-
|
|
36
|
-
if (!config.collectDeviceId) {
|
|
37
|
-
cachedContext = context;
|
|
38
|
-
}
|
|
45
|
+
cachedContext = context;
|
|
39
46
|
contextPromise = null;
|
|
47
|
+
// if collectDeviceId is false, return the context without device ID
|
|
48
|
+
if (!collectDeviceId) {
|
|
49
|
+
return {
|
|
50
|
+
...context,
|
|
51
|
+
deviceId: undefined,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
40
54
|
return context;
|
|
41
55
|
})
|
|
42
56
|
.catch((error) => {
|