To make all of the features of the Playtime SDK available, you need to initialize it first. This initialization happens asynchronously in the background, with its completion indicated by a callback method. Make sure to initialize the SDK immediately after the app launches and each time it returns to the foreground.
Best practices for the SDK initialization:
Initialize early: Initialize the SDK as soon as possible after your app starts. This ensures all Playtime SDK features are ready for use right away.
Initialize after your app authentication: Once a user signs up or logs in, initialize the SDK again with the latest user details. This updates the userID within the SDK.
Initialize regularly: For the best user experience, call the init method every time your app comes into the foreground. Doing so will not affect your app's performance.
Initialization triggers: Call the init method at the app start and resume (when the app comes back into the foreground).
Initialization
// The initialization will run in the main application process asynchronously in the background and notify you when it is finished by invoking the AdjoeInitializationListener's onInitialisationFinished or onInitialisationError method.
classMainActivity : AppCompatActivity {overridefunonCreate(savedInstanceState: Bundle?) { Adjoe.init(this, "sdkHash", options, object: AdjoeInitialisationListener {overridefunonInitialisationFinished() {// the adjoe SDK was initialized successfully }overridefunonInitialisationError(exception: Exception?) {// an error occurred while initializing the adjoe SDK.// note that exception might be null } }) }}
// The initialization will run in the main application process asynchronously in the background and notify you when it is finished by invoking the AdjoeInitializationListener's onInitialisationFinished or onInitialisationError method.
publicclassMainActivityextendsActivity { @OverrideprotectedvoidonCreate() { super.onCreate();Adjoe.init(this,"sdkHash", options,newAdjoeInitialisationListener() { @OverridepublicvoidonInitialisationFinished() {// the adjoe SDK was initialized successfully } @OverridepublicvoidonInitialisationError(Exception exception) {// an error occurred while initializing the adjoe SDK.// note that exception might be null } }); }}
// Should be called during the app start, for example in the App.js's componentDidMount() methodAdjoe.init('sdkHash', options).then(() => {console.log('Initialized adjoe SDK'); }).catch((err) => {console.log('Could not initilize adjoe SDK');console.error(err); });
// 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. Make sure to initialize in initState as well as didChangeAppLifecycleState.
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';voidinitializeAdjoe() {Adjoe.init(sdkHash, options).then((_) {print('Init finished successful'); }, onError: (err) {print('Init failed: $err'); });}
usingio.adjoe.sdk;publicclassMain {voidStart(){Adjoe.Init("sdkHash", options, AdjoeInitialisationSuccess, AdjoeInitialisationError);}publicvoidAdjoeInitialisationSuccess(){ // the adjoe SDK was initialized successfully}publicvoidAdjoeInitialisationError(Exception exception){ // an error occurred while initializing the adjoe SDK. // note that exception might be null}}
window.AdjoePlugin.initialize('sdkHash','options',function() {// the adjoe plugin was initialized successfully },function(err) {// an error occurred while initializing the adjoe plugin. },);
Important: Initialization must happen on the main thread since it's a UI-related action. Calling any of the init methods off the main thread could lead to app disruptions.
adjoe Options
Pass the following additional options to the Playtime SDK during initialization:
val options = Adjoe.Options() .setUserId(userId) .setParams(adjoeParams); .setUserProfile(adjoeUserProfile) .setExtensions(adjoeExtensions);
// A complete examplewindow.AdjoePlugin.initialize('sdkHash', { 'user_id':getUserId(),'adjoe_params': {'uaNetwork':"uaNetwork_value",'uaChannel':"uaChannel_value",'uaSubPublisherCleartext':"uaSubPublisherCleartext_value",'uaSubPublisherEncrypted':"uaSubPublisherEncrypted_value",'placement':'placement_value' },'adjoe_extension': {'subId1':"RN_subId1",'subId2':"RN_subId2",'subId3':"RN_subId3",'subId4':"RN_subId4",'subId5':"RN_subId5" },'user_profile': {'gender':'MALE','birthdate':"2023-07-17T22:25:00.000Z" } },function() {// the adjoe plugin was initialized successfully },function(err) {// an error occurred while initializing the adjoe plugin. },);
adjoe Parameters
When initializing the SDK, you should include additional User Acquisition and Playtime placement parameters. These parameters allow you to track and analyze Playtime's performance within your app.
To make the most of the Playtime SDK, to maximize your revenue and provide the best user experience, use all of these parameters for data-driven optimizations. For instance, you can monitor the performance of different Playtime button placements or determine the effectiveness of different UA sources.
You can provide these parameters in any combination, both at initialization and at any point in the app's lifecycle—such as when a user launches the Playtime Offerwall, interacts with a campaign or requests a payout.
These values must be url-safe as they could potentially be returned as query parameters in the S2S Payout request.
adjoe.setUAParams({'uaNetwork':"RN-uaNetwork",'uaChannel':"RN-uaChannel",'uaSubPublisherCleartext':"RN-uaSubPublisherCleartext",'uaSubPublisherEncrypted':"RN-uaSubPublisherEncrypted",'placement':'RN-placement'}).then(() => {this.logDialog(`Setting UA prameters were sucessful.`);}).catch((err) => {this.logDialog(`Setting UA prameters failed.`);console.error(err);});
// A complete examplewindow.AdjoePlugin.initialize('sdkHash', { 'user_id':getUserId(),'adjoe_params': {'uaNetwork':"uaNetwork_value",'uaChannel':"uaChannel_value",'uaSubPublisherCleartext':"uaSubPublisherCleartext_value",'uaSubPublisherEncrypted':"uaSubPublisherEncrypted_value",'placement':'placement_value' },'adjoe_extension': {'subId1':"RN_subId1",'subId2':"RN_subId2",'subId3':"RN_subId3",'subId4':"RN_subId4",'subId5':"RN_subId5" },'user_profile': {'gender':'male','birthdate':"2023-07-17T22:25:00.000Z" } },function() {// the adjoe plugin was initialized successfully },function(err) {// an error occurred while initializing the adjoe plugin. },);
User Profile Information
Our game recommendations are personalized through algorithms that consider users' preferences and gender information. If a user consents to share their gender and/or birthday, you can share this information with adjoe to enhance the customization of game suggestions.
The code below is for demonstration purposes and can be modified to best suit your app's set-up. The important thing is that you get the user's birthday and gender information from your backend and pass in the data to adjoe when initializing.
The birthday data should be in ISO format. If your data doesn't already look like that, please make sure to format it so that it is. Example: 2023-07-17T22:25:00.000Z
funadjoeUserProfile(): AdjoeUserProfile {val gender: AdjoeGender=when (getUserGender()) {"male"-> AdjoeGender.MALE"female"-> AdjoeGender.FEMALEelse-> AdjoeGender.UNKNOWN }// if you don't know the exact birthday, the year is enoughval birthday: Date=if (isExactBirthdayKnown()) {getUserBirthday() } else {val calendar = Calendar.getInstance() calendar.set(Calendar.YEAR, getYearOfBirth()) calendar.set(Calendar.MONTH, 0) calendar.set(Calendar.DAY_OF_MONTH, 0) calendar.time }returnAdjoeUserProfile(gender, birthday)}
publicclassUserProfileUtils {publicstaticAdjoeUserProfileadjoeUserProfile() {AdjoeGender gender =getAdjoeGender(getUserGender());Date birthday =getBirthday();returnnewAdjoeUserProfile(gender, birthday); }privatestaticAdjoeGendergetAdjoeGender(String userGender) {switch (userGender) {case"male":returnAdjoeGender.MALE;case"female":returnAdjoeGender.FEMALE;default:returnAdjoeGender.UNKNOWN; } }privatestaticStringgetUserGender() {// Implement this method to get the user's genderreturn"male"; // Example placeholder }privatestaticDategetBirthday() {if (isExactBirthdayKnown()) {returngetUserBirthday(); } else {Calendar calendar =Calendar.getInstance();calendar.set(Calendar.YEAR,getYearOfBirth());calendar.set(Calendar.MONTH,Calendar.JANUARY);calendar.set(Calendar.DAY_OF_MONTH,1);returncalendar.getTime(); } }privatestaticDategetUserBirthday() {// Implement this method to get the user's birthdayreturnnewDate(); // Example placeholder }privatestaticbooleanisExactBirthdayKnown() {// Implement this method to determine if the exact birthday is knownreturntrue; // Example placeholder }privatestaticintgetYearOfBirth() {// Implement this method to get the user's year of birthreturn1990; // Example placeholder }}
functionadjoeUserProfile() {constuserGender=getUserGender();let gender;if (userGender ==="male") { gender ="MALE"; } elseif (userGender ==="female") { gender ="FEMALE"; } else { gender ="UNKNOWN"; }// if you don't know the month or day, you can set them to 01let birthday;if (isExactBirthdayKnown()) { birthday =newDate(getUserBirthday()); } else {constcalendar=newDate();calendar.setFullYear(getYearOfBirth());calendar.setMonth(0);calendar.setDate(1); birthday = calendar; } birthday =birthday.toISOString() return { gender, birthday };}
import'package:adjoe/user_profile.dart';import'package:adjoe/gender.dart';AdjoeGender gender;switch (getUserGender()) {case"male": gender =AdjoeGender.MALE;break;case"female": gender =AdjoeGender.FEMALE;break;default: gender =AdjoeGender.UNKNOWN;break;}// set the birthday. If you don't know the user's exact birthday, the year is already enough.DateTime birthday =getUserBirthday();AdjoeUserProfile adjoeUserProfile =AdjoeUserProfile() ..gender = gender ..birthday = birthday;
//Cordova has a different API that can be used to set the user profile information.window.AdjoePlugin.setProfile( source, gender, birthday,function() {// successfully sent the profile information to adjoe },function(err) {// an error occurred while sending the profile information to adjoe },);
adjoe Extensions
These are optional identifiers used in your backend. They will be provided back in the S2S payout URL.
// A complete examplewindow.AdjoePlugin.initialize('sdkHash', { 'user_id':getUserId(),'adjoe_params': {'uaNetwork':"uaNetwork_value",'uaChannel':"uaChannel_value",'uaSubPublisherCleartext':"uaSubPublisherCleartext_value",'uaSubPublisherEncrypted':"uaSubPublisherEncrypted_value",'placement':'placement_value' },'adjoe_extension': {'subId1':"RN_subId1",'subId2':"RN_subId2",'subId3':"RN_subId3",'subId4':"RN_subId4",'subId5':"RN_subId5" },'user_profile': {'gender':'male','birthdate':"2023-07-17T22:25:00.000Z" } },function() {// the adjoe plugin was initialized successfully },function(err) {// an error occurred while initializing the adjoe plugin. },);
Checking Initialization
We recommend to verify the SDK is correctly initialized. Each wrapper provides an Adjoe.isInitialized method for this purpose. When executed, this method returns true if the SDK is initialized, and false otherwise. Use IsInitialized for debugging or to verify SDK initialization before calling other methods.
Important: Do not call Adjoe.init based on the result of isInitialized.The SDK already performs its own initialization checks. Doing so again may degrade the user experience.
A custom identifier you can assign to each user. If you haven't set one, the Playtime SDK generates it automatically. It is accessible through Adjoe.getUserId(Context). This ID is necessary for S2S payouts, thus required. Ensure this value is url-safe and that the value is never empty.