ionic4admob-rewardedvideoadcordova-admob

Ionic AdMob Plus - How to track user rewards in a RewardedAd and show the updated balance in the UI?


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();
  }

Solution

  • 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.