1

I am working with the AdMob-Plus plugin and trying to integrate the RewardedAd as shown here.

THE ISSUE:

I want to offer 3 coins for every RewardedAd watched. My main issue is that I am unable to figure out how to track successfully after a user has watched a complete RewardedAd and increment the existing count of the coins in the user account by adding the new coin value to it and show this new value to the user in the UI.

EXAMPLE:

If the user already has 6 coins in his account and watches a RewardedAd, then his account should show the new balance as 9 coins. How can I achieve this?

THE CODE THAT I HAVE TRIED SO FAR:

  async loadRewardsAd(): Promise<void> {
    this.rewarded = new this.admob.RewardedAd({
      adUnitId: this.adRewardedId,
      serverSideVerification: {
        customData: 'coin=3',
        userId: '1234567',
      }
    });

    // Load rewarded
    await this.rewarded.load();
    // Display rewarded
    await this.rewarded.show();
  }
Devner
  • 6,825
  • 11
  • 63
  • 104

1 Answers1

0

As far as I see there is no option to get the total amount to display in the ad but only the fresh rewarded points like shown here:

if (mRewardedAd != null) {
  Activity activityContext = MainActivity.this;
  mRewardedAd.show(activityContext, new OnUserEarnedRewardListener() {
    @Override
    public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
      // Handle the reward.
      Log.d(TAG, "The user earned the reward.");
      int rewardAmount = rewardItem.getAmount();
      String rewardType = rewardItem.getType();
    }
  });
} else {
  Log.d(TAG, "The rewarded ad wasn't ready yet.");
}

this is the same code in Kotlin:

if (mRewardedAd != null) {
  mRewardedAd?.show(this, OnUserEarnedRewardListener() {
    fun onUserEarnedReward(rewardItem: RewardItem) {
      var rewardAmount = rewardItem.amount
      var rewardType = rewardItem.type
      Log.d(TAG, "User earned the reward.")
    }
  })
} else {
  Log.d(TAG, "The rewarded ad wasn't ready yet.")
}

Beware the hint on the top of the page:

Warning: There are many breaking changes coming in version 20.0.0. Version 19.7.0 introduces many new APIs, deprecates many classes and APIs and renames many classes in preparation for version 20.0.0. Please read the migration guide for more details on the changes.

Getting the total amount seems to require to login into the AdMob Reporting API, which is not available for common viewers: admob/api

The reporting by the cordova-admop api seems even to be impossible, I never found any functionality for it.

David
  • 5,882
  • 3
  • 33
  • 44
  • Is there a non-java equivalent version of your solution that I can use in Ionic app? – Devner Jul 18 '22 at 01:20
  • The restrictions concerning the transparency are coming from the ad-server, especially if the google-admop-api is used. So another client sided api can't exceed these restrictions. In general it might be possible to maintain an own server that is querying the ad-data regularly and providing the total-points, that would require a second query on client side. It should be considered though that a solution like that might infringe the terms of use perhaps. – David Jul 18 '22 at 01:41
  • Sorry if I was not clear in my earlier message. I meant to say that you have shared the Java version of the code. Is there a Ionic version of the code that you posted, so that I can use it directly in my Ionic app? – Devner Jul 18 '22 at 02:07
  • Above the code is the link, where I took that code. There you can get also the kotlin variant. – David Jul 18 '22 at 02:09
  • I am unable to get any of the above codes to work. Is there any other code that you may be able to perhaps share with me? – Devner Jul 20 '22 at 06:05