Skip to main content

Initialization

Start New Session

In order to set up the Pricing Optimization SDK, first you should use the sessionStart() method to initialize internal SDK structures.

This method accepts the following parameters:

To initiate the wappier Optimization SDK, create a new Application class or update the existing one and add the following line at the onCreate() method of that class:

Wappier.getInstance()
.startSession(this, apiKey, new Locale("en"), userName, flatBuffer, kvpMap, billingLocalePrice);
  • As a userName argument you should pass your unique and constant user indentifier, which can be used to share loyalty user status across devices. In case you don’t have that type of user identifier you can pass a null value.

  • As a kvpMap argument you can pass a map of one or multiple Key-Value pairs to be added to this user. In case you don’t want to, you can pass a null value.

  • As a flatBuffer argument you can pass the option to handle the API response in flat buffer or json format by setting this boolean parameter from the dataview calls only. So if the loyalty tactics will be drawn from the main app, you need to pass this parameter to specify the type of the dataview responses. If the Loyalty UI will be drawn from the SDK this parameter can be ignored.

    • If you pass true, you will receive the responses in Flatbuffer_JSON format.

    • If you pass false, you will receive the responses in JSON format.

  • As billingLocalePrice you can pass an int param, that is the priceInMicros of the special SKU, if any. In case that you don’t have this value, you can pass 0.

An example of getting the price in micros of an SKU is displayed below. (Implementation varies, depending of the language, java/kotlin and the billing library version)

val sku: MutableList<String> = mutableListOf()
sku.add(specialSKU)
billingManager.querySkuDetailsAsync(sku) { _: BillingResult?, list: List<SkuDetails?>? ->
if (list!!.isNotEmpty()){
Log.d("BillingLocaleFragment", "SKU priceAmountMicros: " + list[0]?.priceAmountMicros)
}
}
localization
  • You have to pass the selected language to sdk using new Locale() in lowercase. That method accepts inputs as language based on ISO 639. If you pass null instead of valid Locale the sdk will detect the current language of the device.

  • The Loyalty User Profile Language should be the same as the application’s. So please pass the value as new Locale with the language of your app.

  • In case your application supports language change from the in-app settings page, please call the above method with the new language when the end-users change the app language.

  • In case your application language is based on the device language you may pass the build.language value as new Locale.

The wappier Optimization SDK provides you callbacks that inform you about the state of sdk initialization. The rest of the SDK methods should be called, after successful SDK initialization.

For example if startSession has completed successfully you can show the loyIcon to your user:

StartListener startListener = new StartListener() {
@Override
public void onSessionStarted() {
mCustomButton.showLoyIcon("Activity1");
}

@Override
public void onStartSessionError() {

}
};

Don’t forget to register and unregister the Listener:

 protected void onStart() {
super.onStart();
Wappier.getInstance().setStartListener(startListener);
}

@Override
protected void onStop() {
super.onStop();
Wappier.getInstance().removeStartListener();
}