insert-affiliate-react-native-sdk 1.10.0 → 1.11.1
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/.claude/settings.local.json +8 -2
- package/dist/DeepLinkIapProvider.js +253 -151
- package/docs/deep-linking-appsflyer.md +23 -2
- package/docs/deep-linking-branch.md +23 -2
- package/package.json +1 -1
- package/readme.md +70 -22
- package/src/DeepLinkIapProvider.tsx +225 -91
|
@@ -102,7 +102,7 @@ AppRegistry.registerComponent(appName, () => RootComponent);
|
|
|
102
102
|
### Example with Adapty
|
|
103
103
|
|
|
104
104
|
```javascript
|
|
105
|
-
import React, { useEffect } from 'react';
|
|
105
|
+
import React, { useEffect, useRef } from 'react';
|
|
106
106
|
import { AppRegistry, Platform } from 'react-native';
|
|
107
107
|
import appsFlyer from 'react-native-appsflyer';
|
|
108
108
|
import { adapty } from 'react-native-adapty';
|
|
@@ -112,6 +112,25 @@ import { name as appName } from './app.json';
|
|
|
112
112
|
|
|
113
113
|
const DeepLinkHandler = () => {
|
|
114
114
|
const { setInsertAffiliateIdentifier, isInitialized } = useDeepLinkIapProvider();
|
|
115
|
+
const adaptyActivationPromiseRef = useRef(null);
|
|
116
|
+
|
|
117
|
+
// Initialize Adapty SDK
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
const initAdapty = async () => {
|
|
120
|
+
try {
|
|
121
|
+
adaptyActivationPromiseRef.current = adapty.activate('YOUR_ADAPTY_PUBLIC_SDK_KEY', {
|
|
122
|
+
__ignoreActivationOnFastRefresh: __DEV__,
|
|
123
|
+
});
|
|
124
|
+
await adaptyActivationPromiseRef.current;
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error('Failed to activate Adapty SDK:', error);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
if (!adaptyActivationPromiseRef.current) {
|
|
131
|
+
initAdapty();
|
|
132
|
+
}
|
|
133
|
+
}, []);
|
|
115
134
|
|
|
116
135
|
useEffect(() => {
|
|
117
136
|
if (!isInitialized) return;
|
|
@@ -138,7 +157,9 @@ const DeepLinkHandler = () => {
|
|
|
138
157
|
try {
|
|
139
158
|
const insertAffiliateIdentifier = await setInsertAffiliateIdentifier(referringLink);
|
|
140
159
|
|
|
141
|
-
if (insertAffiliateIdentifier) {
|
|
160
|
+
if (insertAffiliateIdentifier && adaptyActivationPromiseRef.current) {
|
|
161
|
+
// Wait for Adapty activation before updating profile
|
|
162
|
+
await adaptyActivationPromiseRef.current;
|
|
142
163
|
await adapty.updateProfile({
|
|
143
164
|
codableCustomAttributes: {
|
|
144
165
|
insert_affiliate: insertAffiliateIdentifier,
|
|
@@ -80,7 +80,7 @@ AppRegistry.registerComponent(appName, () => RootComponent);
|
|
|
80
80
|
### Example with Adapty
|
|
81
81
|
|
|
82
82
|
```javascript
|
|
83
|
-
import React, { useEffect } from 'react';
|
|
83
|
+
import React, { useEffect, useRef } from 'react';
|
|
84
84
|
import { AppRegistry } from 'react-native';
|
|
85
85
|
import branch from 'react-native-branch';
|
|
86
86
|
import { adapty } from 'react-native-adapty';
|
|
@@ -90,6 +90,25 @@ import { name as appName } from './app.json';
|
|
|
90
90
|
|
|
91
91
|
const DeepLinkHandler = () => {
|
|
92
92
|
const { setInsertAffiliateIdentifier } = useDeepLinkIapProvider();
|
|
93
|
+
const adaptyActivationPromiseRef = useRef(null);
|
|
94
|
+
|
|
95
|
+
// Initialize Adapty SDK
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
const initAdapty = async () => {
|
|
98
|
+
try {
|
|
99
|
+
adaptyActivationPromiseRef.current = adapty.activate('YOUR_ADAPTY_PUBLIC_SDK_KEY', {
|
|
100
|
+
__ignoreActivationOnFastRefresh: __DEV__,
|
|
101
|
+
});
|
|
102
|
+
await adaptyActivationPromiseRef.current;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error('Failed to activate Adapty SDK:', error);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
if (!adaptyActivationPromiseRef.current) {
|
|
109
|
+
initAdapty();
|
|
110
|
+
}
|
|
111
|
+
}, []);
|
|
93
112
|
|
|
94
113
|
useEffect(() => {
|
|
95
114
|
const branchSubscription = branch.subscribe(async ({ error, params }) => {
|
|
@@ -104,7 +123,9 @@ const DeepLinkHandler = () => {
|
|
|
104
123
|
try {
|
|
105
124
|
const insertAffiliateIdentifier = await setInsertAffiliateIdentifier(referringLink);
|
|
106
125
|
|
|
107
|
-
if (insertAffiliateIdentifier) {
|
|
126
|
+
if (insertAffiliateIdentifier && adaptyActivationPromiseRef.current) {
|
|
127
|
+
// Wait for Adapty activation before updating profile
|
|
128
|
+
await adaptyActivationPromiseRef.current;
|
|
108
129
|
await adapty.updateProfile({
|
|
109
130
|
codableCustomAttributes: {
|
|
110
131
|
insert_affiliate: insertAffiliateIdentifier,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "insert-affiliate-react-native-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.1",
|
|
4
4
|
"description": "A package for connecting with the Insert Affiliate Platform to add app based affiliate marketing.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/readme.md
CHANGED
|
@@ -234,7 +234,7 @@ Complete the [Adapty SDK installation](https://adapty.io/docs/sdk-installation-r
|
|
|
234
234
|
**Step 2: Code Setup**
|
|
235
235
|
|
|
236
236
|
```javascript
|
|
237
|
-
import React, { useEffect } from 'react';
|
|
237
|
+
import React, { useEffect, useRef } from 'react';
|
|
238
238
|
import { adapty } from 'react-native-adapty';
|
|
239
239
|
import { useDeepLinkIapProvider } from 'insert-affiliate-react-native-sdk';
|
|
240
240
|
|
|
@@ -242,30 +242,53 @@ const ADAPTY_PUBLIC_SDK_KEY = 'YOUR_ADAPTY_PUBLIC_SDK_KEY'; // From https://app.
|
|
|
242
242
|
|
|
243
243
|
const App = () => {
|
|
244
244
|
const { initialize, isInitialized, setInsertAffiliateIdentifierChangeCallback } = useDeepLinkIapProvider();
|
|
245
|
+
const adaptyActivationPromiseRef = useRef(null);
|
|
245
246
|
|
|
246
|
-
// Initialize
|
|
247
|
+
// Initialize Adapty SDK
|
|
247
248
|
useEffect(() => {
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
249
|
+
const initAdapty = async () => {
|
|
250
|
+
try {
|
|
251
|
+
adaptyActivationPromiseRef.current = adapty.activate(ADAPTY_PUBLIC_SDK_KEY, {
|
|
252
|
+
__ignoreActivationOnFastRefresh: __DEV__,
|
|
253
|
+
});
|
|
254
|
+
await adaptyActivationPromiseRef.current;
|
|
255
|
+
} catch (error) {
|
|
256
|
+
console.error('Failed to activate Adapty SDK:', error);
|
|
255
257
|
}
|
|
256
258
|
};
|
|
257
|
-
|
|
259
|
+
|
|
260
|
+
if (!adaptyActivationPromiseRef.current) {
|
|
261
|
+
initAdapty();
|
|
262
|
+
}
|
|
263
|
+
}, []);
|
|
264
|
+
|
|
265
|
+
// Initialize Insert Affiliate SDK
|
|
266
|
+
useEffect(() => {
|
|
267
|
+
if (!isInitialized) {
|
|
268
|
+
initialize("YOUR_COMPANY_CODE");
|
|
269
|
+
}
|
|
258
270
|
}, [initialize, isInitialized]);
|
|
259
271
|
|
|
260
272
|
// Set Adapty attribute when affiliate identifier changes
|
|
261
273
|
useEffect(() => {
|
|
262
274
|
setInsertAffiliateIdentifierChangeCallback(async (identifier) => {
|
|
263
275
|
if (identifier) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
276
|
+
if (adaptyActivationPromiseRef.current) {
|
|
277
|
+
try {
|
|
278
|
+
// Wait for Adapty activation before updating profile
|
|
279
|
+
await adaptyActivationPromiseRef.current;
|
|
280
|
+
|
|
281
|
+
await adapty.updateProfile({
|
|
282
|
+
codableCustomAttributes: {
|
|
283
|
+
insert_affiliate: identifier,
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
} catch (error) {
|
|
287
|
+
console.error('Failed to update Adapty profile with affiliate identifier:', error);
|
|
288
|
+
}
|
|
289
|
+
} else {
|
|
290
|
+
console.error('Adapty SDK is not initialized');
|
|
291
|
+
}
|
|
269
292
|
}
|
|
270
293
|
});
|
|
271
294
|
|
|
@@ -502,25 +525,50 @@ const App = () => {
|
|
|
502
525
|
**With Adapty:**
|
|
503
526
|
|
|
504
527
|
```javascript
|
|
528
|
+
import React, { useEffect, useRef } from 'react';
|
|
505
529
|
import { useDeepLinkIapProvider } from 'insert-affiliate-react-native-sdk';
|
|
506
530
|
import { adapty } from 'react-native-adapty';
|
|
507
531
|
|
|
508
532
|
const App = () => {
|
|
509
533
|
const { setInsertAffiliateIdentifierChangeCallback } = useDeepLinkIapProvider();
|
|
534
|
+
const adaptyActivationPromiseRef = useRef(null);
|
|
510
535
|
|
|
536
|
+
// Initialize Adapty SDK (see Option 2: Adapty for full setup)
|
|
511
537
|
useEffect(() => {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
insert_affiliate: identifier,
|
|
517
|
-
},
|
|
538
|
+
const initAdapty = async () => {
|
|
539
|
+
try {
|
|
540
|
+
adaptyActivationPromiseRef.current = adapty.activate('YOUR_ADAPTY_PUBLIC_SDK_KEY', {
|
|
541
|
+
__ignoreActivationOnFastRefresh: __DEV__,
|
|
518
542
|
});
|
|
543
|
+
await adaptyActivationPromiseRef.current;
|
|
544
|
+
} catch (error) {
|
|
545
|
+
console.error('Failed to activate Adapty SDK:', error);
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
if (!adaptyActivationPromiseRef.current) {
|
|
550
|
+
initAdapty();
|
|
551
|
+
}
|
|
552
|
+
}, []);
|
|
553
|
+
|
|
554
|
+
useEffect(() => {
|
|
555
|
+
setInsertAffiliateIdentifierChangeCallback(async (identifier) => {
|
|
556
|
+
if (identifier && adaptyActivationPromiseRef.current) {
|
|
557
|
+
try {
|
|
558
|
+
await adaptyActivationPromiseRef.current;
|
|
559
|
+
await adapty.updateProfile({
|
|
560
|
+
codableCustomAttributes: {
|
|
561
|
+
insert_affiliate: identifier,
|
|
562
|
+
},
|
|
563
|
+
});
|
|
564
|
+
} catch (error) {
|
|
565
|
+
console.error('Failed to update Adapty profile:', error);
|
|
566
|
+
}
|
|
519
567
|
}
|
|
520
568
|
});
|
|
521
569
|
|
|
522
570
|
return () => setInsertAffiliateIdentifierChangeCallback(null);
|
|
523
|
-
}, []);
|
|
571
|
+
}, [setInsertAffiliateIdentifierChangeCallback]);
|
|
524
572
|
|
|
525
573
|
return <YourAppContent />;
|
|
526
574
|
};
|