Other methods

There are some other methods in the adjoe SDK which you might find helpful.

getVersion

Returns the internal version code of the adjoe SDK, for example 17.

getVersionName

Returns the version name of the adjoe SDK, for example 1.2.0.

hasAcceptedTOS

Returns true if the user has accepted the adjoe TOS and false otherwise.

Payout via SDK

The following information on SDK-side reward handling is only relevant for your integration if you cannot use Server-to-Server Payout. Do not implement these functions if you already successfully followed the steps in the Payout section - it could trigger error messages and unexpected behaviour.

If you cannot handle the payout requests via an endpoint on your server, we can also handle the reward payouts inside the SDK itself.

To pay out the rewards that the user has collected from partner apps directly in the SDK, call

adjoe.doPayout()
  .then((payoutValue) => {
    // successfully paid out 'payoutValue' rewards
  })
  .catch((reason, err) => {
    // an error occurred while paying out the rewards
  
    // 'reason' is one of
    //  - Adjoe.PAYOUT_UNKNOWN
    //  - Adjoe.PAYOUT_NOT_ENOUGH_COINS
    //  - Adjoe.PAYOUT_TOS_NOT_ACCEPTED

    // if available, get more information about the error
    console.error(err);
  });

This method always pays out all rewards which the user has collected, i.e. the value of rewards.available_payout_coins.

If the user has not accepted the adjoe Terms of Service yet, this operation will fail and reason will be equal to Adjoe.PAYOUT_TOS_NOT_ACCEPTED. You might want to forward to Playtime again so that the user can accept the adjoe Terms of Service. This operation will also fail with reason equal to Adjoe.PAYOUT_UNKNOWN if the user is blocked by the adjoe services.

Adjoe Parameters

You can pass additional UA and placement parameters when you pay out the rewards:

Adjoe.doPayout({
	'uaNetwork': "uaNetwork_value",
	'uaChannel': "uaChannel_value",
	'uaSubPublisherCleartext': "uaSubPublisherCleartext_value",
	'uaSubPublisherEncrypted': "uaSubPublisherEncrypted_value",
	'placement': 'placement_value'
});

Retrying the payout

Sometimes, it can happen that the latest rewards haven't been processed yet by the server when you pay out. In this case, the promise rejects with reason equal to Adjoe.PAYOUT_NOT_ENOUGH_COINS. To overcome this, you can implement a retry mechanism for the payout, for example with an exponential backoff.

Example:

const PAYOUT_RETRY_BASE = 2000;
const PAYOUT_RETRY_MULTIPLIER = 2;
const MAX_PAYOUT_RETRIES = 5;

const doAdjoePayout = () => {
  doAdjoePayoutInternal(0);
};

const doAdjoePayoutInternal = (times) => {
  if (times < 0 || times >== MAX_PAYOUT_RETRIES) {
    // the payout has failed too often, which means that the user has no coins
    // you should handle this case properly
    return;
  }

  Adjoe.doPayout()
    .then((payoutValue) => {
      // everything is fine, rewards have been paid out
    })
    .catch((reason, err) => {
      if (reason === Adjoe.PAYOUT_NOT_ENOUGH_COINS) {
        setTimeout(() => {
          doAdjoePayoutInternal(times + 1);
        }, PAYOUT_RETRY_BASE * PAYOUT_RETRY_MULTIPLIER^times);
      } else {
        console.log(err);
      }
    });
};

Further context on Rewards

You can get information about the rewards that the user has collected as well as about how many rewards are available for payout and how many the user has already spent.

To do so call

Adjoe.requestRewards()
  .then((rewards) => {
    // successfully requested the rewards

    // get how many rewards the user has collected
    const reward = rewards.reward;
    
    // get how many rewards are available for payout
    const availableForPayout = rewards.available_for_payout;
    
    // get how many rewards the user has already spent
    const alreadySpentCoins = rewards.already_spent;
  })
  .catch((err) => {
    // an error occurred while requesting the rewards
    // you can try to get additional information about the error for debugging
    console.error(err);
  });

This operation will fail if the SDK is not initialized, the user has not accepted the adjoe Terms of Service or is blocked by the adjoe services.

Adjoe Parameters

You can pass additional UA and placement parameters when you request the rewards:

Adjoe.requestRewards({
	'uaNetwork': "uaNetwork_value",
	'uaChannel': "uaChannel_value",
	'uaSubPublisherCleartext': "uaSubPublisherCleartext_value",
	'uaSubPublisherEncrypted': "uaSubPublisherEncrypted_value",
	'placement': 'placement_value'
});

Last updated