insert-affiliate-react-native-sdk 1.1.2 → 1.1.5

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 CHANGED
@@ -2,53 +2,70 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- The **InsertAffiliateReactNative SDK** is designed for React Native applications, providing seamless integration with the [Insert Affiliate platform](https://insertaffiliate.com). For more details and to access the Insert Affiliate dashboard, visit [app.insertaffiliate.com](https://app.insertaffiliate.com).
5
+ The **InsertAffiliateReactNative SDK** is designed for React Native applications, providing seamless integration with the [Insert Affiliate platform](https://insertaffiliate.com). The InsertAffiliateReactNative SDK simplifies affiliate marketing for iOS apps with in-app-purchases, allowing developers to create a seamless user experience for affiliate tracking and monetisation.
6
6
 
7
- ## Features
7
+ ### Features
8
8
 
9
- - **Unique Device Identification**: Generates and stores a short unique device ID to identify users effectively.
9
+ - **Unique Device ID**: Creates a unique ID to anonymously associate purchases with users for tracking purposes.
10
10
  - **Affiliate Identifier Management**: Set and retrieve the affiliate identifier based on user-specific links.
11
- - **In-App Purchase (IAP) Initialisation**: Easily reinitialise in-app purchases with validation options using the affiliate identifier.
11
+ - **In-App Purchase (IAP) Initialisation**: Easily reinitialise in-app purchases with the option to validate using an affiliate identifier.
12
12
 
13
13
  ## Peer Dependencies
14
14
 
15
15
  Before using this package, ensure you have the following dependencies installed:
16
16
 
17
17
  - [react-native-iap](https://www.npmjs.com/package/react-native-iap)
18
- - [react-native-branch](https://www.npmjs.com/package/react-native-branch)
19
18
  - [axios](https://www.npmjs.com/package/axios)
20
19
 
20
+ ## Getting Started
21
+
22
+ To get started with the InsertAffiliateReactNative SDK:
23
+
24
+ 1. [Install the React Native Package](#installation)
25
+ 2. [Initialise the SDK in App.tsx](#basic-usage)
26
+ 3. [Set up in-app purchases (Required)](#in-app-purchase-setup-required)
27
+ 4. [Set up deep linking (Required)](#deep-link-setup-required)
28
+
21
29
  ## Installation
22
30
 
23
- To integrate the InsertAffiliateReactNative SDK into your project, run:
31
+ To integrate the InsertAffiliateReactNative SDK into your app:
24
32
 
33
+ 1. Install the NPM package.
25
34
  ```bash
26
35
  npm install insert-affiliate-react-native-sdk
27
36
  ```
28
37
 
29
- ## Usage
30
- ### Importing the SDK
31
- Import the provider from the package:
38
+ ## Basic Usage
32
39
 
40
+ ### Initialisation in `App.tsx`
33
41
 
34
- ```javascript
35
- import { DeepLinkIapProvider } from 'insert-affiliate-react-native-sdk';
36
- ```
37
-
38
- ## 1. Integrating the Provider in Your Application (`App.tsx`)
39
- ### Step 1: Wrap Your Application with the Iaptic Provider and Pass Context Properties
42
+ First, wrap your with our provider and call the `initialise` method early in your app's lifecycle:
40
43
 
41
- - Replace `{{ your_iaptic_app_id }}` with your **Iaptic App ID**. You can find this [here](https://www.iaptic.com/account).
42
- - Replace `{{ your_iaptic_app_name }}` with your **Iaptic App Name**. You can find this [here](https://www.iaptic.com/account).
43
- - Replace `{{ your_iaptic_public_key }}` with your **Iaptic Public Key**. You can find this [here](https://www.iaptic.com/settings).
44
+ ```javascript
45
+ const Child = () => {
46
+ const {
47
+ referrerLink,
48
+ subscriptions,
49
+ iapLoading,
50
+ handleBuySubscription,
51
+ userId,
52
+ userPurchase,
53
+ trackEvent,
54
+ initialize,
55
+ isInitialized,
56
+ } = useDeepLinkIapProvider();
44
57
 
45
- Here's the code with placeholders for you to swap out:
58
+ useEffect(() => {
59
+ initialize("{{ your-company-code }}");
60
+ }, [initialize, isInitialized]);
61
+
62
+ // ...
63
+
64
+ }
46
65
 
47
- ```javascript
48
66
  const App = () => {
49
67
  return (
50
68
  <DeepLinkIapProvider
51
- iapSkus={IAP_SKUS}
52
69
  iapticAppId="{{ your_iaptic_app_id }}"
53
70
  iapticAppName="{{ your_iaptic_app_name }}"
54
71
  iapticPublicKey="{{ your_iaptic_public_key }}">
@@ -57,63 +74,81 @@ const App = () => {
57
74
  );
58
75
  };
59
76
  ```
77
+ - Replace `{{ your_iaptic_app_id }}` with your **Iaptic App ID**. You can find this [here](https://www.iaptic.com/account).
78
+ - Replace `{{ your_iaptic_app_name }}` with your **Iaptic App Name**. You can find this [here](https://www.iaptic.com/account).
79
+ - Replace `{{ your_iaptic_public_key }}` with your **Iaptic Public Key**. You can find this [here](https://www.iaptic.com/settings).
80
+ - Replace `{{ your_company_code }}` with the unique company code associated with your Insert Affiliate account. You can find this code in your dashboard under [Settings](http://app.insertaffiliate.com/settings).
60
81
 
61
- ## 2. When the User Makes a Purchase, Call Our SDK's "handleBuySubscription"
62
- Here’s a complete example of how to use the SDK:
82
+ ## In-App Purchase Setup [Required]
83
+ Insert Affiliate requires a Receipt Verification platform to validate in-app purchases. You must choose **one** of our supported partners:
84
+ - [Iaptic](https://www.iaptic.com/account)
85
+ - [RevenueCat](https://www.revenuecat.com/)
63
86
 
64
- In the code below, please remember to update your IAP_SKUS with the comma separated list of your in app purchase SKU's.
87
+ ### Option 1: Iaptic Integration
88
+ First, complete the [Iaptic account setup](https://www.iaptic.com/signup) and code integration.
89
+
90
+ Then after setting up the in app purchase (IAP) with Iaptic, call Insert Affiliate's handlePurchaseValidation on purchase.
65
91
 
66
92
  ```javascript
67
93
  import React from 'react';
68
94
  import { ActivityIndicator, Button, StyleSheet, Text, View } from 'react-native';
69
95
  import { DeepLinkIapProvider, useDeepLinkIapProvider } from 'insert-affiliate-react-native-sdk';
96
+ import { useIAP, requestSubscription, withIAPContext, getProducts, getSubscriptions, initConnection } from "react-native-iap";
70
97
 
71
98
  const Child = () => {
72
- const {
73
- referrerLink,
74
- subscriptions,
75
- iapLoading,
76
- handleBuySubscription,
77
- userId,
78
- userPurchase,
79
- isIapticValidated,
80
- } = useDeepLinkIapProvider();
99
+ const {
100
+ initialize,
101
+ isInitialized,
102
+ handlePurchaseValidation,
103
+ } = useDeepLinkIapProvider();
81
104
 
82
- export const IAP_SKUS = Platform.select({
83
- android: [''], // Here, put a comma separated list of the In App Purchase SKU's
84
- ios: [''], // Here, put a comma separated list of the In App Purchase SKU's
85
- }) as string[];
105
+ const [iapLoading, setIapLoading] = useState(false);
106
+ const { currentPurchase, connected } = useIAP();
107
+
108
+ // ***...***
109
+ // Fetch & Load your subscription/purchases and handling the IAP purchase here as per the Iaptic Documentation...
110
+ // ***...***
111
+
112
+ // Initialize the Insert Affiliate SDK at the earliest possible moment
113
+ useEffect(() => {
114
+ if (!isInitialized) {
115
+ initialize("{{ your_company_code }}");
116
+ }
117
+ }, [initialize, isInitialized]);
86
118
 
87
119
 
88
- return (
89
- <View>
90
- {subscriptions.length ? (
91
- <Button
92
- disabled={iapLoading}
93
- title={
94
- userPurchase
95
- ? `Successfully Purchased`
96
- : `Click to Buy (${subscriptions[0].localizedPrice} / ${subscriptions[0].subscriptionPeriodUnitIOS})`
97
- }
98
- onPress={() => {
99
- if (iapLoading) return;
100
- if (!userPurchase) handleBuySubscription(subscriptions[0].productId); //
101
- }}
102
- />
103
- ) : null}
104
- {iapLoading && <ActivityIndicator size={'small'} color={'black'} />}
105
- </View>
106
- );
120
+ // Validate the purchase with Iaptic through Insert Affiliate's SDK for Affiliate Tracking
121
+ useEffect(() => {
122
+ if (currentPurchase) {
123
+ handlePurchaseValidation(currentPurchase).then((isValid: boolean) => {
124
+ if (isValid) {
125
+ console.log("Purchase validated successfully.");
126
+ } else {
127
+ console.error("Purchase validation failed.");
128
+ }
129
+ });
130
+ }
131
+ }, [currentPurchase, handlePurchaseValidation]);
132
+
133
+ return (
134
+ <View>
135
+ <Button
136
+ disabled={iapLoading}
137
+ title={`Click to Buy Subscription`}
138
+ onPress={() => handleBuySubscription("oneMonthSubscriptionTwo")}
139
+ />
140
+ {iapLoading && <ActivityIndicator size={"small"} color={"black"} />}
141
+ </View>
142
+ );
107
143
  };
108
144
 
109
145
  const App = () => {
110
146
  return (
111
147
  // Wrapped application code from the previous step...
112
148
  <DeepLinkIapProvider
113
- iapSkus={IAP_SKUS}
114
- iapticAppId="your_iaptic_app_id"
115
- iapticAppName="your_iaptic_app_name"
116
- iapticPublicKey="your_iaptic_public_key">
149
+ iapticAppId="{{ your_iaptic_app_id }}"
150
+ iapticAppName="{{ your_iaptic_app_name }}"
151
+ iapticPublicKey="{{ your_iaptic_public_key }}">
117
152
  <Child />
118
153
  </DeepLinkIapProvider>
119
154
  );
@@ -121,4 +156,140 @@ const App = () => {
121
156
 
122
157
  export default App;
123
158
  ```
159
+ - Replace `{{ your_iaptic_app_id }}` with your **Iaptic App ID**. You can find this [here](https://www.iaptic.com/account).
160
+ - Replace `{{ your_iaptic_app_name }}` with your **Iaptic App Name**. You can find this [here](https://www.iaptic.com/account).
161
+ - Replace `{{ your_iaptic_public_key }}` with your **Iaptic Public Key**. You can find this [here](https://www.iaptic.com/settings).
162
+ - Replace `{{ your_company_code }}` with the unique company code associated with your Insert Affiliate account. You can find this code in your dashboard under [Settings](http://app.insertaffiliate.com/settings).
163
+
164
+ ### Option 2: RevenueCat Integration
165
+ <!--#### 1. Code Setup-->
166
+ <!--First, complete the [RevenueCat SDK installation](https://www.revenuecat.com/docs/getting-started/installation/ios). Then modify your `AppDelegate.swift`:-->
167
+
168
+ COMING SOON...
169
+
170
+ ## Deep Link Setup [Required]
171
+
172
+ ### Step 1: Add the Deep Linking Platform Dependency
173
+
174
+ In this example, the deep linking functionality is implemented using [Branch.io](https://dashboard.branch.io/).
175
+
176
+ Any alternative deep linking platform can be used by passing the referring link to ```InsertAffiliateSwift.setInsertAffiliateIdentifier(referringLink: "{{ link }}")``` as in the below Branch.io example
177
+
178
+ After setting up your Branch integration, add the following code to your ```index.js```
179
+
180
+ <!--#### Example with RevenueCat-->
181
+ <!--```swift-->
182
+ <!--import SwiftUI-->
183
+ <!--import BranchSDK-->
184
+ <!--import InAppPurchaseLib-->
185
+ <!--import InsertAffiliateSwift-->
186
+
187
+ <!--class AppDelegate: UIResponder, UIApplicationDelegate {-->
188
+ <!-- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {-->
189
+ <!-- Branch.getInstance().initSession(launchOptions: launchOptions) { (params, error) in-->
190
+ <!-- if let referringLink = params?["~referring_link"] as? String {-->
191
+ <!-- InsertAffiliateSwift.setInsertAffiliateIdentifier(referringLink: referringLink) { result in-->
192
+ <!-- guard let shortCode = result else {-->
193
+ <!-- return-->
194
+ <!-- }-->
195
+
196
+ <!-- Purchases.shared.logIn(shortCode) { (customerInfo, created, error) in-->
197
+ <!-- // customerInfo updated for my_app_user_id. If you are having issues, you can investigate here.-->
198
+ <!-- }-->
199
+ <!-- }-->
200
+ <!-- }-->
201
+ <!-- return true-->
202
+ <!-- }-->
203
+ <!--}-->
204
+ <!--```-->
205
+
206
+ #### Example with Iaptic
207
+ ```swift
208
+ import branch from 'react-native-branch';
209
+ import { DeepLinkIapProvider, useDeepLinkIapProvider } from 'insert-affiliate-react-native-sdk';
210
+
211
+ branch.subscribe(async ({ error, params }) => {
212
+ if (error) {
213
+ console.error('Error from Branch: ' + error);
214
+ return;
215
+ }
216
+
217
+ if (params['+clicked_branch_link']) {
218
+ if (params["~referring_link"]) {
219
+ setInsertAffiliateIdentifier(params["~referring_link"], (shortLink) => {
220
+ console.log("Insert Affiliate - setInsertAffiliateIdentifier: ", params["~referring_link"], " - Stored shortLink ", shortLink);
221
+ });
222
+ }
223
+ }
224
+ });
225
+
226
+ ```
227
+
228
+ ## Additional Features
229
+
230
+ ### 1. Event Tracking (Beta)
231
+
232
+ The **InsertAffiliateReactNative SDK** now includes a beta feature for event tracking. Use event tracking to log key user actions such as signups, purchases, or referrals. This is useful for:
233
+ - Understanding user behaviour.
234
+ - Measuring the effectiveness of marketing campaigns.
235
+ - Incentivising affiliates for designated actions being taken by the end users, rather than just in app purchases (i.e. pay an affilaite for each signup).
236
+
237
+ At this stage, we cannot guarantee that this feature is fully resistant to tampering or manipulation.
238
+
239
+ #### Using `trackEvent`
124
240
 
241
+ To track an event, use the `trackEvent` function. Make sure to set an affiliate identifier first; otherwise, event tracking won’t work. Here’s an example:
242
+
243
+ ```javascript
244
+ const {
245
+ referrerLink,
246
+ subscriptions,
247
+ iapLoading,
248
+ handleBuySubscription,
249
+ userId,
250
+ userPurchase,
251
+ trackEvent, // Required for trackEvent
252
+ } = useDeepLinkIapProvider();
253
+
254
+ <Button
255
+ title={'track event'}
256
+ onPress={() => {
257
+ trackEvent('event_name')
258
+ .then(() => console.log('Event tracked successfully!'))
259
+ }}
260
+ />
261
+ ```
262
+
263
+ ### 2. Short Codes (Beta)
264
+
265
+ #### What are Short Codes?
266
+
267
+ Short codes are unique, 10-character alphanumeric identifiers that affiliates can use to promote products or subscriptions. These codes are ideal for influencers or partners, making them easier to share than long URLs.
268
+
269
+ **Example Use Case**: An influencer promotes a subscription with the short code "JOIN12345" within their TikTok video's description. When users enter this code within your app during sign-up or before purchase, the app tracks the subscription back to the influencer for commission payouts.
270
+
271
+ For more information, visit the [Insert Affiliate Short Codes Documentation](https://docs.insertaffiliate.com/short-codes).
272
+
273
+ #### Setting a Short Code
274
+
275
+ Use the `setShortCode` method to associate a short code with an affiliate. This is ideal for scenarios where users enter the code via an input field, pop-up, or similar UI element.
276
+
277
+ Short codes must meet the following criteria:
278
+ - Exactly **10 characters long**.
279
+ - Contain only **letters and numbers** (alphanumeric characters).
280
+ - Replace {{ user_entered_short_code }} with the short code the user enters through your chosen input method, i.e. an input field / pop up element
281
+
282
+ ```javascript
283
+ import {
284
+ DeepLinkIapProvider,
285
+ } from 'insert-affiliate-react-native-sdk';
286
+
287
+ const {
288
+ setShortCode,
289
+ } = useDeepLinkIapProvider();
290
+
291
+ <Button
292
+ title={'Set Short Code'}
293
+ onPress={() => setShortCode('JOIN123456')}
294
+ />
295
+ ```