@selwise/react-native 0.1.2 → 0.1.4
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 +79 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Headless React Native SDK for Selwise tracking, identity, search, and recommenda
|
|
|
8
8
|
npm install @selwise/react-native @react-native-async-storage/async-storage
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Compatible with Expo and Bare React Native.
|
|
12
12
|
|
|
13
13
|
## Quick Start
|
|
14
14
|
|
|
@@ -21,39 +21,99 @@ await sdk.init({
|
|
|
21
21
|
siteKey: 'YOUR_SITE_KEY',
|
|
22
22
|
apiUrl: 'https://api.selwise.com/api/v1',
|
|
23
23
|
apiKey: 'YOUR_MOBILE_API_KEY',
|
|
24
|
-
sdkVersion: '0.1.
|
|
24
|
+
sdkVersion: '0.1.2',
|
|
25
25
|
});
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
##
|
|
28
|
+
## Config Reference
|
|
29
|
+
|
|
30
|
+
| Field | Required | Default | Description |
|
|
31
|
+
| --- | --- | --- | --- |
|
|
32
|
+
| `siteKey` | Yes | - | Selwise site key. |
|
|
33
|
+
| `apiKey` | Yes | - | Scoped mobile API key. |
|
|
34
|
+
| `apiUrl` | No | `https://api.selwise.com/api/v1` | API base URL. |
|
|
35
|
+
| `sdkPlatform` | No | `react-native` | Header value for client platform. |
|
|
36
|
+
| `sdkVersion` | No | `0.1.0` | Header value for SDK version. |
|
|
37
|
+
| `flushIntervalMs` | No | `15000` | Periodic flush interval. |
|
|
38
|
+
| `batchSize` | No | `25` | Max events per flush batch. |
|
|
39
|
+
| `maxRetries` | No | `5` | Retry attempts per failed event. |
|
|
40
|
+
| `maxQueueSize` | No | `500` | Max queued events. |
|
|
41
|
+
| `journeyTtlMs` | No | `1800000` | Journey expiration window. |
|
|
42
|
+
| `storagePrefix` | No | `selwise_rn` | Storage key prefix. |
|
|
43
|
+
| `storage` | No | AsyncStorage if available, otherwise in-memory | Custom storage adapter. |
|
|
44
|
+
|
|
45
|
+
## Method Availability
|
|
46
|
+
|
|
47
|
+
| Method Group | Available | Notes |
|
|
48
|
+
| --- | --- | --- |
|
|
49
|
+
| Lifecycle (`init`, `destroy`) | Yes | `init` required before other calls. |
|
|
50
|
+
| Tracking (`track`, `flush`) | Yes | `flush` forces immediate network send. |
|
|
51
|
+
| Orders (`trackOrder`) | Yes | Sends to public order endpoint. |
|
|
52
|
+
| Identity (`identify`, `setTraits`) | Yes | Links and updates user profile state. |
|
|
53
|
+
| Session/Journey getters | Yes | Returns runtime IDs and journey state. |
|
|
54
|
+
| Data layer (`pushDataLayer`, `getDataLayer`) | Yes | Local state snapshot, not a network sender by itself. |
|
|
55
|
+
| Consent (`getConsentState`, `grantConsent`, `revokeConsent`) | Yes | Uses public consent endpoints with scoped auth. |
|
|
56
|
+
| Headless data APIs (`search`, recommendation, config methods) | Yes | You render UI in app code. |
|
|
57
|
+
| `window.Selwise` / DOM rendering | No | v1 is headless only. |
|
|
58
|
+
|
|
59
|
+
## Track vs Data Layer
|
|
29
60
|
|
|
30
61
|
```ts
|
|
31
|
-
sdk.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
metadata: { source: 'react-native' },
|
|
62
|
+
sdk.track('product_view', {
|
|
63
|
+
entityType: 'product',
|
|
64
|
+
entityId: 'sku-123',
|
|
65
|
+
metadata: { productItemCode: 'sku-123' },
|
|
36
66
|
});
|
|
37
67
|
|
|
38
68
|
await sdk.flush();
|
|
39
69
|
```
|
|
40
70
|
|
|
41
|
-
|
|
71
|
+
```ts
|
|
72
|
+
sdk.pushDataLayer({
|
|
73
|
+
event: 'product_view',
|
|
74
|
+
product: { sku: 'sku-123', title: 'Runner Pro' },
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
console.log(sdk.getDataLayer());
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- `track` is for canonical network event ingestion.
|
|
81
|
+
- `pushDataLayer` is for local structured state mirroring.
|
|
42
82
|
|
|
43
|
-
|
|
83
|
+
## Auth Scope Quick Reference
|
|
84
|
+
|
|
85
|
+
| HTTP Method | Required Scope |
|
|
86
|
+
| --- | --- |
|
|
87
|
+
| `GET` | `mobile_read` |
|
|
88
|
+
| `POST`, `PUT`, `PATCH`, `DELETE` | `mobile_write` |
|
|
89
|
+
|
|
90
|
+
Headers sent automatically:
|
|
44
91
|
|
|
45
92
|
- `x-selwise-api-key`
|
|
46
|
-
- `x-selwise-client-platform
|
|
47
|
-
- `x-selwise-client-version
|
|
93
|
+
- `x-selwise-client-platform`
|
|
94
|
+
- `x-selwise-client-version`
|
|
95
|
+
|
|
96
|
+
## Troubleshooting
|
|
97
|
+
|
|
98
|
+
1. `403 Invalid API key or insufficient scope`.
|
|
99
|
+
- Check key status and method scope.
|
|
100
|
+
|
|
101
|
+
2. Events are queued but not ingested.
|
|
102
|
+
- Call `await sdk.flush()` and verify network/retry window.
|
|
103
|
+
|
|
104
|
+
3. Search/recommendation responses arrive but nothing renders.
|
|
105
|
+
- SDK is headless; render data with your own RN components.
|
|
48
106
|
|
|
49
|
-
##
|
|
107
|
+
## Documentation
|
|
50
108
|
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
|
|
55
|
-
|
|
109
|
+
- [React Native Integration](https://docs.selwise.com/getting-started/react-native-integration/)
|
|
110
|
+
- [Platform Playbooks](https://docs.selwise.com/getting-started/platform-playbooks/)
|
|
111
|
+
- [Public API](https://docs.selwise.com/client-api/public-api/)
|
|
112
|
+
- [Event Cookbook](https://docs.selwise.com/client-api/event-cookbook/)
|
|
113
|
+
- [Mobile Auth](https://docs.selwise.com/client-api/mobile-auth/)
|
|
114
|
+
- [Verification](https://docs.selwise.com/getting-started/verification/)
|
|
115
|
+
- [Troubleshooting](https://docs.selwise.com/getting-started/integration-troubleshooting/)
|
|
56
116
|
|
|
57
117
|
## License
|
|
58
118
|
|
|
59
|
-
MIT
|
|
119
|
+
MIT, see [LICENSE](./LICENSE).
|