Before you can use any of the Playtime SDK's functionality you have to initialize it. Initialization runs asynchronously in the background on the main application process, and you are told the outcome through a callback.

Call initialize(Context,AppsPrizeConfig,AppsPrizeListener) from your Application class. When it finishes you are notified through the AppsPrizeListener, via either onInitialize or onInitializedFailed, depending on the result.

Java
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);
            }
        });
    }
}
Kotlin
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 are:

  • 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) or initialize(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) or initialize(Context, AppsPrizeConfig, AppsPrizeConfig) instead.

AppsPrizeConfig

Kotlin
data class AppsPrizeConfig

This class holds the configuration information of AppsPrize.

build

Kotlin
fun build(token: String, advertisingId: String, userId: String): AppsPrizeConfig

Builds an AppsPrizeConfig from the current properties and returns the instance.

  • token: AppsPrize token provided once you sign up and add your app to dashboard (dashboard.appsprize.com).
  • advertisingId: Google advertising id from device.
  • userId: App unique user ID

setCountry and setLanguage

Kotlin
 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

Collecting a user profile matters, because it is how offers get targeted to the right people. We use gender, age, UA channel, UA network and ad placement for segmentation.

Gender

Kotlin
setGender(gender: String?)

Age

Kotlin
setAge(age: Int?)

UA Channel

Kotlin
setUaChannel(uaChannel: String?)

UA Network

Kotlin
setUaNetwork(uaNetwork: String?)

Ad Placement

Kotlin
setAdPlacement(adPlacement: String?)

AppsPrizeListener

Kotlin
interface AppsPrizeListener

This interface notifies your application when an AppsPrize event occurs.

onInitialize

Kotlin
open fun onInitialize()

Tells you that AppsPrize initialization completed.

onInitializedFailed

Kotlin
open fun onInitializeFailed(errorMessage: String)

Tells you that AppsPrize initialization failed to complete. errorMessage carries the reason for the failure.

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

onRewardUpdate

Kotlin
open fun onRewardUpdate(rewards: List<AppReward>)

Tells you the user completed one or more rewards in a session. rewards is the list of rewards they earned.

onNotification

Kotlin
open fun onNotification(notifications: List<AppsPrizeNotification>)

Tells you about the user's current notifications, such as receiving rewards or a prompt to open the SDK. notifications is the list of current notifications.

Call AppsPrize.init(Config) as your app starts. When it finishes you are notified through AppsPrize.init's onInitialize or onInitializedFailed, depending on the result.

onRewardUpdate tells you that the user has completed one or multiple rewards in a session.

Please make sure that "userId" and "token" have not an empty value. Also, "country" and "language" should be defined for country targeting. We need to get device locale into the SDK in order to fill the feed with relevant offers.

JavaScript
const appsPrizeConfig: AppsPrizeConfig = {
    /// The token used for authentication.
    token: "token";

    // The advertising identifier used for tracking.
    advertisingId: "adId";

    // The user identifier.
    userId: "userId";

    // The country associated with the user.
    country: "UK";

    // The language preference of the user.
    language: "en";
  
    //User Profile for better targeting.
    gender: "gender",
    age: 30,
    uaChannel: "uaChannel",
    uaNetwork: "uaNetwork",
    adPlacement: "adPlacement",

    // (Optional) The styling configuration for UI customization.
    style: AppsPrizeStyleConfig;
}
JavaScript
AppsPrize.init(config, {
  onInitialize: (event) => {
    console.log("AppsPrize:TS:onInitialize")
  },
  onInitializeFailed: (event) => {
    console.log(`AppsPrize:TS:onInitializeFailed:${JSON.stringify(event)}`)
  },
  onRewardUpdate: (event) => {
    console.log(`AppsPrize:TS:onRewardUpdate:${JSON.stringify(event)}`)
  },
  onNotification: (event) => {
    console.log(`AppsPrize:TS:onNotification:${JSON.stringify(event)}`)
  },
})

The config object takes these parameters:

  • String token: The SDK token that you can take it from the dashboard once you add your app.
  • String userId: A custom user identifier that you give to your users. With the help of this ID, we will match the payouts to your users and inform you by server-to-server payout method.

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

Call AppsPrize.Initialize as your app starts. When it finishes you are notified through AppsPrize.Initialize's OnInitialize or OnInitializedFailed, depending on the result.

OnRewardUpdate tells you that the user has completed one or multiple rewards in a session.

Please make sure that "userId" and "token" have not an empty value. Also, "country" and "language" should be defined for country targeting. We need to get device locale into the SDK in order to fill the feed with relevant offers.

C#
new AppsPrizeConfig(
        token: TOKEN,
        advertisingId: AD_ID,
        userId: USER_ID,
        country: "US",
        language: "en",
        // User Profile for better targeting.
        gender: "MALE",
        age: 30,
        uaChannel: "uaChannel",
        uaNetwork: "uaNetwork",
        adPlacement: "adPlacement",
        new AppsPrizeStyleConfig(
            primaryColor: Color.blue,
            secondaryColor: Color.black,
            highlightColor: Color.green,
            offersTitleText: "Test Offer",
            appsTitleText: "Test Apps"
        )
    )

The config object takes these parameters:

  • String token: The SDK token that you can take it from the dashboard once you add your app.
  • String userId: A custom user identifier that you give to your users. With the help of this ID, we will match the payouts to your users and inform you by server-to-server payout method.

Setting up AppsprizeListener

C#
public class AppsPrizeCustomListener : IAppsPrizeListener {
//...
    public void OnInitialize()
    {
        Debug.Log("[AppsPrize-Unity]: OnInitialize");
    }

    public void OnInitializeFailed(string errorMessage)
    {
        Debug.Log("[AppsPrize-Unity]: OnInitializeFailed");
    }

    public void OnRewardUpdate(List<AppRewards> rewards)
    {
        Debug.Log("[AppsPrize-Unity]: OnRewardUpdate: " + rewards.ToString());
    }
  
    public void OnNotification(List<AppsPrizeNotification> notifications)
    {
        Debug.Log("[AppsPrize-Unity]: OnNotification: " + notifications.ToString());
    }
//...
}

//...
AppsPrize.Initialize(
    appsPrizeConfig,
    new AppsPrizeCustomListener()
);
//...

You need to listen to OnInitializedFailed once the user opens your app and not show the AppsPrize for these users.

Next step

Once the SDK initializes, move on to using the SDK.