@traffical/react-native 0.5.0 → 0.5.2
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 +56 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -324,6 +324,62 @@ function CheckoutScreen({ navigation }) {
|
|
|
324
324
|
|
|
325
325
|
---
|
|
326
326
|
|
|
327
|
+
## Type-Safe Event Tracking
|
|
328
|
+
|
|
329
|
+
The `useTraffical` hook supports a `TEvents` generic that enforces event names and property shapes at compile time. Combined with `@traffical/cli generate-types`, you get full type safety on every `track()` call.
|
|
330
|
+
|
|
331
|
+
### 1. Generate types from your config
|
|
332
|
+
|
|
333
|
+
```bash
|
|
334
|
+
bunx @traffical/cli generate-types
|
|
335
|
+
# → creates .traffical/traffical.generated.ts
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### 2. Create a typed wrapper
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
// lib/traffical.ts
|
|
342
|
+
import type { TrafficalEventProperties } from './traffical.generated';
|
|
343
|
+
import { useTraffical as useTrafficalBase, type UseTrafficalOptions, type ParameterValue } from '@traffical/react-native';
|
|
344
|
+
|
|
345
|
+
export type TrafficalTrack = <E extends Extract<keyof TrafficalEventProperties, string>>(
|
|
346
|
+
event: E,
|
|
347
|
+
properties?: TrafficalEventProperties[E],
|
|
348
|
+
options?: { decisionId?: string; unitKey?: string }
|
|
349
|
+
) => void;
|
|
350
|
+
|
|
351
|
+
export function useTraffical<T extends Record<string, ParameterValue>>(
|
|
352
|
+
options: UseTrafficalOptions<T>
|
|
353
|
+
) {
|
|
354
|
+
const result = useTrafficalBase<T>(options);
|
|
355
|
+
return { ...result, track: result.track as unknown as TrafficalTrack };
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### 3. Use it
|
|
360
|
+
|
|
361
|
+
```tsx
|
|
362
|
+
import { useTraffical } from '@/lib/traffical';
|
|
363
|
+
|
|
364
|
+
function PaywallScreen() {
|
|
365
|
+
const { params, track } = useTraffical({
|
|
366
|
+
defaults: { 'paywall.headline': 'Go Premium' },
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
track('subscribe', {
|
|
370
|
+
plan: 'pro_monthly',
|
|
371
|
+
value: 9.99,
|
|
372
|
+
}); // ✅ compiles — properties checked against generated schema
|
|
373
|
+
|
|
374
|
+
track('subscribe', {
|
|
375
|
+
plan: 'pro_monthly',
|
|
376
|
+
bogus: true, // ❌ Type error: not in SubscribeProperties
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
---
|
|
382
|
+
|
|
327
383
|
## Differences from @traffical/react
|
|
328
384
|
|
|
329
385
|
| | `@traffical/react` | `@traffical/react-native` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@traffical/react-native",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Traffical SDK for React Native - server-evaluated feature flags, A/B testing, and adaptive optimization",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"typecheck": "tsc --noEmit"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@traffical/core": "0.
|
|
26
|
-
"@traffical/js-client": "0.
|
|
25
|
+
"@traffical/core": "0.8.0",
|
|
26
|
+
"@traffical/js-client": "0.12.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/bun": "latest",
|