respectlytics-react-native 1.0.1 → 2.0.0

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.
Files changed (50) hide show
  1. package/README.md +43 -34
  2. package/lib/commonjs/EventQueue.js +174 -0
  3. package/lib/commonjs/EventQueue.js.map +1 -0
  4. package/lib/commonjs/NetworkClient.js +158 -0
  5. package/lib/commonjs/NetworkClient.js.map +1 -0
  6. package/lib/commonjs/Respectlytics.js +167 -0
  7. package/lib/commonjs/Respectlytics.js.map +1 -0
  8. package/lib/commonjs/SessionManager.js +75 -0
  9. package/lib/commonjs/SessionManager.js.map +1 -0
  10. package/lib/commonjs/Storage.js +57 -0
  11. package/lib/commonjs/Storage.js.map +1 -0
  12. package/lib/commonjs/index.js +37 -0
  13. package/lib/commonjs/index.js.map +1 -0
  14. package/lib/commonjs/types.js +35 -0
  15. package/lib/commonjs/types.js.map +1 -0
  16. package/lib/module/EventQueue.js +166 -0
  17. package/lib/module/EventQueue.js.map +1 -0
  18. package/lib/module/NetworkClient.js +151 -0
  19. package/lib/module/NetworkClient.js.map +1 -0
  20. package/lib/module/Respectlytics.js +162 -0
  21. package/lib/module/Respectlytics.js.map +1 -0
  22. package/lib/module/SessionManager.js +68 -0
  23. package/lib/module/SessionManager.js.map +1 -0
  24. package/lib/module/Storage.js +50 -0
  25. package/lib/module/Storage.js.map +1 -0
  26. package/lib/module/index.js +23 -0
  27. package/lib/module/index.js.map +1 -0
  28. package/lib/module/types.js +29 -0
  29. package/lib/module/types.js.map +1 -0
  30. package/lib/typescript/EventQueue.d.ts +47 -0
  31. package/lib/typescript/EventQueue.d.ts.map +1 -0
  32. package/lib/typescript/NetworkClient.d.ts +48 -0
  33. package/lib/typescript/NetworkClient.d.ts.map +1 -0
  34. package/lib/typescript/Respectlytics.d.ts +61 -0
  35. package/lib/typescript/Respectlytics.d.ts.map +1 -0
  36. package/lib/typescript/SessionManager.d.ts +39 -0
  37. package/lib/typescript/SessionManager.d.ts.map +1 -0
  38. package/lib/typescript/Storage.d.ts +26 -0
  39. package/lib/typescript/Storage.d.ts.map +1 -0
  40. package/lib/typescript/index.d.ts +18 -0
  41. package/lib/typescript/index.d.ts.map +1 -0
  42. package/lib/typescript/types.d.ts +38 -0
  43. package/lib/typescript/types.d.ts.map +1 -0
  44. package/package.json +2 -2
  45. package/src/NetworkClient.ts +1 -1
  46. package/src/Respectlytics.ts +7 -29
  47. package/src/SessionManager.ts +24 -20
  48. package/src/index.ts +8 -1
  49. package/src/types.ts +5 -2
  50. package/src/UserManager.ts +0 -74
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "respectlytics-react-native",
3
- "version": "1.0.1",
3
+ "version": "2.0.0",
4
4
  "description": "Official Respectlytics SDK for React Native. Privacy-first analytics with automatic session management, offline event queuing, and zero device identifier collection.",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
7
- "types": "lib/typescript/src/index.d.ts",
7
+ "types": "lib/typescript/index.d.ts",
8
8
  "react-native": "src/index.ts",
9
9
  "source": "src/index.ts",
10
10
  "files": [
@@ -138,13 +138,13 @@ export class NetworkClient {
138
138
 
139
139
  /**
140
140
  * Convert Event object to API payload format
141
+ * Note: As of v2.0.0, no user_id field is sent (session-based analytics only)
141
142
  */
142
143
  private eventToPayload(event: Event): Record<string, unknown> {
143
144
  return {
144
145
  event_name: event.eventName,
145
146
  timestamp: event.timestamp,
146
147
  session_id: event.sessionId,
147
- user_id: event.userId || undefined,
148
148
  screen: event.screen || undefined,
149
149
  platform: event.platform,
150
150
  os_version: event.osVersion,
@@ -9,22 +9,24 @@
9
9
  import { Platform, Dimensions, NativeModules } from 'react-native';
10
10
  import { Event } from './types';
11
11
  import { SessionManager } from './SessionManager';
12
- import { UserManager } from './UserManager';
13
12
  import { NetworkClient } from './NetworkClient';
14
13
  import { EventQueue } from './EventQueue';
15
14
 
16
15
  /**
17
16
  * Main entry point for the Respectlytics SDK.
18
17
  *
18
+ * v2.0.0 uses session-based analytics only:
19
+ * - Session IDs are generated automatically in RAM
20
+ * - Sessions rotate every 2 hours
21
+ * - New session on every app restart
22
+ * - No persistent user tracking (GDPR/ePrivacy compliant)
23
+ *
19
24
  * Usage:
20
25
  * ```typescript
21
26
  * // 1. Configure at app launch
22
27
  * Respectlytics.configure('your-api-key');
23
28
  *
24
- * // 2. Enable user tracking (optional)
25
- * Respectlytics.identify();
26
- *
27
- * // 3. Track events
29
+ * // 2. Track events
28
30
  * Respectlytics.track('purchase');
29
31
  * Respectlytics.track('view_product', 'ProductScreen');
30
32
  * ```
@@ -34,13 +36,11 @@ class RespectlyticsSDK {
34
36
  private networkClient: NetworkClient;
35
37
  private eventQueue: EventQueue;
36
38
  private sessionManager: SessionManager;
37
- private userManager: UserManager;
38
39
 
39
40
  constructor() {
40
41
  this.networkClient = new NetworkClient();
41
42
  this.eventQueue = new EventQueue(this.networkClient);
42
43
  this.sessionManager = new SessionManager();
43
- this.userManager = new UserManager();
44
44
  }
45
45
 
46
46
  /**
@@ -57,7 +57,6 @@ class RespectlyticsSDK {
57
57
 
58
58
  this.networkClient.configure(apiKey);
59
59
  this.eventQueue.start();
60
- this.userManager.loadUserId();
61
60
  this.isConfigured = true;
62
61
 
63
62
  console.log('[Respectlytics] ✓ SDK configured');
@@ -92,26 +91,6 @@ class RespectlyticsSDK {
92
91
  this.eventQueue.add(event);
93
92
  }
94
93
 
95
- /**
96
- * Enable cross-session user tracking.
97
- * Generates and persists a random user ID that will be included in all subsequent events.
98
- *
99
- * Note: User IDs are auto-generated and cannot be overridden. This is by design for privacy.
100
- */
101
- async identify(): Promise<void> {
102
- await this.userManager.identify();
103
- console.log('[Respectlytics] ✓ User identified');
104
- }
105
-
106
- /**
107
- * Clear the user ID.
108
- * Call when the user logs out. Subsequent events will be anonymous until identify() is called again.
109
- */
110
- async reset(): Promise<void> {
111
- await this.userManager.reset();
112
- console.log('[Respectlytics] ✓ User reset');
113
- }
114
-
115
94
  /**
116
95
  * Force send all queued events immediately.
117
96
  * Rarely needed - the SDK auto-flushes every 30 seconds or when the queue reaches 10 events.
@@ -129,7 +108,6 @@ class RespectlyticsSDK {
129
108
  eventName,
130
109
  timestamp: new Date().toISOString(),
131
110
  sessionId: this.sessionManager.getSessionId(),
132
- userId: this.userManager.getUserId(),
133
111
  screen: screen || null,
134
112
  ...metadata,
135
113
  };
@@ -3,7 +3,8 @@
3
3
  * Respectlytics React Native SDK
4
4
  *
5
5
  * Manages session ID generation and rotation.
6
- * Sessions automatically rotate after 30 minutes of inactivity.
6
+ * Sessions are stored in RAM only (never persisted) for GDPR/ePrivacy compliance.
7
+ * Sessions automatically rotate every 2 hours.
7
8
  *
8
9
  * Copyright (c) 2025 Respectlytics. All rights reserved.
9
10
  */
@@ -20,37 +21,40 @@ function generateUUID(): string {
20
21
  }
21
22
 
22
23
  /**
23
- * Manages session ID generation and rotation
24
+ * Manages session ID generation and rotation.
25
+ *
26
+ * Session IDs are:
27
+ * - Generated immediately when the SDK initializes
28
+ * - Stored in RAM only (never persisted to AsyncStorage)
29
+ * - Rotated automatically every 2 hours
30
+ * - Regenerated on every app restart (new instance = new session)
31
+ *
32
+ * This RAM-only approach ensures GDPR/ePrivacy compliance:
33
+ * - No device storage = No consent required under ePrivacy Directive Article 5(3)
34
+ * - Each app launch creates a fresh, unlinked session
24
35
  */
25
36
  export class SessionManager {
26
- private sessionId: string | null = null;
27
- private lastEventTime: number | null = null;
37
+ // Session ID generated immediately at class instantiation
38
+ private sessionId: string = this.generateSessionId();
39
+ private sessionStart: Date = new Date();
28
40
 
29
- // 30 minutes in milliseconds
30
- private readonly SESSION_TIMEOUT_MS = 30 * 60 * 1000;
41
+ // 2 hours in milliseconds
42
+ private readonly SESSION_TIMEOUT_MS = 2 * 60 * 60 * 1000;
31
43
 
32
44
  /**
33
45
  * Get current session ID, rotating if necessary.
34
- * Session rotates after 30 minutes of inactivity.
46
+ * Session rotates after 2 hours of continuous use.
35
47
  */
36
48
  getSessionId(): string {
37
- const now = Date.now();
38
-
39
- // Check if session expired
40
- if (
41
- this.lastEventTime !== null &&
42
- now - this.lastEventTime > this.SESSION_TIMEOUT_MS
43
- ) {
44
- // Force new session
45
- this.sessionId = null;
46
- }
49
+ const now = new Date();
50
+ const elapsed = now.getTime() - this.sessionStart.getTime();
47
51
 
48
- // Generate new session if needed
49
- if (this.sessionId === null) {
52
+ // Rotate session after 2 hours
53
+ if (elapsed > this.SESSION_TIMEOUT_MS) {
50
54
  this.sessionId = this.generateSessionId();
55
+ this.sessionStart = now;
51
56
  }
52
57
 
53
- this.lastEventTime = now;
54
58
  return this.sessionId;
55
59
  }
56
60
 
package/src/index.ts CHANGED
@@ -1,7 +1,14 @@
1
1
  /**
2
2
  * Respectlytics React Native SDK
3
3
  *
4
- * Official SDK for privacy-first analytics.
4
+ * Official SDK for privacy-first, session-based analytics.
5
+ *
6
+ * v2.0.0 Features:
7
+ * - Session-based analytics (no persistent user tracking)
8
+ * - RAM-only session storage (GDPR/ePrivacy compliant)
9
+ * - Automatic 2-hour session rotation
10
+ * - New session on every app restart
11
+ *
5
12
  * Copyright (c) 2025 Respectlytics. All rights reserved.
6
13
  */
7
14
 
package/src/types.ts CHANGED
@@ -13,12 +13,13 @@
13
13
  * This interface only contains fields accepted by the Respectlytics API.
14
14
  * The API uses a strict allowlist for privacy protection.
15
15
  * Custom properties are NOT supported - this is by design for privacy.
16
+ *
17
+ * Note: As of v2.0.0, there is no userId field. Session-based analytics only.
16
18
  */
17
19
  export interface Event {
18
20
  eventName: string;
19
21
  timestamp: string;
20
22
  sessionId: string;
21
- userId: string | null;
22
23
  screen: string | null;
23
24
  platform: string;
24
25
  osVersion: string;
@@ -29,8 +30,10 @@ export interface Event {
29
30
 
30
31
  /**
31
32
  * Storage keys used by the SDK
33
+ *
34
+ * Note: As of v2.0.0, we only persist the event queue.
35
+ * Session IDs are RAM-only for GDPR/ePrivacy compliance.
32
36
  */
33
37
  export const STORAGE_KEYS = {
34
- USER_ID: 'com.respectlytics.userId',
35
38
  EVENT_QUEUE: 'com.respectlytics.eventQueue',
36
39
  } as const;
@@ -1,74 +0,0 @@
1
- /**
2
- * UserManager.ts
3
- * Respectlytics React Native SDK
4
- *
5
- * Manages user ID generation, persistence, and reset.
6
- * User IDs are auto-generated and cannot be overridden.
7
- * This is by design for maximum privacy.
8
- *
9
- * Copyright (c) 2025 Respectlytics. All rights reserved.
10
- */
11
-
12
- import { Storage } from './Storage';
13
- import { STORAGE_KEYS } from './types';
14
-
15
- /**
16
- * Manages user ID generation, persistence, and reset
17
- */
18
- export class UserManager {
19
- private _userId: string | null = null;
20
-
21
- /**
22
- * Current user ID (null if not identified)
23
- */
24
- getUserId(): string | null {
25
- return this._userId;
26
- }
27
-
28
- /**
29
- * Load any persisted user ID from storage
30
- */
31
- async loadUserId(): Promise<void> {
32
- this._userId = await Storage.getItem(STORAGE_KEYS.USER_ID);
33
- }
34
-
35
- /**
36
- * Generate or retrieve user ID.
37
- * If already identified, returns existing ID.
38
- * If not, generates a new ID and persists it.
39
- */
40
- async identify(): Promise<void> {
41
- // Check storage first
42
- const stored = await Storage.getItem(STORAGE_KEYS.USER_ID);
43
- if (stored) {
44
- this._userId = stored;
45
- return;
46
- }
47
-
48
- // Generate new ID (32 lowercase hex chars)
49
- const newId = this.generateUserId();
50
- await Storage.setItem(STORAGE_KEYS.USER_ID, newId);
51
- this._userId = newId;
52
- }
53
-
54
- /**
55
- * Clear user ID. Call on logout.
56
- */
57
- async reset(): Promise<void> {
58
- await Storage.removeItem(STORAGE_KEYS.USER_ID);
59
- this._userId = null;
60
- }
61
-
62
- /**
63
- * Generate a new user ID (32 lowercase hex characters)
64
- * UUID without dashes, all lowercase
65
- */
66
- private generateUserId(): string {
67
- const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
68
- const r = (Math.random() * 16) | 0;
69
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
70
- return v.toString(16);
71
- });
72
- return uuid.toLowerCase().replace(/-/g, '');
73
- }
74
- }