Initialization
In order to access the functionalities of the AppsPrize Playtime SDK, it is necessary to perform an initialization process. To achieve this, simply make a call to Application class initialize(Context,AppsPrizeConfig,AppsPrizeListener)
The initialization will occur asynchronously in the main application process, running in the background. Upon completion, you will be notified through the AppsPrizeListener
's onInitialize
or onInitializedFailed
method, depending on the outcome.
public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
AppsPrizeConfig config = new AppsPrizeConfig.Builder()
.build(APPS_PRIZE_APP_TOKEN, ADVERTISING_ID, USER_ID);
AppsPrize.initialize(getApplicationContext(), config, new AppsPrizeListener() {
@Override
public void onInitialize() {
Log.d("[AppsPrize]", "MainApplication:onCreate AppsPrize:onInitialize");
}
@Override
public void onInitializeFailed(@NonNull String errorMessage) {
Log.d("[AppsPrize]", "MainApplication:onCreate AppsPrize:onInitializeFailed: err: " + errorMessage);
}
@Override
public void onRewardUpdate(@NonNull List<AppReward> rewards) {
Log.d("[AppsPrize]", "MainApplication:onCreate AppsPrize:onRewardUpdate: " + rewards);
}
@Override
public void onNotification(@NonNull List<AppsPrizeNotification> notifications) {
Log.d("[AppsPrize]", "MainApplication:onCreate AppsPrize:onNotification: " + notifications);
}
});
}
}
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
val config = AppsPrizeConfig.Builder()
.build(APPS_PRIZE_APP_TOKEN, ADVERTISING_ID, USER_ID)
AppsPrize.initialize(applicationContext, config, object : AppsPrizeListener {
override fun onInitialize() {
Log.d("[AppsPrize]", "MainApplication:onCreate AppsPrize:onInitialize")
}
override fun onInitializeFailed(errorMessage: String) {
Log.d("[AppsPrize]", "MainApplication:onCreate AppsPrize:onInitializeFailed: err: $errorMessage")
}
override fun onRewardUpdate(rewards: List<AppReward>) {
Log.d("[AppsPrize]", "MainApplication:onCreate AppsPrize:onRewardUpdate: $rewards")
}
override fun onNotification(notifications: List<AppsPrizeNotification>) {
Log.d("[AppsPrize]", "MainApplication:onCreate AppsPrize:onNotification: $notifications")
}
})
}
}
The parameters to this call are as follows:
- Context: Your application's
context
. - AppsPrizeConfig: An object to pass additional options to the AppsPrize SDK when initializing. This parameter is a must and you can call
initialize(Context, AppsPrizeConfig)
orinitialize(Context, AppsPrizeConfig, AppsPrizeListener)
instead. - AppsPrizeListener: A listener which informs you about whether the AppsPrize Playtime SDK was initialized successfully or not. This parameter is optional and you can call
initialize(Context,AppsPrizeConfig)
orinitialize(Context, AppsPrizeConfig, AppsPrizeConfig)
instead.
You can create an AppsPrizeConfig
object in the following way:
AppsPrizeConfig
data class AppsPrizeConfig
This class holds the configuration information of AppsPrize
Functions
- Build
fun build(token: String, advertisingId: String, userId: String): AppsPrizeConfig
This function builds AppsPrizeConfig with the current properties
Return
AppsPrizeConfig instance
Parameters
token: AppsPrize token provided once you sign up and add your app to dashboard (https://dashboard.appsprize.com).
advertisingId: Google advertising id from device.
userId: App unique user ID
setCountry/setLanguage
val config = AppsPrizeConfig.Builder()
.setCountry("ES")
.setLanguage("es")
Device-locale is used for country and language default. We need to get these functions from the app in order to target offers according to end user location.
User Profile
In order to target your users better and show relevant offers to them, it's crucial to collect User Profile. We collect Gender, Age, UA Channel, UA Network and Ad Placement for segmentation.
Gender
setGender(gender: String?)
This function allows to set user gender information for targeting.
Age
setAge(age: Int?)
This function allows to set user age information for targeting.
UA Channel
setUaChannel(uaChannel: String?)
This function allows to set UA Channel.
UA Network
setUaNetwork(uaNetwork: String?)
This function allows to set UA Network.
Ad Placement
setAdPlacement(adPlacement: String?)
This function allows to set AD Placement.
And for the AppsPrizeListener
;
AppsPrizeListener
interface AppsPrizeListener
This interface represents AppsPrizeListener
which notifies applications when an event occurs about AppsPrize.
Functions
- onInitialize
open fun onInitialize()
This function will let you know that AppsPrize initialization is completed.
- onInitializedFailed
open fun onInitializeFailed(errorMessage: String)
This function will let you know that AppsPrize initialization has failed to complete.
You need to listen to
onInitializedFailed
once the user opens your app and not show the AppsPrize for these users. This event will be coming under the following conditions:
- Data load failed
- Network fail
- Corrupted data- App token not found
- Wrong region/country
Parameters
errorMessage: Error message of the load fail reason.
- onRewardUpdate
open fun onRewardUpdate(rewards: List<AppReward>)
This function will let you know that the user has completed one or multiple rewards in a session.
Parameters
rewards: List of rewards earned by user.
-
onNotification
open fun onNotification(notifications: List<AppsPrizeNotification>)
This function will let you know that the user's current notifications such as getting rewards, notify to open the SDK, etc.
Parameters
notifications: List of current notifications.
Updated 8 days ago