insert-affiliate-react-native-sdk 1.0.6 → 1.0.7
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/DeepLinkIapProvider.tsx +37 -0
- package/updateProcess.md +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "insert-affiliate-react-native-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "A package that will give context having implementation of react-native-branch and react-native-iap and iaptic validate api.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,6 +31,7 @@ type T_DEEPLINK_IAP_CONTEXT = {
|
|
|
31
31
|
userId: string;
|
|
32
32
|
isIapticValidated: boolean | undefined;
|
|
33
33
|
handleBuySubscription: (productId: string, offerToken?: string) => void;
|
|
34
|
+
trackEvent: (eventName: string) => Promise<void>;
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
type RequestBody = {
|
|
@@ -65,6 +66,7 @@ export const DeepLinkIapContext = createContext<T_DEEPLINK_IAP_CONTEXT>({
|
|
|
65
66
|
referrerLink: "",
|
|
66
67
|
userId: "",
|
|
67
68
|
handleBuySubscription: (productId: string, offerToken?: string) => {},
|
|
69
|
+
trackEvent: async (eventName: string) => {},
|
|
68
70
|
});
|
|
69
71
|
|
|
70
72
|
const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
|
|
@@ -372,6 +374,40 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
|
|
|
372
374
|
}
|
|
373
375
|
};
|
|
374
376
|
|
|
377
|
+
const trackEvent = async (eventName: string): Promise<void> => {
|
|
378
|
+
try {
|
|
379
|
+
if (!referrerLink || !userId) {
|
|
380
|
+
console.warn(
|
|
381
|
+
"[Insert Affiliate] No affiliate identifier found. Please set one before tracking events."
|
|
382
|
+
);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const payload = {
|
|
387
|
+
eventName,
|
|
388
|
+
deepLinkParam: `${referrerLink}/${userId}`, // Similar to Swift SDK
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
const response = await axios.post(
|
|
392
|
+
"https://api.insertaffiliate.com/v1/trackEvent",
|
|
393
|
+
payload,
|
|
394
|
+
{
|
|
395
|
+
headers: { "Content-Type": "application/json" },
|
|
396
|
+
}
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
if (response.status === 200) {
|
|
400
|
+
console.log("[Insert Affiliate] Event tracked successfully");
|
|
401
|
+
} else {
|
|
402
|
+
console.error(
|
|
403
|
+
`[Insert Affiliate] Failed to track event with status code: ${response.status}`
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
} catch (error) {
|
|
407
|
+
console.error("[Insert Affiliate] Error tracking event:", error);
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
|
|
375
411
|
useEffect(() => {
|
|
376
412
|
return () => {
|
|
377
413
|
endConnection();
|
|
@@ -389,6 +425,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
|
|
|
389
425
|
referrerLink,
|
|
390
426
|
userId,
|
|
391
427
|
handleBuySubscription,
|
|
428
|
+
trackEvent,
|
|
392
429
|
}}
|
|
393
430
|
>
|
|
394
431
|
{children}
|
package/updateProcess.md
CHANGED