@affiliateo/react-native 1.0.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@affiliateo/react-native",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Affiliateo SDK for React Native — mobile affiliate attribution and screen tracking",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
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,
@@ -153,7 +156,7 @@ export function AffiliateoProvider({
153
156
  client.sendEvents(campaignId, deviceId, [
154
157
  { type: 'session_start', timestamp: new Date().toISOString() },
155
158
  ]).catch(() => {})
156
- } else if (nextState === 'background' || nextState === 'inactive') {
159
+ } else if (nextState === 'background') {
157
160
  client.sendEvents(campaignId, deviceId, [
158
161
  { type: 'session_end', timestamp: new Date().toISOString() },
159
162
  ]).catch(() => {})
@@ -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={state}>
195
+ <AffiliateoContext.Provider value={contextValue}>
171
196
  {children}
172
197
  </AffiliateoContext.Provider>
173
198
  )
package/src/types.ts CHANGED
@@ -33,4 +33,6 @@ export interface AffiliateoContextValue {
33
33
  isMatched: boolean
34
34
  isLoading: boolean
35
35
  visitorId: string | null
36
+ trackScreen: (screenName: string) => void
37
+ trackEvent: (eventName: string, metadata?: Record<string, unknown>) => void
36
38
  }