respectlytics-react-native 2.1.0 → 2.2.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.
- package/LICENSE +17 -20
- package/README.md +34 -6
- package/lib/commonjs/EventQueue.js +1 -1
- package/lib/commonjs/NetworkClient.js +11 -7
- package/lib/commonjs/NetworkClient.js.map +1 -1
- package/lib/commonjs/Respectlytics.js +10 -6
- package/lib/commonjs/Respectlytics.js.map +1 -1
- package/lib/commonjs/SessionManager.js +4 -4
- package/lib/commonjs/Storage.js +1 -1
- package/lib/commonjs/index.js +3 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js +3 -4
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/EventQueue.js +1 -1
- package/lib/module/NetworkClient.js +11 -7
- package/lib/module/NetworkClient.js.map +1 -1
- package/lib/module/Respectlytics.js +10 -6
- package/lib/module/Respectlytics.js.map +1 -1
- package/lib/module/SessionManager.js +4 -4
- package/lib/module/Storage.js +1 -1
- package/lib/module/index.js +3 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js +3 -4
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/EventQueue.d.ts +1 -1
- package/lib/typescript/NetworkClient.d.ts +6 -5
- package/lib/typescript/NetworkClient.d.ts.map +1 -1
- package/lib/typescript/Respectlytics.d.ts +10 -4
- package/lib/typescript/Respectlytics.d.ts.map +1 -1
- package/lib/typescript/SessionManager.d.ts +4 -4
- package/lib/typescript/Storage.d.ts +1 -1
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +3 -4
- package/lib/typescript/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/EventQueue.ts +4 -4
- package/src/NetworkClient.ts +11 -7
- package/src/Respectlytics.ts +10 -6
- package/src/SessionManager.ts +6 -6
- package/src/Storage.ts +1 -1
- package/src/index.ts +5 -6
- package/src/types.ts +3 -4
package/LICENSE
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2025 Respectlytics. All rights reserved.
|
|
1
|
+
MIT License
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
- View and read the source code for transparency and security review
|
|
6
|
-
- Install the SDK via official package managers (SPM, npm, pub.dev)
|
|
7
|
-
- Use the SDK to send analytics data to the official Respectlytics service
|
|
3
|
+
Copyright (c) 2025 Respectlytics
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
shall not be liable for any damages arising from the use of this SDK.
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/respectlytics-react-native)
|
|
4
4
|
[](https://github.com/respectlytics/respectlytics-react-native)
|
|
5
|
-
[](LICENSE)
|
|
6
6
|
|
|
7
7
|
Official Respectlytics SDK for React Native. Privacy-first, session-based analytics with automatic session management, offline event queuing, and zero device identifier collection.
|
|
8
8
|
|
|
@@ -10,11 +10,12 @@ Official Respectlytics SDK for React Native. Privacy-first, session-based analyt
|
|
|
10
10
|
|
|
11
11
|
Respectlytics helps developers avoid collecting personal data in the first place. We believe the best way to handle sensitive data is to never collect it.
|
|
12
12
|
|
|
13
|
-
Our SDK collects only 4 fields:
|
|
13
|
+
Our SDK collects only 4 fields, and the API stores 5 total:
|
|
14
14
|
- `event_name` - What happened
|
|
15
|
-
- `timestamp` - When it happened
|
|
15
|
+
- `timestamp` - When it happened
|
|
16
16
|
- `session_id` - Groups events in a session (RAM-only, auto-rotates)
|
|
17
17
|
- `platform` - iOS or Android
|
|
18
|
+
- `country` - Derived server-side from IP (IP immediately discarded, never stored)
|
|
18
19
|
|
|
19
20
|
That's it. No device identifiers, no fingerprinting, no persistent tracking.
|
|
20
21
|
|
|
@@ -65,20 +66,36 @@ Respectlytics.configure('your-api-key');
|
|
|
65
66
|
// 2. Track events
|
|
66
67
|
Respectlytics.track('purchase');
|
|
67
68
|
Respectlytics.track('view_product');
|
|
69
|
+
|
|
70
|
+
// For self-hosted instances:
|
|
71
|
+
Respectlytics.configure('your-api-key', {
|
|
72
|
+
apiEndpoint: 'https://your-server.com/api/v1/events/',
|
|
73
|
+
});
|
|
68
74
|
```
|
|
69
75
|
|
|
70
76
|
That's it! Session management is fully automatic.
|
|
71
77
|
|
|
72
78
|
## API Reference
|
|
73
79
|
|
|
74
|
-
### `configure(apiKey: string)`
|
|
80
|
+
### `configure(apiKey: string, options?: { apiEndpoint?: string })`
|
|
75
81
|
|
|
76
82
|
Initialize the SDK with your API key. Call once at app startup.
|
|
77
83
|
|
|
78
84
|
```typescript
|
|
85
|
+
// Respectlytics Cloud (default)
|
|
79
86
|
Respectlytics.configure('your-api-key');
|
|
87
|
+
|
|
88
|
+
// Self-hosted instance
|
|
89
|
+
Respectlytics.configure('your-api-key', {
|
|
90
|
+
apiEndpoint: 'https://your-server.com/api/v1/events/',
|
|
91
|
+
});
|
|
80
92
|
```
|
|
81
93
|
|
|
94
|
+
| Parameter | Type | Required | Description |
|
|
95
|
+
|-----------|------|----------|-------------|
|
|
96
|
+
| `apiKey` | `string` | Yes | Your Respectlytics API key |
|
|
97
|
+
| `options.apiEndpoint` | `string` | No | Custom endpoint for self-hosted instances |
|
|
98
|
+
|
|
82
99
|
### `track(eventName: string)`
|
|
83
100
|
|
|
84
101
|
Track an event.
|
|
@@ -156,12 +173,23 @@ Events are automatically queued when offline and sent when connectivity returns:
|
|
|
156
173
|
3. Queue is flushed when connectivity is restored
|
|
157
174
|
4. Failed sends are retried with exponential backoff
|
|
158
175
|
|
|
176
|
+
## Migration from v2.1.x
|
|
177
|
+
|
|
178
|
+
### Changes in v2.2.0
|
|
179
|
+
|
|
180
|
+
- `configure()` now accepts an optional second argument `{ apiEndpoint }` for self-hosted instances
|
|
181
|
+
- License changed from proprietary to MIT
|
|
182
|
+
- The API stores 5 fields total (the 4 sent by the SDK plus `country` derived server-side)
|
|
183
|
+
|
|
184
|
+
### What to do
|
|
185
|
+
|
|
186
|
+
No breaking changes. Existing code works as-is.
|
|
187
|
+
|
|
159
188
|
## Migration from v2.0.x
|
|
160
189
|
|
|
161
190
|
### Changes in v2.1.0
|
|
162
191
|
|
|
163
192
|
- `track()` method now takes only `eventName` - the `screen` parameter has been removed
|
|
164
|
-
- The SDK now sends only 4 fields to the API (down from 10)
|
|
165
193
|
- Deprecated fields (`screen`, `os_version`, `app_version`, `locale`, `device_type`, `region`) are no longer collected
|
|
166
194
|
|
|
167
195
|
### What to do
|
|
@@ -182,7 +210,7 @@ Respectlytics provides a technical solution focused on privacy. Regulations vary
|
|
|
182
210
|
|
|
183
211
|
## License
|
|
184
212
|
|
|
185
|
-
This SDK is
|
|
213
|
+
This SDK is licensed under the [MIT License](LICENSE).
|
|
186
214
|
|
|
187
215
|
## Support
|
|
188
216
|
|
|
@@ -14,7 +14,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
14
14
|
*
|
|
15
15
|
* Manages event batching, persistence, and automatic flushing.
|
|
16
16
|
* Events are NEVER lost - they are persisted immediately and retried on failure.
|
|
17
|
-
* Copyright (c) 2025 Respectlytics.
|
|
17
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
const MAX_QUEUE_SIZE = 10;
|
|
@@ -9,10 +9,10 @@ exports.networkClient = exports.NetworkError = exports.NetworkClient = void 0;
|
|
|
9
9
|
* Respectlytics React Native SDK
|
|
10
10
|
*
|
|
11
11
|
* Handles HTTP communication with the Respectlytics API.
|
|
12
|
-
* Copyright (c) 2025 Respectlytics.
|
|
12
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const DEFAULT_API_ENDPOINT = 'https://respectlytics.com/api/v1/events/';
|
|
16
16
|
const MAX_RETRIES = 3;
|
|
17
17
|
const TIMEOUT_MS = 30000;
|
|
18
18
|
let NetworkError = exports.NetworkError = /*#__PURE__*/function (NetworkError) {
|
|
@@ -28,12 +28,16 @@ let NetworkError = exports.NetworkError = /*#__PURE__*/function (NetworkError) {
|
|
|
28
28
|
}({});
|
|
29
29
|
class NetworkClient {
|
|
30
30
|
apiKey = null;
|
|
31
|
+
apiEndpoint = DEFAULT_API_ENDPOINT;
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
|
-
* Configure the network client with an API key
|
|
34
|
+
* Configure the network client with an API key and optional custom endpoint
|
|
34
35
|
*/
|
|
35
|
-
configure(apiKey) {
|
|
36
|
+
configure(apiKey, apiEndpoint) {
|
|
36
37
|
this.apiKey = apiKey;
|
|
38
|
+
if (apiEndpoint) {
|
|
39
|
+
this.apiEndpoint = apiEndpoint;
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
/**
|
|
@@ -65,7 +69,7 @@ class NetworkClient {
|
|
|
65
69
|
const controller = new AbortController();
|
|
66
70
|
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
67
71
|
try {
|
|
68
|
-
const response = await fetch(
|
|
72
|
+
const response = await fetch(this.apiEndpoint, {
|
|
69
73
|
method: 'POST',
|
|
70
74
|
headers: {
|
|
71
75
|
'Content-Type': 'application/json',
|
|
@@ -129,8 +133,8 @@ class NetworkClient {
|
|
|
129
133
|
}
|
|
130
134
|
|
|
131
135
|
/**
|
|
132
|
-
* Convert Event object to API payload format
|
|
133
|
-
*
|
|
136
|
+
* Convert Event object to API payload format.
|
|
137
|
+
* The SDK sends 4 fields; the API stores 5 (adding country derived from IP).
|
|
134
138
|
*/
|
|
135
139
|
eventToPayload(event) {
|
|
136
140
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["DEFAULT_API_ENDPOINT","MAX_RETRIES","TIMEOUT_MS","NetworkError","exports","NetworkClient","apiKey","apiEndpoint","configure","isConfigured","send","events","Error","NotConfigured","event","sendEvent","attempt","controller","AbortController","timeoutId","setTimeout","abort","response","fetch","method","headers","body","JSON","stringify","eventToPayload","signal","clearTimeout","ok","status","Unauthorized","BadRequest","delay","Math","pow","RateLimited","ServerError","InvalidResponse","error","message","name","Timeout","event_name","eventName","timestamp","session_id","sessionId","platform","ms","Promise","resolve","networkClient"],"sourceRoot":"../../src","sources":["NetworkClient.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,MAAMA,oBAAoB,GAAG,0CAA0C;A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;AACF;AACA;EACUf,KAAKA,CAACgB,EAAU,EAAiB;IACvC,OAAO,IAAIC,OAAO,CAACC,OAAO,IAAIlC,UAAU,CAACkC,OAAO,EAAEF,EAAE,CAAC,CAAC;EACxD;AACF;AAAChD,OAAA,CAAAC,aAAA,GAAAA,aAAA;AAEM,MAAMkD,aAAa,GAAAnD,OAAA,CAAAmD,aAAA,GAAG,IAAIlD,aAAa,CAAC,CAAC","ignoreList":[]}
|
|
@@ -13,7 +13,7 @@ var _EventQueue = require("./EventQueue");
|
|
|
13
13
|
* Respectlytics React Native SDK
|
|
14
14
|
*
|
|
15
15
|
* Main entry point for the SDK.
|
|
16
|
-
* Copyright (c) 2025 Respectlytics.
|
|
16
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -23,13 +23,16 @@ var _EventQueue = require("./EventQueue");
|
|
|
23
23
|
* - Session IDs are generated automatically in RAM
|
|
24
24
|
* - Sessions rotate every 2 hours
|
|
25
25
|
* - New session on every app restart
|
|
26
|
-
* - Only 4 fields sent
|
|
26
|
+
* - Only 4 fields sent by SDK; 5 stored (country derived server-side)
|
|
27
27
|
*
|
|
28
28
|
* Usage:
|
|
29
29
|
* ```typescript
|
|
30
30
|
* // 1. Configure at app launch
|
|
31
31
|
* Respectlytics.configure('your-api-key');
|
|
32
32
|
*
|
|
33
|
+
* // For self-hosted instances:
|
|
34
|
+
* Respectlytics.configure('your-api-key', { apiEndpoint: 'https://your-server.com/api/v1/events/' });
|
|
35
|
+
*
|
|
33
36
|
* // 2. Track events
|
|
34
37
|
* Respectlytics.track('purchase');
|
|
35
38
|
* ```
|
|
@@ -48,23 +51,24 @@ class RespectlyticsSDK {
|
|
|
48
51
|
* Call once at app startup.
|
|
49
52
|
*
|
|
50
53
|
* @param apiKey Your Respectlytics API key from the dashboard
|
|
54
|
+
* @param options Optional configuration (e.g., apiEndpoint for self-hosted instances)
|
|
51
55
|
*/
|
|
52
|
-
configure(apiKey) {
|
|
56
|
+
configure(apiKey, options) {
|
|
53
57
|
if (!apiKey || apiKey.trim() === '') {
|
|
54
58
|
console.log('[Respectlytics] ⚠️ API key cannot be empty');
|
|
55
59
|
return;
|
|
56
60
|
}
|
|
57
|
-
this.networkClient.configure(apiKey);
|
|
61
|
+
this.networkClient.configure(apiKey, options?.apiEndpoint);
|
|
58
62
|
this.eventQueue.start();
|
|
59
63
|
this.isConfigured = true;
|
|
60
|
-
console.log('[Respectlytics] ✓ SDK configured (v2.
|
|
64
|
+
console.log('[Respectlytics] ✓ SDK configured (v2.2.0)');
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
/**
|
|
64
68
|
* Track an event.
|
|
65
69
|
*
|
|
66
70
|
* Custom properties are NOT supported - this is by design for privacy.
|
|
67
|
-
* The API
|
|
71
|
+
* The API stores 5 fields (these 4 plus country derived server-side).
|
|
68
72
|
*
|
|
69
73
|
* @param eventName Name of the event (e.g., "purchase", "button_clicked")
|
|
70
74
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_SessionManager","_NetworkClient","_EventQueue","RespectlyticsSDK","isConfigured","constructor","networkClient","NetworkClient","eventQueue","EventQueue","sessionManager","SessionManager","platform","Platform","OS","configure","apiKey","trim","console","log","start","track","eventName","length","event","timestamp","Date","toISOString","sessionId","getSessionId","add","flush","exports","Respectlytics","_default","default"],"sourceRoot":"../../src","sources":["Respectlytics.ts"],"mappings":";;;;;;AAQA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMI,gBAAgB,CAAC;EACbC,YAAY,GAAG,KAAK;EAM5BC,WAAWA,CAAA,EAAG;IACZ,IAAI,CAACC,aAAa,GAAG,IAAIC,4BAAa,CAAC,CAAC;IACxC,IAAI,CAACC,UAAU,GAAG,IAAIC,sBAAU,CAAC,IAAI,CAACH,aAAa,CAAC;IACpD,IAAI,CAACI,cAAc,GAAG,IAAIC,8BAAc,CAAC,CAAC;IAC1C,IAAI,CAACC,QAAQ,GAAGC,qBAAQ,CAACC,EAAE,KAAK,KAAK,GAAG,KAAK,GAAG,SAAS;EAC3D;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEC,SAASA,CAACC,MAAc,EAAQ;
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_SessionManager","_NetworkClient","_EventQueue","RespectlyticsSDK","isConfigured","constructor","networkClient","NetworkClient","eventQueue","EventQueue","sessionManager","SessionManager","platform","Platform","OS","configure","apiKey","options","trim","console","log","apiEndpoint","start","track","eventName","length","event","timestamp","Date","toISOString","sessionId","getSessionId","add","flush","exports","Respectlytics","_default","default"],"sourceRoot":"../../src","sources":["Respectlytics.ts"],"mappings":";;;;;;AAQA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMI,gBAAgB,CAAC;EACbC,YAAY,GAAG,KAAK;EAM5BC,WAAWA,CAAA,EAAG;IACZ,IAAI,CAACC,aAAa,GAAG,IAAIC,4BAAa,CAAC,CAAC;IACxC,IAAI,CAACC,UAAU,GAAG,IAAIC,sBAAU,CAAC,IAAI,CAACH,aAAa,CAAC;IACpD,IAAI,CAACI,cAAc,GAAG,IAAIC,8BAAc,CAAC,CAAC;IAC1C,IAAI,CAACC,QAAQ,GAAGC,qB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KAAKA,CAAA,EAAkB;IAC3B,MAAM,IAAI,CAACzB,UAAU,CAACyB,KAAK,CAAC,CAAC;EAC/B;AACF;;AAEA;AAAAC,OAAA,CAAA/B,gBAAA,GAAAA,gBAAA;AACA,MAAMgC,aAAa,GAAG,IAAIhC,gBAAgB,CAAC,CAAC;AAAC,IAAAiC,QAAA,GAAAF,OAAA,CAAAG,OAAA,GAC9BF,aAAa","ignoreList":[]}
|
|
@@ -9,10 +9,10 @@ exports.SessionManager = void 0;
|
|
|
9
9
|
* Respectlytics React Native SDK
|
|
10
10
|
*
|
|
11
11
|
* Manages session ID generation and rotation.
|
|
12
|
-
* Sessions are stored in RAM only (never persisted
|
|
12
|
+
* Sessions are stored in RAM only (never persisted to disk).
|
|
13
13
|
* Sessions automatically rotate every 2 hours.
|
|
14
14
|
*
|
|
15
|
-
* Copyright (c) 2025 Respectlytics.
|
|
15
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -35,8 +35,8 @@ function generateUUID() {
|
|
|
35
35
|
* - Rotated automatically every 2 hours
|
|
36
36
|
* - Regenerated on every app restart (new instance = new session)
|
|
37
37
|
*
|
|
38
|
-
* This RAM-only approach
|
|
39
|
-
* -
|
|
38
|
+
* This RAM-only approach means session data never touches device storage:
|
|
39
|
+
* - Sessions exist only in memory and are lost on app restart
|
|
40
40
|
* - Each app launch creates a fresh, unlinked session
|
|
41
41
|
*/
|
|
42
42
|
class SessionManager {
|
package/lib/commonjs/Storage.js
CHANGED
|
@@ -12,7 +12,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
12
12
|
*
|
|
13
13
|
* Wrapper around AsyncStorage for persisting SDK data.
|
|
14
14
|
*
|
|
15
|
-
* Copyright (c) 2025 Respectlytics.
|
|
15
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
/**
|
package/lib/commonjs/index.js
CHANGED
|
@@ -26,11 +26,11 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
26
26
|
*
|
|
27
27
|
* v2.0.0 Features:
|
|
28
28
|
* - Session-based analytics (no persistent user tracking)
|
|
29
|
-
* - RAM-only session storage (
|
|
29
|
+
* - RAM-only session storage (never persisted to disk)
|
|
30
30
|
* - Automatic 2-hour session rotation
|
|
31
31
|
* - New session on every app restart
|
|
32
|
-
*
|
|
33
|
-
* Copyright (c) 2025 Respectlytics.
|
|
32
|
+
*
|
|
33
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
34
34
|
*/
|
|
35
35
|
// Default export - the main SDK instance
|
|
36
36
|
var _default = exports.default = _Respectlytics.default; // Named exports for advanced usage
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_Respectlytics","_interopRequireWildcard","require","_types","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_default","exports","Respectlytics"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"names":["_Respectlytics","_interopRequireWildcard","require","_types","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_default","exports","Respectlytics"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;AAaA,IAAAA,cAAA,GAAAC,uBAAA,CAAAC,OAAA;AAOA,IAAAC,MAAA,GAAAD,OAAA;AAAgC,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;AApBhC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AAAA,IAAAkB,QAAA,GAAAC,OAAA,CAAAV,OAAA,GACeW,sBAAa,EAE5B","ignoreList":[]}
|
package/lib/commonjs/types.js
CHANGED
|
@@ -8,15 +8,14 @@ exports.STORAGE_KEYS = void 0;
|
|
|
8
8
|
* types.ts
|
|
9
9
|
* Respectlytics React Native SDK
|
|
10
10
|
*
|
|
11
|
-
* Copyright (c) 2025 Respectlytics.
|
|
12
|
-
* This SDK is provided under a proprietary license.
|
|
13
|
-
* See LICENSE file for details.
|
|
11
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
14
12
|
*/
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
15
|
* Represents an analytics event - flat structure matching API payload
|
|
18
16
|
*
|
|
19
|
-
*
|
|
17
|
+
* The SDK sends these 4 fields. The API stores 5 total
|
|
18
|
+
* (adding country, derived server-side from IP which is immediately discarded):
|
|
20
19
|
* - event_name (required)
|
|
21
20
|
* - timestamp
|
|
22
21
|
* - session_id
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["STORAGE_KEYS","exports","EVENT_QUEUE"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA
|
|
1
|
+
{"version":3,"names":["STORAGE_KEYS","exports","EVENT_QUEUE"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG;EAC1BE,WAAW,EAAE;AACf,CAAU","ignoreList":[]}
|
package/lib/module/EventQueue.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Manages event batching, persistence, and automatic flushing.
|
|
6
6
|
* Events are NEVER lost - they are persisted immediately and retried on failure.
|
|
7
|
-
* Copyright (c) 2025 Respectlytics.
|
|
7
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { AppState } from 'react-native';
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Respectlytics React Native SDK
|
|
4
4
|
*
|
|
5
5
|
* Handles HTTP communication with the Respectlytics API.
|
|
6
|
-
* Copyright (c) 2025 Respectlytics.
|
|
6
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const DEFAULT_API_ENDPOINT = 'https://respectlytics.com/api/v1/events/';
|
|
10
10
|
const MAX_RETRIES = 3;
|
|
11
11
|
const TIMEOUT_MS = 30000;
|
|
12
12
|
export let NetworkError = /*#__PURE__*/function (NetworkError) {
|
|
@@ -22,12 +22,16 @@ export let NetworkError = /*#__PURE__*/function (NetworkError) {
|
|
|
22
22
|
}({});
|
|
23
23
|
export class NetworkClient {
|
|
24
24
|
apiKey = null;
|
|
25
|
+
apiEndpoint = DEFAULT_API_ENDPOINT;
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
|
-
* Configure the network client with an API key
|
|
28
|
+
* Configure the network client with an API key and optional custom endpoint
|
|
28
29
|
*/
|
|
29
|
-
configure(apiKey) {
|
|
30
|
+
configure(apiKey, apiEndpoint) {
|
|
30
31
|
this.apiKey = apiKey;
|
|
32
|
+
if (apiEndpoint) {
|
|
33
|
+
this.apiEndpoint = apiEndpoint;
|
|
34
|
+
}
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
/**
|
|
@@ -59,7 +63,7 @@ export class NetworkClient {
|
|
|
59
63
|
const controller = new AbortController();
|
|
60
64
|
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
61
65
|
try {
|
|
62
|
-
const response = await fetch(
|
|
66
|
+
const response = await fetch(this.apiEndpoint, {
|
|
63
67
|
method: 'POST',
|
|
64
68
|
headers: {
|
|
65
69
|
'Content-Type': 'application/json',
|
|
@@ -123,8 +127,8 @@ export class NetworkClient {
|
|
|
123
127
|
}
|
|
124
128
|
|
|
125
129
|
/**
|
|
126
|
-
* Convert Event object to API payload format
|
|
127
|
-
*
|
|
130
|
+
* Convert Event object to API payload format.
|
|
131
|
+
* The SDK sends 4 fields; the API stores 5 (adding country derived from IP).
|
|
128
132
|
*/
|
|
129
133
|
eventToPayload(event) {
|
|
130
134
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["DEFAULT_API_ENDPOINT","MAX_RETRIES","TIMEOUT_MS","NetworkError","NetworkClient","apiKey","apiEndpoint","configure","isConfigured","send","events","Error","NotConfigured","event","sendEvent","attempt","controller","AbortController","timeoutId","setTimeout","abort","response","fetch","method","headers","body","JSON","stringify","eventToPayload","signal","clearTimeout","ok","status","Unauthorized","BadRequest","delay","Math","pow","RateLimited","ServerError","InvalidResponse","error","message","name","Timeout","event_name","eventName","timestamp","session_id","sessionId","platform","ms","Promise","resolve","networkClient"],"sourceRoot":"../../src","sources":["NetworkClient.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,MAAMA,oBAAoB,GAAG,0CAA0C;AACvE,MAAMC,WAAW,GAAG,CAAC;AACrB,MAAMC,UAAU,GAAG,KAAK;AAExB,WAAYC,YAAY,0BAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAA,OAAZA,YAAY;AAAA;AAWxB,OAAO,MAAMC,aAAa,CAAC;EACjBC,MAAM,GAAkB,IAAI;EAC5BC,WAAW,GAAWN,oBAAoB;;EAElD;AACF;AACA;EACEO,SAASA,CAACF,MAAc,EAAEC,WAAoB,EAAQ;IACpD,IAAI,CAACD,MAAM,GAAGA,MAAM;IACpB,IAAIC,WAAW,EAAE;MACf,IAAI,CAACA,WAAW,GAAGA,WAAW;IAChC;EACF;;EAEA;AACF;AACA;EACEE,YAAYA,CAAA,EAAY;IACtB,OAAO,IAAI,CAACH,MAAM,KAAK,IAAI;EAC7B;;EAEA;AACF;AACA;EACE,MAAMI,IAAIA,CAACC,MAAe,EAAiB;IACzC,IAAI,CAAC,IAAI,CAACL,MAAM,EAAE;MAChB,MAAM,IAAIM,KAAK,CAACR,YAAY,CAACS,aAAa,CAAC;IAC7C;IAEA,KAAK,MAAMC,KAAK,IAAIH,MAAM,EAAE;MAC1B,MAAM,IAAI,CAACI,SAAS,CAACD,KAAK,EAAE,CAAC,CAAC;IAChC;EACF;;EAEA;AACF;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AAG,CAAC,CAAC;MAC3C;MAEA,MAAM,IAAIJ,KAAK,CAACR,YAAY,CAACA,YAAY,CAAC;IAC5C;EACF;;EAEA;AACF;AACA;AACA;EACUyB,cAAcA,CAACf,KAAY,EAA2B;IAC5D,OAAO;MACLgC,UAAU,EAAEhC,KAAK,CAACiC,SAAS;MAC3BC,SAAS,EAAElC,KAAK,CAACkC,SAAS;MAC1BC,UAAU,EAAEnC,KAAK,CAACoC,SAAS;MAC3BC,QAAQ,EAAErC,KAAK,CAACqC;IAClB,CAAC;EACH;;EAEA;AACF;AACA;EACUf,KAAKA,CAACgB,EAAU,EAAiB;IACvC,OAAO,IAAIC,OAAO,CAACC,OAAO,IAAIlC,UAAU,CAACkC,OAAO,EAAEF,EAAE,CAAC,CAAC;EACxD;AACF;AAEA,OAAO,MAAMG,aAAa,GAAG,IAAIlD,aAAa,CAAC,CAAC","ignoreList":[]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Respectlytics React Native SDK
|
|
4
4
|
*
|
|
5
5
|
* Main entry point for the SDK.
|
|
6
|
-
* Copyright (c) 2025 Respectlytics.
|
|
6
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { Platform } from 'react-native';
|
|
@@ -18,13 +18,16 @@ import { EventQueue } from './EventQueue';
|
|
|
18
18
|
* - Session IDs are generated automatically in RAM
|
|
19
19
|
* - Sessions rotate every 2 hours
|
|
20
20
|
* - New session on every app restart
|
|
21
|
-
* - Only 4 fields sent
|
|
21
|
+
* - Only 4 fields sent by SDK; 5 stored (country derived server-side)
|
|
22
22
|
*
|
|
23
23
|
* Usage:
|
|
24
24
|
* ```typescript
|
|
25
25
|
* // 1. Configure at app launch
|
|
26
26
|
* Respectlytics.configure('your-api-key');
|
|
27
27
|
*
|
|
28
|
+
* // For self-hosted instances:
|
|
29
|
+
* Respectlytics.configure('your-api-key', { apiEndpoint: 'https://your-server.com/api/v1/events/' });
|
|
30
|
+
*
|
|
28
31
|
* // 2. Track events
|
|
29
32
|
* Respectlytics.track('purchase');
|
|
30
33
|
* ```
|
|
@@ -43,23 +46,24 @@ class RespectlyticsSDK {
|
|
|
43
46
|
* Call once at app startup.
|
|
44
47
|
*
|
|
45
48
|
* @param apiKey Your Respectlytics API key from the dashboard
|
|
49
|
+
* @param options Optional configuration (e.g., apiEndpoint for self-hosted instances)
|
|
46
50
|
*/
|
|
47
|
-
configure(apiKey) {
|
|
51
|
+
configure(apiKey, options) {
|
|
48
52
|
if (!apiKey || apiKey.trim() === '') {
|
|
49
53
|
console.log('[Respectlytics] ⚠️ API key cannot be empty');
|
|
50
54
|
return;
|
|
51
55
|
}
|
|
52
|
-
this.networkClient.configure(apiKey);
|
|
56
|
+
this.networkClient.configure(apiKey, options?.apiEndpoint);
|
|
53
57
|
this.eventQueue.start();
|
|
54
58
|
this.isConfigured = true;
|
|
55
|
-
console.log('[Respectlytics] ✓ SDK configured (v2.
|
|
59
|
+
console.log('[Respectlytics] ✓ SDK configured (v2.2.0)');
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
/**
|
|
59
63
|
* Track an event.
|
|
60
64
|
*
|
|
61
65
|
* Custom properties are NOT supported - this is by design for privacy.
|
|
62
|
-
* The API
|
|
66
|
+
* The API stores 5 fields (these 4 plus country derived server-side).
|
|
63
67
|
*
|
|
64
68
|
* @param eventName Name of the event (e.g., "purchase", "button_clicked")
|
|
65
69
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Platform","SessionManager","NetworkClient","EventQueue","RespectlyticsSDK","isConfigured","constructor","networkClient","eventQueue","sessionManager","platform","OS","configure","apiKey","trim","console","log","start","track","eventName","length","event","timestamp","Date","toISOString","sessionId","getSessionId","add","flush","Respectlytics"],"sourceRoot":"../../src","sources":["Respectlytics.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,QAAQ,cAAc;AAEvC,SAASC,cAAc,QAAQ,kBAAkB;AACjD,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,UAAU,QAAQ,cAAc;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,CAAC;EACbC,YAAY,GAAG,KAAK;EAM5BC,WAAWA,CAAA,EAAG;IACZ,IAAI,CAACC,aAAa,GAAG,IAAIL,aAAa,CAAC,CAAC;IACxC,IAAI,CAACM,UAAU,GAAG,IAAIL,UAAU,CAAC,IAAI,CAACI,aAAa,CAAC;IACpD,IAAI,CAACE,cAAc,GAAG,IAAIR,cAAc,CAAC,CAAC;IAC1C,IAAI,CAACS,QAAQ,GAAGV,QAAQ,CAACW,EAAE,KAAK,KAAK,GAAG,KAAK,GAAG,SAAS;EAC3D;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEC,SAASA,CAACC,MAAc,EAAQ;
|
|
1
|
+
{"version":3,"names":["Platform","SessionManager","NetworkClient","EventQueue","RespectlyticsSDK","isConfigured","constructor","networkClient","eventQueue","sessionManager","platform","OS","configure","apiKey","options","trim","console","log","apiEndpoint","start","track","eventName","length","event","timestamp","Date","toISOString","sessionId","getSessionId","add","flush","Respectlytics"],"sourceRoot":"../../src","sources":["Respectlytics.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,QAAQ,cAAc;AAEvC,SAASC,cAAc,QAAQ,kBAAkB;AACjD,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,UAAU,QAAQ,cAAc;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,CAAC;EACbC,YAAY,GAAG,KAAK;EAM5BC,WAAWA,CAAA,EAAG;IACZ,IAAI,CAACC,aAAa,GAAG,IAAIL,aAAa,C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AAc,CAACmB,YAAY,CAAC,CAAC;MAC7ClB,QAAQ,EAAE,IAAI,CAACA;IACjB,CAAC;IAED,IAAI,CAACF,UAAU,CAACqB,GAAG,CAACN,KAAK,CAAC;EAC5B;;EAEA;AACF;AACA;AACA;EACE,MAAMO,KAAKA,CAAA,EAAkB;IAC3B,MAAM,IAAI,CAACtB,UAAU,CAACsB,KAAK,CAAC,CAAC;EAC/B;AACF;;AAEA;AACA,MAAMC,aAAa,GAAG,IAAI3B,gBAAgB,CAAC,CAAC;AAC5C,eAAe2B,aAAa;AAC5B,SAAS3B,gBAAgB","ignoreList":[]}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Respectlytics React Native SDK
|
|
4
4
|
*
|
|
5
5
|
* Manages session ID generation and rotation.
|
|
6
|
-
* Sessions are stored in RAM only (never persisted
|
|
6
|
+
* Sessions are stored in RAM only (never persisted to disk).
|
|
7
7
|
* Sessions automatically rotate every 2 hours.
|
|
8
8
|
*
|
|
9
|
-
* Copyright (c) 2025 Respectlytics.
|
|
9
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -29,8 +29,8 @@ function generateUUID() {
|
|
|
29
29
|
* - Rotated automatically every 2 hours
|
|
30
30
|
* - Regenerated on every app restart (new instance = new session)
|
|
31
31
|
*
|
|
32
|
-
* This RAM-only approach
|
|
33
|
-
* -
|
|
32
|
+
* This RAM-only approach means session data never touches device storage:
|
|
33
|
+
* - Sessions exist only in memory and are lost on app restart
|
|
34
34
|
* - Each app launch creates a fresh, unlinked session
|
|
35
35
|
*/
|
|
36
36
|
export class SessionManager {
|
package/lib/module/Storage.js
CHANGED
package/lib/module/index.js
CHANGED
|
@@ -5,13 +5,12 @@
|
|
|
5
5
|
*
|
|
6
6
|
* v2.0.0 Features:
|
|
7
7
|
* - Session-based analytics (no persistent user tracking)
|
|
8
|
-
* - RAM-only session storage (
|
|
8
|
+
* - RAM-only session storage (never persisted to disk)
|
|
9
9
|
* - Automatic 2-hour session rotation
|
|
10
10
|
* - New session on every app restart
|
|
11
|
-
*
|
|
12
|
-
* Copyright (c) 2025 Respectlytics.
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
14
|
import Respectlytics from './Respectlytics';
|
|
16
15
|
|
|
17
16
|
// Default export - the main SDK instance
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Respectlytics","RespectlyticsSDK","Event"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA
|
|
1
|
+
{"version":3,"names":["Respectlytics","RespectlyticsSDK","Event"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,aAAa,MAAM,iBAAiB;;AAE3C;AACA,eAAeA,aAAa;;AAE5B;AACA,SAASC,gBAAgB,QAAQ,iBAAiB;AAClD,SAASC,KAAK,QAAQ,SAAS","ignoreList":[]}
|
package/lib/module/types.js
CHANGED
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
* types.ts
|
|
3
3
|
* Respectlytics React Native SDK
|
|
4
4
|
*
|
|
5
|
-
* Copyright (c) 2025 Respectlytics.
|
|
6
|
-
* This SDK is provided under a proprietary license.
|
|
7
|
-
* See LICENSE file for details.
|
|
5
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
8
6
|
*/
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* Represents an analytics event - flat structure matching API payload
|
|
12
10
|
*
|
|
13
|
-
*
|
|
11
|
+
* The SDK sends these 4 fields. The API stores 5 total
|
|
12
|
+
* (adding country, derived server-side from IP which is immediately discarded):
|
|
14
13
|
* - event_name (required)
|
|
15
14
|
* - timestamp
|
|
16
15
|
* - session_id
|
package/lib/module/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["STORAGE_KEYS","EVENT_QUEUE"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA
|
|
1
|
+
{"version":3,"names":["STORAGE_KEYS","EVENT_QUEUE"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,YAAY,GAAG;EAC1BC,WAAW,EAAE;AACf,CAAU","ignoreList":[]}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Manages event batching, persistence, and automatic flushing.
|
|
6
6
|
* Events are NEVER lost - they are persisted immediately and retried on failure.
|
|
7
|
-
* Copyright (c) 2025 Respectlytics.
|
|
7
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
8
8
|
*/
|
|
9
9
|
import { Event } from './types';
|
|
10
10
|
import { NetworkClient } from './NetworkClient';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Respectlytics React Native SDK
|
|
4
4
|
*
|
|
5
5
|
* Handles HTTP communication with the Respectlytics API.
|
|
6
|
-
* Copyright (c) 2025 Respectlytics.
|
|
6
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
7
7
|
*/
|
|
8
8
|
import { Event } from './types';
|
|
9
9
|
export declare enum NetworkError {
|
|
@@ -18,10 +18,11 @@ export declare enum NetworkError {
|
|
|
18
18
|
}
|
|
19
19
|
export declare class NetworkClient {
|
|
20
20
|
private apiKey;
|
|
21
|
+
private apiEndpoint;
|
|
21
22
|
/**
|
|
22
|
-
* Configure the network client with an API key
|
|
23
|
+
* Configure the network client with an API key and optional custom endpoint
|
|
23
24
|
*/
|
|
24
|
-
configure(apiKey: string): void;
|
|
25
|
+
configure(apiKey: string, apiEndpoint?: string): void;
|
|
25
26
|
/**
|
|
26
27
|
* Check if the client is configured
|
|
27
28
|
*/
|
|
@@ -35,8 +36,8 @@ export declare class NetworkClient {
|
|
|
35
36
|
*/
|
|
36
37
|
private sendEvent;
|
|
37
38
|
/**
|
|
38
|
-
* Convert Event object to API payload format
|
|
39
|
-
*
|
|
39
|
+
* Convert Event object to API payload format.
|
|
40
|
+
* The SDK sends 4 fields; the API stores 5 (adding country derived from IP).
|
|
40
41
|
*/
|
|
41
42
|
private eventToPayload;
|
|
42
43
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkClient.d.ts","sourceRoot":"","sources":["../../src/NetworkClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAMhC,oBAAY,YAAY;IACtB,aAAa,mBAAmB;IAChC,eAAe,qBAAqB;IACpC,YAAY,iBAAiB;IAC7B,UAAU,gBAAgB;IAC1B,WAAW,iBAAiB;IAC5B,WAAW,iBAAiB;IAC5B,YAAY,kBAAkB;IAC9B,OAAO,YAAY;CACpB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAuB;
|
|
1
|
+
{"version":3,"file":"NetworkClient.d.ts","sourceRoot":"","sources":["../../src/NetworkClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAMhC,oBAAY,YAAY;IACtB,aAAa,mBAAmB;IAChC,eAAe,qBAAqB;IACpC,YAAY,iBAAiB;IAC7B,UAAU,gBAAgB;IAC1B,WAAW,iBAAiB;IAC5B,WAAW,iBAAiB;IAC5B,YAAY,kBAAkB;IAC9B,OAAO,YAAY;CACpB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,WAAW,CAAgC;IAEnD;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IAOrD;;OAEG;IACH,YAAY,IAAI,OAAO;IAIvB;;OAEG;IACG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAU1C;;OAEG;YACW,SAAS;IAgFvB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAStB;;OAEG;IACH,OAAO,CAAC,KAAK;CAGd;AAED,eAAO,MAAM,aAAa,eAAsB,CAAC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Respectlytics React Native SDK
|
|
4
4
|
*
|
|
5
5
|
* Main entry point for the SDK.
|
|
6
|
-
* Copyright (c) 2025 Respectlytics.
|
|
6
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Main entry point for the Respectlytics SDK.
|
|
@@ -12,13 +12,16 @@
|
|
|
12
12
|
* - Session IDs are generated automatically in RAM
|
|
13
13
|
* - Sessions rotate every 2 hours
|
|
14
14
|
* - New session on every app restart
|
|
15
|
-
* - Only 4 fields sent
|
|
15
|
+
* - Only 4 fields sent by SDK; 5 stored (country derived server-side)
|
|
16
16
|
*
|
|
17
17
|
* Usage:
|
|
18
18
|
* ```typescript
|
|
19
19
|
* // 1. Configure at app launch
|
|
20
20
|
* Respectlytics.configure('your-api-key');
|
|
21
21
|
*
|
|
22
|
+
* // For self-hosted instances:
|
|
23
|
+
* Respectlytics.configure('your-api-key', { apiEndpoint: 'https://your-server.com/api/v1/events/' });
|
|
24
|
+
*
|
|
22
25
|
* // 2. Track events
|
|
23
26
|
* Respectlytics.track('purchase');
|
|
24
27
|
* ```
|
|
@@ -35,13 +38,16 @@ declare class RespectlyticsSDK {
|
|
|
35
38
|
* Call once at app startup.
|
|
36
39
|
*
|
|
37
40
|
* @param apiKey Your Respectlytics API key from the dashboard
|
|
41
|
+
* @param options Optional configuration (e.g., apiEndpoint for self-hosted instances)
|
|
38
42
|
*/
|
|
39
|
-
configure(apiKey: string
|
|
43
|
+
configure(apiKey: string, options?: {
|
|
44
|
+
apiEndpoint?: string;
|
|
45
|
+
}): void;
|
|
40
46
|
/**
|
|
41
47
|
* Track an event.
|
|
42
48
|
*
|
|
43
49
|
* Custom properties are NOT supported - this is by design for privacy.
|
|
44
|
-
* The API
|
|
50
|
+
* The API stores 5 fields (these 4 plus country derived server-side).
|
|
45
51
|
*
|
|
46
52
|
* @param eventName Name of the event (e.g., "purchase", "button_clicked")
|
|
47
53
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Respectlytics.d.ts","sourceRoot":"","sources":["../../src/Respectlytics.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH
|
|
1
|
+
{"version":3,"file":"Respectlytics.d.ts","sourceRoot":"","sources":["../../src/Respectlytics.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,cAAM,gBAAgB;IACpB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,QAAQ,CAAS;;IASzB;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAanE;;;;;;;OAOG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IA0B9B;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B;AAGD,QAAA,MAAM,aAAa,kBAAyB,CAAC;AAC7C,eAAe,aAAa,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Respectlytics React Native SDK
|
|
4
4
|
*
|
|
5
5
|
* Manages session ID generation and rotation.
|
|
6
|
-
* Sessions are stored in RAM only (never persisted
|
|
6
|
+
* Sessions are stored in RAM only (never persisted to disk).
|
|
7
7
|
* Sessions automatically rotate every 2 hours.
|
|
8
8
|
*
|
|
9
|
-
* Copyright (c) 2025 Respectlytics.
|
|
9
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
10
10
|
*/
|
|
11
11
|
/**
|
|
12
12
|
* Manages session ID generation and rotation.
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
* - Rotated automatically every 2 hours
|
|
18
18
|
* - Regenerated on every app restart (new instance = new session)
|
|
19
19
|
*
|
|
20
|
-
* This RAM-only approach
|
|
21
|
-
* -
|
|
20
|
+
* This RAM-only approach means session data never touches device storage:
|
|
21
|
+
* - Sessions exist only in memory and are lost on app restart
|
|
22
22
|
* - Each app launch creates a fresh, unlinked session
|
|
23
23
|
*/
|
|
24
24
|
export declare class SessionManager {
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
*
|
|
6
6
|
* v2.0.0 Features:
|
|
7
7
|
* - Session-based analytics (no persistent user tracking)
|
|
8
|
-
* - RAM-only session storage (
|
|
8
|
+
* - RAM-only session storage (never persisted to disk)
|
|
9
9
|
* - Automatic 2-hour session rotation
|
|
10
10
|
* - New session on every app restart
|
|
11
11
|
*
|
|
12
|
-
* Copyright (c) 2025 Respectlytics.
|
|
12
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
13
13
|
*/
|
|
14
14
|
import Respectlytics from './Respectlytics';
|
|
15
15
|
export default Respectlytics;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAG5C,eAAe,aAAa,CAAC;AAG7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
* types.ts
|
|
3
3
|
* Respectlytics React Native SDK
|
|
4
4
|
*
|
|
5
|
-
* Copyright (c) 2025 Respectlytics.
|
|
6
|
-
* This SDK is provided under a proprietary license.
|
|
7
|
-
* See LICENSE file for details.
|
|
5
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
8
6
|
*/
|
|
9
7
|
/**
|
|
10
8
|
* Represents an analytics event - flat structure matching API payload
|
|
11
9
|
*
|
|
12
|
-
*
|
|
10
|
+
* The SDK sends these 4 fields. The API stores 5 total
|
|
11
|
+
* (adding country, derived server-side from IP which is immediately discarded):
|
|
13
12
|
* - event_name (required)
|
|
14
13
|
* - timestamp
|
|
15
14
|
* - session_id
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,KAAK;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY;;CAEf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "respectlytics-react-native",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.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",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"url": "git+https://github.com/respectlytics/respectlytics-react-native.git"
|
|
39
39
|
},
|
|
40
40
|
"author": "Respectlytics <respectlytics@loheden.com>",
|
|
41
|
-
"license": "
|
|
41
|
+
"license": "MIT",
|
|
42
42
|
"bugs": {
|
|
43
43
|
"url": "https://github.com/respectlytics/respectlytics-react-native/issues"
|
|
44
44
|
},
|
package/src/EventQueue.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* EventQueue.ts
|
|
3
3
|
* Respectlytics React Native SDK
|
|
4
|
-
*
|
|
4
|
+
*
|
|
5
5
|
* Manages event batching, persistence, and automatic flushing.
|
|
6
6
|
* Events are NEVER lost - they are persisted immediately and retried on failure.
|
|
7
|
-
* Copyright (c) 2025 Respectlytics.
|
|
7
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { AppState, AppStateStatus } from 'react-native';
|
|
@@ -65,10 +65,10 @@ export class EventQueue {
|
|
|
65
65
|
*/
|
|
66
66
|
async add(event: Event): Promise<void> {
|
|
67
67
|
this.events.push(event);
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
// IMMEDIATELY persist before any async operations
|
|
70
70
|
await this.persistQueue();
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
// Check if we should flush
|
|
73
73
|
if (this.events.length >= MAX_QUEUE_SIZE) {
|
|
74
74
|
this.flush();
|
package/src/NetworkClient.ts
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* Respectlytics React Native SDK
|
|
4
4
|
*
|
|
5
5
|
* Handles HTTP communication with the Respectlytics API.
|
|
6
|
-
* Copyright (c) 2025 Respectlytics.
|
|
6
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { Event } from './types';
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const DEFAULT_API_ENDPOINT = 'https://respectlytics.com/api/v1/events/';
|
|
12
12
|
const MAX_RETRIES = 3;
|
|
13
13
|
const TIMEOUT_MS = 30000;
|
|
14
14
|
|
|
@@ -25,12 +25,16 @@ export enum NetworkError {
|
|
|
25
25
|
|
|
26
26
|
export class NetworkClient {
|
|
27
27
|
private apiKey: string | null = null;
|
|
28
|
+
private apiEndpoint: string = DEFAULT_API_ENDPOINT;
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
|
-
* Configure the network client with an API key
|
|
31
|
+
* Configure the network client with an API key and optional custom endpoint
|
|
31
32
|
*/
|
|
32
|
-
configure(apiKey: string): void {
|
|
33
|
+
configure(apiKey: string, apiEndpoint?: string): void {
|
|
33
34
|
this.apiKey = apiKey;
|
|
35
|
+
if (apiEndpoint) {
|
|
36
|
+
this.apiEndpoint = apiEndpoint;
|
|
37
|
+
}
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
/**
|
|
@@ -65,7 +69,7 @@ export class NetworkClient {
|
|
|
65
69
|
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
66
70
|
|
|
67
71
|
try {
|
|
68
|
-
const response = await fetch(
|
|
72
|
+
const response = await fetch(this.apiEndpoint, {
|
|
69
73
|
method: 'POST',
|
|
70
74
|
headers: {
|
|
71
75
|
'Content-Type': 'application/json',
|
|
@@ -137,8 +141,8 @@ export class NetworkClient {
|
|
|
137
141
|
}
|
|
138
142
|
|
|
139
143
|
/**
|
|
140
|
-
* Convert Event object to API payload format
|
|
141
|
-
*
|
|
144
|
+
* Convert Event object to API payload format.
|
|
145
|
+
* The SDK sends 4 fields; the API stores 5 (adding country derived from IP).
|
|
142
146
|
*/
|
|
143
147
|
private eventToPayload(event: Event): Record<string, unknown> {
|
|
144
148
|
return {
|
package/src/Respectlytics.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Respectlytics React Native SDK
|
|
4
4
|
*
|
|
5
5
|
* Main entry point for the SDK.
|
|
6
|
-
* Copyright (c) 2025 Respectlytics.
|
|
6
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { Platform } from 'react-native';
|
|
@@ -19,13 +19,16 @@ import { EventQueue } from './EventQueue';
|
|
|
19
19
|
* - Session IDs are generated automatically in RAM
|
|
20
20
|
* - Sessions rotate every 2 hours
|
|
21
21
|
* - New session on every app restart
|
|
22
|
-
* - Only 4 fields sent
|
|
22
|
+
* - Only 4 fields sent by SDK; 5 stored (country derived server-side)
|
|
23
23
|
*
|
|
24
24
|
* Usage:
|
|
25
25
|
* ```typescript
|
|
26
26
|
* // 1. Configure at app launch
|
|
27
27
|
* Respectlytics.configure('your-api-key');
|
|
28
28
|
*
|
|
29
|
+
* // For self-hosted instances:
|
|
30
|
+
* Respectlytics.configure('your-api-key', { apiEndpoint: 'https://your-server.com/api/v1/events/' });
|
|
31
|
+
*
|
|
29
32
|
* // 2. Track events
|
|
30
33
|
* Respectlytics.track('purchase');
|
|
31
34
|
* ```
|
|
@@ -49,25 +52,26 @@ class RespectlyticsSDK {
|
|
|
49
52
|
* Call once at app startup.
|
|
50
53
|
*
|
|
51
54
|
* @param apiKey Your Respectlytics API key from the dashboard
|
|
55
|
+
* @param options Optional configuration (e.g., apiEndpoint for self-hosted instances)
|
|
52
56
|
*/
|
|
53
|
-
configure(apiKey: string): void {
|
|
57
|
+
configure(apiKey: string, options?: { apiEndpoint?: string }): void {
|
|
54
58
|
if (!apiKey || apiKey.trim() === '') {
|
|
55
59
|
console.log('[Respectlytics] ⚠️ API key cannot be empty');
|
|
56
60
|
return;
|
|
57
61
|
}
|
|
58
62
|
|
|
59
|
-
this.networkClient.configure(apiKey);
|
|
63
|
+
this.networkClient.configure(apiKey, options?.apiEndpoint);
|
|
60
64
|
this.eventQueue.start();
|
|
61
65
|
this.isConfigured = true;
|
|
62
66
|
|
|
63
|
-
console.log('[Respectlytics] ✓ SDK configured (v2.
|
|
67
|
+
console.log('[Respectlytics] ✓ SDK configured (v2.2.0)');
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
/**
|
|
67
71
|
* Track an event.
|
|
68
72
|
*
|
|
69
73
|
* Custom properties are NOT supported - this is by design for privacy.
|
|
70
|
-
* The API
|
|
74
|
+
* The API stores 5 fields (these 4 plus country derived server-side).
|
|
71
75
|
*
|
|
72
76
|
* @param eventName Name of the event (e.g., "purchase", "button_clicked")
|
|
73
77
|
*/
|
package/src/SessionManager.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Respectlytics React Native SDK
|
|
4
4
|
*
|
|
5
5
|
* Manages session ID generation and rotation.
|
|
6
|
-
* Sessions are stored in RAM only (never persisted
|
|
6
|
+
* Sessions are stored in RAM only (never persisted to disk).
|
|
7
7
|
* Sessions automatically rotate every 2 hours.
|
|
8
8
|
*
|
|
9
|
-
* Copyright (c) 2025 Respectlytics.
|
|
9
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -22,15 +22,15 @@ function generateUUID(): string {
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Manages session ID generation and rotation.
|
|
25
|
-
*
|
|
25
|
+
*
|
|
26
26
|
* Session IDs are:
|
|
27
27
|
* - Generated immediately when the SDK initializes
|
|
28
28
|
* - Stored in RAM only (never persisted to AsyncStorage)
|
|
29
29
|
* - Rotated automatically every 2 hours
|
|
30
30
|
* - Regenerated on every app restart (new instance = new session)
|
|
31
|
-
*
|
|
32
|
-
* This RAM-only approach
|
|
33
|
-
* -
|
|
31
|
+
*
|
|
32
|
+
* This RAM-only approach means session data never touches device storage:
|
|
33
|
+
* - Sessions exist only in memory and are lost on app restart
|
|
34
34
|
* - Each app launch creates a fresh, unlinked session
|
|
35
35
|
*/
|
|
36
36
|
export class SessionManager {
|
package/src/Storage.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Respectlytics React Native SDK
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* Official SDK for privacy-first, session-based analytics.
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* v2.0.0 Features:
|
|
7
7
|
* - Session-based analytics (no persistent user tracking)
|
|
8
|
-
* - RAM-only session storage (
|
|
8
|
+
* - RAM-only session storage (never persisted to disk)
|
|
9
9
|
* - Automatic 2-hour session rotation
|
|
10
10
|
* - New session on every app restart
|
|
11
|
-
*
|
|
12
|
-
* Copyright (c) 2025 Respectlytics.
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
14
|
import Respectlytics from './Respectlytics';
|
|
16
15
|
|
|
17
16
|
// Default export - the main SDK instance
|
package/src/types.ts
CHANGED
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
* types.ts
|
|
3
3
|
* Respectlytics React Native SDK
|
|
4
4
|
*
|
|
5
|
-
* Copyright (c) 2025 Respectlytics.
|
|
6
|
-
* This SDK is provided under a proprietary license.
|
|
7
|
-
* See LICENSE file for details.
|
|
5
|
+
* Copyright (c) 2025 Respectlytics. Licensed under MIT.
|
|
8
6
|
*/
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* Represents an analytics event - flat structure matching API payload
|
|
12
10
|
*
|
|
13
|
-
*
|
|
11
|
+
* The SDK sends these 4 fields. The API stores 5 total
|
|
12
|
+
* (adding country, derived server-side from IP which is immediately discarded):
|
|
14
13
|
* - event_name (required)
|
|
15
14
|
* - timestamp
|
|
16
15
|
* - session_id
|