@affiliateo/react-native 1.0.2 → 1.1.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/package.json +1 -1
- package/src/provider.tsx +27 -2
- package/src/types.ts +2 -0
package/package.json
CHANGED
package/src/provider.tsx
CHANGED
|
@@ -73,11 +73,14 @@ async function getStableDeviceId(): Promise<string> {
|
|
|
73
73
|
return cachedDeviceId
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
const noop = () => {}
|
|
76
77
|
export const AffiliateoContext = createContext<AffiliateoContextValue>({
|
|
77
78
|
refCode: null,
|
|
78
79
|
isMatched: false,
|
|
79
80
|
isLoading: true,
|
|
80
81
|
visitorId: null,
|
|
82
|
+
trackScreen: noop,
|
|
83
|
+
trackEvent: noop,
|
|
81
84
|
})
|
|
82
85
|
|
|
83
86
|
/**
|
|
@@ -92,7 +95,7 @@ export function AffiliateoProvider({
|
|
|
92
95
|
apiUrl,
|
|
93
96
|
children,
|
|
94
97
|
}: AffiliateoConfig & { children: React.ReactNode }) {
|
|
95
|
-
const [state, setState] = useState<AffiliateoContextValue
|
|
98
|
+
const [state, setState] = useState<Omit<AffiliateoContextValue, 'trackScreen' | 'trackEvent'>>({
|
|
96
99
|
refCode: null,
|
|
97
100
|
isMatched: false,
|
|
98
101
|
isLoading: true,
|
|
@@ -166,8 +169,30 @@ export function AffiliateoProvider({
|
|
|
166
169
|
}
|
|
167
170
|
}, [campaignId, apiUrl])
|
|
168
171
|
|
|
172
|
+
const trackScreen = useCallback((screenName: string) => {
|
|
173
|
+
const deviceId = deviceIdRef.current
|
|
174
|
+
if (!deviceId) return
|
|
175
|
+
clientRef.current.sendEvents(campaignId, deviceId, [
|
|
176
|
+
{ type: 'screen_view', screen: screenName, timestamp: new Date().toISOString() },
|
|
177
|
+
]).catch(() => {})
|
|
178
|
+
}, [campaignId])
|
|
179
|
+
|
|
180
|
+
const trackEvent = useCallback((eventName: string, metadata?: Record<string, unknown>) => {
|
|
181
|
+
const deviceId = deviceIdRef.current
|
|
182
|
+
if (!deviceId) return
|
|
183
|
+
clientRef.current.sendEvents(campaignId, deviceId, [
|
|
184
|
+
{ type: 'custom', screen: eventName, timestamp: new Date().toISOString(), metadata },
|
|
185
|
+
]).catch(() => {})
|
|
186
|
+
}, [campaignId])
|
|
187
|
+
|
|
188
|
+
const contextValue: AffiliateoContextValue = {
|
|
189
|
+
...state,
|
|
190
|
+
trackScreen,
|
|
191
|
+
trackEvent,
|
|
192
|
+
}
|
|
193
|
+
|
|
169
194
|
return (
|
|
170
|
-
<AffiliateoContext.Provider value={
|
|
195
|
+
<AffiliateoContext.Provider value={contextValue}>
|
|
171
196
|
{children}
|
|
172
197
|
</AffiliateoContext.Provider>
|
|
173
198
|
)
|
package/src/types.ts
CHANGED