insert_affiliate_flutter_sdk 1.0.2
insert_affiliate_flutter_sdk: ^1.0.2 copied to clipboard
A Flutter SDK for integrating affiliate tracking and in-app purchases for the Insert Affiliate Platform.
Insert Affiliate Flutter SDK #
Overview #
The Insert Affiliate Flutter SDK is designed for Flutter applications, providing seamless integration with the Insert Affiliate platform.The Insert Affiliate Flutter SDK simplifies affiliate marketing for iOS apps with in-app-purchases, allowing developers to create a seamless user experience for affiliate tracking and monetisation.
Features #
- Unique Device ID: Creates a unique ID to anonymously associate purchases with users for tracking purposes.
- Affiliate Identifier Management: Set and retrieve the affiliate identifier based on user-specific links.
- In-App Purchase (IAP) Initialisation: Easily reinitialise in-app purchases with the option to validate using an affiliate identifier.
Getting Started #
To get started with the Insert Affiliate Flutter SDK:
- Install the SDK via pubspec.yaml
- Initialise the SDK in your Main Dart File
- Set up in-app purchases (Required)
Installation #
Include the following dependencies in your pubspec.yaml file:
dependencies:
flutter:
sdk: flutter
insert_affiliate_flutter_sdk: <latest_version>
shared_preferences: <latest_version>
http: <latest_version>
Run $ flutter pub get
in your terminal from the project root to fetch the required packages.
Basic Usage #
Import the SDKs #
Import the SDK in your Main Dart file:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:insert_affiliate_flutter_sdk/insert_affiliate_flutter_sdk.dart';
Initialisation in Main.dart #
To ensure proper initialisation of the Insert Affiliate Flutter SDK, you should initialise the InsertAffiliateFlutterSDK early in your app's lifecycle, typically within Main.dart
.
import 'package:insert_affiliate_flutter_sdk/insert_affiliate_flutter_sdk.dart';
late final InsertAffiliateFlutterSDK insertAffiliateSdk;
void main() async {
// Ensure Flutter is initialized before running any async code
WidgetsFlutterBinding.ensureInitialized();
// Initialise Insert Affiliate SDK
insertAffiliateSdk = InsertAffiliateFlutterSDK(
companyCode: "{{ your_company_code }}",
);
runApp(MyApp());
}
- 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.
In-App Purchase Setup [Required] #
Insert Affiliate requires a Receipt Verification platform to validate in-app purchases. You must choose one of our supported partners:
Option 1: RevenueCat Integration #
COMING SOON
Option 2: Iaptic Integration #
First, complete the In App Purchase Flutter Library setup. Then modify your main.dart
file:
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:insert_affiliate_flutter_sdk/insert_affiliate_flutter_sdk.dart';
late final InsertAffiliateFlutterSDK insertAffiliateSdk;
class _MyAppState extends State<MyApp> {
final InAppPurchase _iap = InAppPurchase.instance;
@override
void initState() {
super.initState();
_purchaseStream.listen((List<PurchaseDetails> purchaseDetailsList) {
_listenToPurchaseUpdated(purchaseDetailsList);
});
}
void _listenToPurchaseUpdated(List<PurchaseDetails> purchaseDetailsList) async {
for (var purchaseDetails in purchaseDetailsList) {
if (purchaseDetails.status == PurchaseStatus.purchased) {
final jsonIapPurchase = {
'transactionReceipt': purchaseDetails.verificationData.localVerificationData,
'orderId': purchaseDetails.purchaseID,
'purchaseToken': purchaseDetails.verificationData.serverVerificationData,
'signature': purchaseDetails.verificationData.localVerificationData,
'applicationUsername': await insertAffiliateSdk.returnInsertAffiliateIdentifier(),
};
final isValid = await insertAffiliateSdk.validatePurchaseWithIapticAPI(
jsonIapPurchase,
"{{ your_iaptic_app_id }}",
"{{ your_iaptic_app_name }}",
"{{ your_iaptic_public_key }}"
);
// Optional: Handle the result of `isValid` if needed
}
}
}
}
Replace the following:
{{ your_iaptic_app_id }}
with your Iaptic App ID{{ your_iaptic_app_name }}
with your Iaptic App Name{{ your_iaptic_public_key }}
with your Iaptic Public Key
Deep Link Setup [Required] #
Step 1: Add the Deep Linking Platform Dependency #
In this example, the deep linking functionality is implemented using Branch.io.
Any alternative deep linking platform can be used by passing the referring link to insertAffiliateSdk.setInsertAffiliateIdentifier(data["~referring_link"]);
as in the below Branch.io example
Step 2: Modify Your Deep Link listSession Listener function in Main.dart
#
After setting up your Branch integration, add the following code to initialise the Insert Affiliate Flutter SDK.
import 'package:flutter_branch_sdk/flutter_branch_sdk.dart';
import 'package:insert_affiliate_flutter_sdk/insert_affiliate_flutter_sdk.dart';
late final InsertAffiliateFlutterSDK insertAffiliateSdk;
class _MyAppState extends State<MyApp> {
late StreamSubscription<Map> _branchStreamSubscription;
@override
void initState() {
super.initState();
_branchStreamSubscription = FlutterBranchSdk.listSession().listen((data) {
if (data.containsKey("+clicked_branch_link") && data["+clicked_branch_link"] == true) {
insertAffiliateSdk.storeInsertAffiliateIdentifier(data["~referring_link"]);
}
}, onError: (error) {
print('Branch session error: ${error.toString()}');
});
}
}
Additional Features #
1. Event Tracking (Beta) #
The InsertAffiliateFlutter 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:§
- Understanding user behaviour.
- Measuring the effectiveness of marketing campaigns.
- 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).
At this stage, we cannot guarantee that this feature is fully resistant to tampering or manipulation.
Using trackEvent
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:
import 'package:insert_affiliate_flutter_sdk/insert_affiliate_flutter_sdk.dart';
ElevatedButton(
onPressed: () {
insertAffiliateSdk.trackEvent(eventName: "yourEventIdentifier")
.then((_) => print('Event tracked successfully!'))
.catchError((error) => print('Error tracking event: $error'));
},
child: Text("Track Test Event"),
);
2. Short Codes (Beta) #
What are Short Codes? #
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.
Example Use Case: An influencer promotes a subscription with the short code "JOIN123456" 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.
For more information, visit the Insert Affiliate Short Codes Documentation.
late final InsertAffiliateFlutterSDK insertAffiliateSdk;
insertAffiliateSdk.setShortCode("B2SC6VRSKQ")
Example Integration
Below is an example SwiftUI implementation where users can enter a short code, which will be validated and associated with the affiliate's account:
late final InsertAffiliateFlutterSDK insertAffiliateSdk;
ElevatedButton(
onPressed: () => insertAffiliateSdk.setShortCode("B2SC6VRSKQ"),
child: Text("Set Short Code"),
)
Example Usage
Set the Affiliate Identifier (required for tracking):
InsertAffiliateSwift.setInsertAffiliateIdentifier(referringLink: "your_affiliate_link")