Initialization
Start New Session
In order to set up the wappier Optimization SDK, first you should use the sessionStart()
method to initialize internal SDK structures.
This method accepts the following parameters:
- Android(Java)
- iOS(obj-C)
- Unity
- C++
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)
}
}
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();
}
[WappierSDK startSessionWithApiKey:@"YOUR_API_KEY"
username:@"YOUR_USER_NAME"
locale:@"uiLocale"
attributes:@{@"attribute1":@"value1"}
flatbuffer:NO
andCompletion:^(BOOL result){
//do something with the result
}
];
You should pass your unique and constant user identifier, which can be used to share loyalty user status across devices. In case you don’t have that type of user identifier please remove the setUserName method.
You can link multiple devices to a single Loyalty User Profile by setting as username your unique user identifier.
You have to pass the selected language to sdk using
uiLocale
in lowercase. If you pass null instead of valid Locale the sdk will detect the current language of the device.They Loyalty User Profile Language should be same as the application. So please pass the value as new Locale 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
Leaving the locale as null will default to using the device language locale setting.
In order to change username, you need to make a new
startSessionWithApiKey
call.You can register a block to get a callback when the startSession is completed (andCompletion:true). The rest SDK methods should be called, after successful SDK initialization.
You can additionally pass a Dictionary of user attributes (e.g., gender)
Dictionary<string, string> attributes = new Dictionary<string, string>()
{
{"KVP", "true"}
};
Wappier.Instance.StartSession(APP_KEY, "userName", "en_US", attributes, flag =>
{
//do something with a boolean flag
}, responseFormat, billingLocalePrice);
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,please pass null as "userName" in the startSession method.
You have to pass the selected language to sdk using
uiLocale
in lowercase. If you pass null instead of valid Locale the sdk will detect the current language of the device.They Loyalty User Profile Language should be same as the application. So please pass the value as new Locale 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.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.
(Android only) As
billingLocalePrice
you can pass an integer, that is thepriceInMicros
of the special SKU, if any. In case that you don’t have this value, you can ignore it.
To initiate the wappier Optimization SDK, call startSession
:
//For iOS
WappierSDKWrapper::getInstance()->startSession(APP_KEY, userName, locale, attributes, billingLocalePrice, [](bool sessionStarted){
//do something with a boolean flag
}, WPResponseFormat);
You can link multiple devices to a single Loyalty User Profile by setting as userName your unique user identifier.
You can leave null to use the device locale.
You can pass a std::map<const char, const char> of additional attributes.
You can pass an Integer to
billingLocalePrice
. For Android this is the priceInMicros of the special SKU. You should pass 0 tobillingLocalePrice
for iOS.You can pass an enum of type
WPResponseFormat
to handle API response in flatbuffer (FBS_JSON
) or json format(JSON
). This parameter is related to 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
FBS_JSON
, you will receive the responses in Flatbuffer_JSON format.If you pass
JSON
, you will receive the responses in JSON format.You can pass a delegate parameter to get a callback when the session start has been completed.
Before calling startSession
, you should first set the JAVA VM by calling:
WPAndroidHelper::getInstance()->setJavaVM(jvm);
where jvm is the JavaVM pointer you have as a parameter in your JNI_OnLoad
function.