react-native-edgee 1.0.6 → 1.0.7

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
@@ -126,7 +126,7 @@ import { EdgeeClient } from 'react-native-edgee';
126
126
  // Create client instance
127
127
  export const edgee = new EdgeeClient({
128
128
  host: "https://your-edgee-host.com",
129
- debug: __DEV__, // Enable debug logging in development
129
+ debug: false, // Set to true if you want to enable debugging
130
130
  collectDeviceId: false, // Set to true if you need unique device tracking
131
131
  });
132
132
  ```
@@ -134,24 +134,32 @@ export const edgee = new EdgeeClient({
134
134
  ### Track Events
135
135
 
136
136
  ```typescript
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'
137
+ // Track screen views
138
+ edgee.screen({
139
+ screen_name: 'Home Screen',
140
+ screen_class: '/',
141
+ properties: {
142
+ category: 'main',
143
+ loaded_time: Date.now()
144
+ }
142
145
  });
143
146
 
144
- // Track user information
145
- edgee.user({
146
- id: '123',
147
- email: 'user@example.com',
148
- plan: 'premium'
147
+ // Track events
148
+ edgee.track({
149
+ name: 'App Launched', // event name
150
+ properties: {
151
+ source: 'cold_start',
152
+ version: '1.0.0'
153
+ }
149
154
  });
150
155
 
151
- // Track screen views
152
- edgee.screen('Home Screen', {
153
- category: 'main',
154
- loaded_time: Date.now()
156
+ // Track user information
157
+ edgee.user({
158
+ user_id: '123',
159
+ properties: {
160
+ email: 'user@example.com',
161
+ plan: 'premium'
162
+ }
155
163
  });
156
164
  ```
157
165
 
@@ -159,11 +167,10 @@ edgee.screen('Home Screen', {
159
167
 
160
168
  ```typescript
161
169
  // Set consent - all tracking calls automatically respect this setting
162
- await edgee.setConsent('granted'); // 'granted', 'denied', or 'pending'
170
+ await edgee.consent('granted'); // 'granted', 'denied', or 'pending'
163
171
 
164
172
  // Check consent status
165
173
  console.log('Current consent:', edgee.getConsent());
166
- console.log('Can track:', edgee.canTrack());
167
174
 
168
175
  // Listen for consent changes
169
176
  const unsubscribe = edgee.onConsentChange((status) => {
@@ -200,98 +207,6 @@ With native modules enabled, each event automatically includes comprehensive con
200
207
  - Memory usage, storage info
201
208
  - Battery level and state (iOS)
202
209
 
203
- ### Network Information
204
- - Connection type (WiFi, cellular, ethernet)
205
- - Carrier name and network codes
206
- - Radio technology (3G, 4G, 5G)
207
-
208
- ### Privacy Information *(Optional)*
209
- - Advertising ID (with proper consent on iOS 14+)
210
- - Device ID (privacy-compliant, opt-in only)
211
- - Tracking authorization status
212
-
213
- ## ⚛️ React Integration
214
-
215
- ### Context Provider (Optional)
216
-
217
- ```typescript
218
- import { EdgeeProvider, useEdgee } from 'react-native-edgee';
219
-
220
- // Wrap your app
221
- export default function App() {
222
- return (
223
- <EdgeeProvider host="https://your-edgee-host.com" debug={__DEV__}>
224
- <YourApp />
225
- </EdgeeProvider>
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
- }
249
- ```
250
-
251
- ### Auto Screen Tracking
252
-
253
- <details>
254
- <summary><strong>Expo Router</strong></summary>
255
-
256
- ```typescript
257
- import { EdgeeAutoTracker } from 'react-native-edgee/expo-router';
258
-
259
- export default function RootLayout() {
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
- ```
271
-
272
- </details>
273
-
274
- <details>
275
- <summary><strong>React Navigation</strong></summary>
276
-
277
- ```typescript
278
- import { navigation } from 'react-native-edgee';
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
- );
292
- ```
293
-
294
- </details>
295
210
 
296
211
  ## ⚙️ Configuration
297
212
 
@@ -300,40 +215,10 @@ interface EdgeeConfig {
300
215
  host: string; // Your Edgee endpoint URL (required)
301
216
  debug?: boolean; // Enable debug logging (default: false)
302
217
  collectDeviceId?: boolean; // Collect unique device ID (default: false)
218
+ 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
219
  }
304
220
  ```
305
221
 
306
- ### Privacy Considerations
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
222
 
338
223
  ## 🧪 Testing with EdgeeTestApp
339
224
 
@@ -365,18 +250,7 @@ The repository includes a test app (`EdgeeTestApp/`) that allows you to quickly
365
250
  yarn start
366
251
  ```
367
252
 
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
- ```
253
+ Then type i to launch an iOS app, or a for Android
380
254
 
381
255
  ### Using the Test App
382
256
 
@@ -396,75 +270,6 @@ The test app provides a simple UI to test all SDK features:
396
270
 
397
271
  4. **Monitor Status**: The status bar at the bottom shows the result of each action
398
272
 
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
273
 
469
274
  ### Debug Mode
470
275
 
@@ -506,4 +311,4 @@ MIT
506
311
  ## 🆘 Support
507
312
 
508
313
  - **Issues**: [GitHub Issues](https://github.com/edgee-cloud/react-native-edgee/issues)
509
- - **Documentation**: [Edgee Docs](https://docs.edgee.cloud)
314
+ - **Documentation**: [Edgee Docs](https://www.edgee.cloud/docs)
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
- components: Record<string, boolean> | undefined;
12
- data: object;
13
- context: EdgeeFullContext;
10
+ screen_name?: string;
11
+ screen_class?: string;
12
+ properties?: object;
14
13
  };
15
14
  export type EdgeeUserEvent = {
16
- type: EventType.User;
17
- data: object;
18
- components: Record<string, boolean> | undefined;
19
- context: EdgeeFullContext;
15
+ user_id?: string;
16
+ anonymous_id?: string;
17
+ properties?: object;
20
18
  };
21
19
  export type EdgeeScreenEvent = {
22
- type: EventType.Screen;
23
- name: string;
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 type EdgeeEvent = EdgeeTrackEvent | EdgeeUserEvent | EdgeeScreenEvent;
29
- export declare const createTrackEvent: (params: Omit<EdgeeTrackEvent, "type">) => EdgeeTrackEvent;
30
- export declare const createUserEvent: (params: Omit<EdgeeUserEvent, "type">) => EdgeeUserEvent;
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 createTrackEvent = (params) => {
12
+ const createScreenEvent = (data, components, context) => {
13
13
  return {
14
14
  type: EventType.Track,
15
- ...params,
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 = (params) => {
33
+ const createUserEvent = (data, components, context) => {
20
34
  return {
21
35
  type: EventType.User,
22
- ...params,
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
- if (event.type === EventType.Track) {
37
- basePayload.data_collection.events.push({
38
- type: "track",
39
- data: {
40
- name: event.name,
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;
@@ -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 | undefined;
34
+ url: string;
35
+ search: string;
36
+ referrer: string;
34
37
  }
35
38
  export interface EdgeeFullContext {
36
39
  client: EdgeeClientContext;
@@ -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: "Home",
32
- path: "/",
33
- url,
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(): Promise<string | null>;
10
- getUserId(): Promise<string | null>;
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
@@ -38,10 +38,10 @@ class EdgeeStore {
38
38
  this.initialized = true;
39
39
  }
40
40
  }
41
- async getEdgeeId() {
41
+ getEdgeeId() {
42
42
  return this.edgeeId;
43
43
  }
44
- async getUserId() {
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(screenName: string, data: object, components?: Components): Promise<void>;
20
+ screen(data: EdgeeScreenEvent, components?: Components): Promise<void>;
20
21
  /**
21
22
  * Track a custom event
22
23
  */
23
- track(name: string, data: object, components?: Components): Promise<void>;
24
+ track(data: EdgeeTrackEvent, components?: Components): Promise<void>;
24
25
  /**
25
26
  * Track a user event
26
27
  */
27
- user(data: object, components?: Components): Promise<void>;
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 type { EdgeeClientContext, EdgeeFullContext, EdgeePageContext, } from "./core/context";
40
- export { clearContextCache, getNativeContext, isNativeModuleAvailable, } from "./native-context";
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.getNativeContext = exports.clearContextCache = exports.useEdgee = exports.EdgeeProvider = exports.EdgeeClient = void 0;
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("application_opened", {
83
- from_background: true,
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("application_backgrounded", {});
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(screenName, data, components) {
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
- // Get native context properties if available and collectDeviceId is enabled
114
- let nativeProperties = {};
115
- if (this.config.collectDeviceId && (0, native_context_1.isNativeModuleAvailable)()) {
116
- try {
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
- // Merge native properties with screen data
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(name, data, components) {
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
- // Get native context properties if available and collectDeviceId is enabled
146
- let nativeProperties = {};
147
- if (this.config.collectDeviceId && (0, native_context_1.isNativeModuleAvailable)()) {
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
- // Merge native properties with event data
159
- const enhancedData = {
160
- ...data,
161
- ...nativeProperties,
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
- // Get native context properties if available and collectDeviceId is enabled
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
- var native_context_2 = require("./native-context");
249
- Object.defineProperty(exports, "clearContextCache", { enumerable: true, get: function () { return native_context_2.clearContextCache; } });
250
- Object.defineProperty(exports, "getNativeContext", { enumerable: true, get: function () { return native_context_2.getNativeContext; } });
251
- Object.defineProperty(exports, "isNativeModuleAvailable", { enumerable: true, get: function () { return native_context_2.isNativeModuleAvailable; } });
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; } });
@@ -1,8 +1,8 @@
1
- import type { EdgeeNativeContext, EdgeeNativeContextConfig } from "./types";
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(config?: EdgeeNativeContextConfig): Promise<EdgeeNativeContext>;
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
  */
@@ -21,22 +21,33 @@ let contextPromise = null;
21
21
  /**
22
22
  * Get comprehensive device and app context from native modules
23
23
  */
24
- async function getNativeContext(config = {}) {
24
+ async function getNativeContext(collectDeviceId) {
25
25
  // Return cached context if available and no device ID collection requested
26
- if (cachedContext && !config.collectDeviceId) {
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
  }
33
- contextPromise = EdgeeReactNative.getContextInfo(config)
40
+ contextPromise = EdgeeReactNative.getContextInfo(collectDeviceId)
34
41
  .then((context) => {
35
- // Cache context if no sensitive data (device ID) was requested
36
- if (!config.collectDeviceId) {
37
- cachedContext = context;
38
- }
42
+ cachedContext = context;
39
43
  contextPromise = null;
44
+ // if collectDeviceId is false, return the context without device ID
45
+ if (!collectDeviceId) {
46
+ return {
47
+ ...context,
48
+ deviceId: undefined,
49
+ };
50
+ }
40
51
  return context;
41
52
  })
42
53
  .catch((error) => {
package/dist/types.d.ts CHANGED
@@ -1,7 +1,4 @@
1
1
  import { NativeModule } from "react-native";
2
- export interface EdgeeNativeContextConfig {
3
- collectDeviceId?: boolean;
4
- }
5
2
  export interface EdgeeNativeContext {
6
3
  appName: string;
7
4
  appVersion: string;
@@ -60,5 +57,5 @@ export interface EdgeeNativeContext {
60
57
  lastUpdateTime?: number;
61
58
  }
62
59
  export interface EdgeeReactNativeModule extends NativeModule {
63
- getContextInfo(config: EdgeeNativeContextConfig): Promise<EdgeeNativeContext>;
60
+ getContextInfo(collectDeviceId: boolean): Promise<EdgeeNativeContext>;
64
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-edgee",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Lightweight Edgee data collection client for React Native with native context collection.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",