singular_flutter_sdk 1.0.1 singular_flutter_sdk: ^1.0.1 copied to clipboard
A Flutter plugin for Singular SDK.
singular_flutter_sdk #
A Flutter plugin for Singular SDK.
Table of content #
- Basic Integration
- Tracking Events
- Tracking Revenues
- Implementing Deeplinks
- Adding SKAdNetwork Support
- Tracking Uninstalls
Supported Platforms #
- Android
- iOS
This plugin is built for #
-
iOS SingularSDK v11.0.2
-
Android SingularSDK v12.0.0
Basic Integration #
You can add Singular Plugin to your Flutter app by adding following to your pubspec.yaml
file:
dependencies:
singular_flutter_sdk: ^1.0.1
Then navigate to your project in the terminal and run:
flutter packages get
Before you initialize the Singular SDK, you have to create a SingularConfig object. The object contains your API key and API secret for the Singular SDK. Optionally, you can add settings to enable various SDK features.
Example:
import 'package:singular_flutter_sdk/singular.dart';
import 'package:singular_flutter_sdk/singular_config.dart';
SingularConfig config = new SingularConfig('API_KEY', 'API_SECRET');
config.customUserId = "test@test.com";
Singular.start(config);
Tracking Events #
You can send events to Singular using the event and eventWithArgs methods.
Example:
Singular.event(eventName);
Singular.eventWithArgs(eventName, {"level-up":"5"});
Tracking Revenues #
Report a custom event to Singular
Example:
Singular.customRevenue("MyCustomRevenue", "USD", 5.50);
Report an IAP event to Singular
Example:
import 'package:singular_flutter_sdk/singular_iap.dart';
singularPurchase = new SingularIOSIAP(
product.price,
product.currencyCode,
purchase.productId,
purchase.purchaseId,
purchase.verificationData.serverVerificationData
);
singularPurchase = new SingularAndroidIAP(
product.price,
product.currencyCode,
purchase.singature,
purchase.verificationData.serverVerificationData
);
Singular.inAppPurchase(eventName, singularPurchase);
Implementing Deeplinks #
To enable Singular Links in iOS and in Android, see Singular Links Prerequisites.
Handling Singular Links
The Singular SDK provides a handler mechanism to read the details of the tracking link that led to the app being opened.
Example:
SingularConfig config = new SingularConfig('API_KEY', 'API_SECRET');
config.singularLinksHandler = (SingularLinkParams params) {
String deeplink = params.deeplink;
String passthrough = params.passthrough;
bool isDeferred = params.isDeferred;
// Add your code here to handle the deep link
});
Singular.init(config);
iOS Prerequisites
In the project’s AppDelegate.m, add the following:
// Top of the AppDelegate.m
#import "SingularAppDelegate.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
[SingularAppDelegate shared].launchOptions = launchOptions;
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *restorableObjects))restorationHandler {
[[SingularAppDelegate shared] continueUserActivity:userActivity restorationHandler:restorationHandler];
return YES;
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
[[SingularAppDelegate shared] handleOpenUrl:url options:options];
return YES;
}
Android Prerequisites
In the project’s MainActivity.java, add the following:
import com.singular.flutter_sdk.SingularBridge;
@Override
protected void onNewIntent(@NonNull Intent intent) {
super.onNewIntent(intent);
SingularBridge.onNewIntent(intent);
}
Adding SKAdNetwork Support #
To enable SKAdNetwork tracking for your app, turn on the skAdNetworkEnabled configuration option before initializing Singular:
Example:
SingularConfig config = new SingularConfig('API_KEY', 'API_SECRET');
config.skAdNetworkEnabled = true;
config.manualSkanConversionManagement = true; // Enable manual conversion value updates
config.conversionValueUpdatedCallback = (int conversionValue) {
print('Received conversionValueUpdatedCallback: ' + conversionValue.toString());
};
Singular.init(config);
Retrieving the Conversion Value
Singular.skanGetConversionValue().then((conversionValue) {
print('conversion value: ' + conversionValue.toString());
});
Tracking Uninstalls #
Send Singular the APNS/FCM token in order to let it track app uninstalls.
Example:
//iOS
Singular.registerDeviceTokenForUninstall(apnsToken);
//Android
Singular.registerDeviceTokenForUninstall(fcmToken);