Initialize the SDK

You must initialize the adjoe SDK before you can use any of its features. To do this, call Adjoe.init(_sdkHash) when your app is starting.

The init method will return a Future<void> which succeeds when the SDK has been initialized successfully and fails with an error when the initialization fails.

After one successful initialization all following calls to Adjoe.Init the returned Future will immediately succeed until your app is removed from the heap.

Best practices for the SDK initialization:

  • Initialize early: You should initialize the SDK as soon as possible after your app starts to make sure that all adjoe features are available when you want to use them.

  • Initialize after your app authentication: You should initialize the SDK (again) with up-to-date details as soon as your user has signed up/signed in to the app so to update the userId.

  • Initialize regularly: For the best user experience, we highly recommend to call this method every time your app comes to the foreground. This should not be noticeable in your app's performance.

  • Initialization triggers: Good places to call this method are the app start and in the didChangeAppLifecycleState method.

Example

import 'package:adjoe/adjoe.dart';
import 'package:adjoe/gender.dart';
import 'package:adjoe/options.dart';
import 'package:adjoe/params.dart';
import 'package:adjoe/user_profile.dart';

void initializeAdjoe() {
  Adjoe.init(sdkHash, options).then((_) {
    print('Init finished successful');
  }, onError: (err) {
    print('Init failed: $err');
  });
}

The parameters to this call are as follows:

  • String sdkHash: Your adjoe SDK hash.

  • AdjoeOptions options: An object to pass additional options to the adjoe SDK when initializing. This parameter is optional and you can call Adjoe.init(String) instead.

You can create an AdjoeOptions object in the following way:

AdjoeOptions options = new AdjoeOptions()
  ..userId = 'user_id'
  ..applicationProcessName = 'io.adjoe.FlutterTestApp'
  ..params = (new AdjoeParams()
    ..uaNetwork = 'The user acquisition network'
    ..uaChannel = 'The user acquisition channel.'
    ..uaSubPublisherCleartext = 'The user acquisition publisher cleartext'
    ..uaSubPublisherEncrypted = 'The user acquisition publisher encrypted'
    ..placement = 'The offerwall placement')
  ..userProfile = (new AdjoeUserProfile()
    ..birthday = birthday
    ..gender = gender)
  ..extensions = (new AdjoeExtensions()
    ..subId1 = 'flutter_subId1'
    ..subId2 = 'flutter_subId2'
    ..subId3 = 'flutter_subId3'
    ..subId4 = 'flutter_subId4'  
    ..subId5 = 'flutter_subId5');
  • String userId: A custom identifier that you wish to assign to this user. If you don't have an identifier for your user already, the adjoe SDK will generate one. You can then access it by calling Adjoe.getUserId(Context). Only this ID will allow you to match the payouts to your users in the process of Server-to-server payout.

  • String applicationProcessName: A custom identifier that you will need to set if you manually set/change the android.process for the application tag in the AndroidManifest.xml.

  • AdjoeParams params: With this you can pass additional UA and placement parameters when you initialize the SDK.

  • AdjoeUserProfile userProfile: This class holds the user's birthday and gender information for the App. adjoe utilizes this data to create targeted advertising campaigns that align with the user's preferences and characteristics.

  • AdjoeExtensions extensions: This object contains additional optional five string identifiers that i.e would have a meaning in your system and they will be provided back in the Server-to-server payout.

If you want to use S2S payout, you have to set the user id in order to match the payout to your user.

The IsInitialized method

To check whether the SDK is initialized you can call Adjoe.isInitialized(). This will return true if the SDK is initialized and false otherwise. However, you should not condition calling init on the result of isInitialized because the SDK will do some checks on its own. You should not do something like the following as it can lead to bad user experience:

void initializeAdjoe() {
    if (!Adjoe.isInitialized()) {
        Adjoe.init(sdkHash, options);
    }
}

Instead, just call init without checking for isInitialized. You can however use isInitialized e.g. for debugging or to check whether the SDK is initialized before calling other methods of the SDK like requestRewards.