Skip to content

Latest commit

 

History

History
256 lines (177 loc) · 6.69 KB

README.md

File metadata and controls

256 lines (177 loc) · 6.69 KB

singular_flutter_kids_sdk

A Flutter plugin for Singular Kids SDK.


Table of content


Supported Platforms

  • Android
  • iOS

This plugin is built for

  • iOS SingularSDK v12.6.0

  • Android SingularSDK v12.6.0


You can add Singular Plugin to your Flutter app by adding following to your pubspec.yaml file:

dependencies:
  singular_flutter_kids_sdk: ^1.5.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_kids_sdk/singular.dart';
import 'package:singular_flutter_kids_sdk/singular_config.dart';

SingularConfig config = new SingularConfig('API_KEY', 'API_SECRET');
config.customUserId = "test@test.com";
Singular.start(config);

You can send events to Singular using the event and eventWithArgs methods.

Example:

Singular.event(eventName);

Singular.eventWithArgs(eventName, {"level-up":"5"});

Report a custom event to Singular

Example:

Singular.customRevenue("MyCustomRevenue", "USD", 5.50);

Report an IAP event to Singular

Example:

import 'package:singular_flutter_kids_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);

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;
    Map urlParameters = params.urlParameters;
    // Add your code here to handle the deep link
});
Singular.init(config);

iOS Prerequisites

Objective-C:

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;

  }

Swift:

import singular_flutter_kids_sdk

override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    if let singularAppDelegate = SingularAppDelegate.shared() {
        singularAppDelegate.launchOptions = launchOptions
    }
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
    
override func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if let singularAppDelegate = SingularAppDelegate.shared() {
        singularAppDelegate.continueUserActivity(userActivity, restorationHandler: nil)
    }
   return true
}
    
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    if let singularAppDelegate = SingularAppDelegate.shared() {
        singularAppDelegate.handleOpen(url, options: options)
    }
   return true
}
    

Android Prerequisites

Java:

In the project’s MainActivity.java, add the following:

import com.singular.flutter_kids_sdk.SingularBridge;

@Override
protected void onNewIntent(@NonNull Intent intent) {
  super.onNewIntent(intent);
  SingularBridge.onNewIntent(intent);
}

Kotlin:

import com.singular.flutter_kids_sdk.SingularBridge;

override fun onNewIntent(intent: Intent) {
  super.onNewIntent(intent)
  SingularBridge.onNewIntent(intent);
}

Starting with version 1.0.15 of the Singular Flutter SDK, skAdNetworkEnabled is enabled by default. To manually 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());
});

Send Singular the APNS/FCM token in order to let it track app uninstalls.

Example:

//iOS
  Singular.registerDeviceTokenForUninstall(apnsToken);

//Android
  Singular.registerDeviceTokenForUninstall(fcmToken);