Hello everyone,
I have some questions about using Rewarded Ads feature. (We're using AdMob ad network)
- What is AppId?
I think, AppId is the app key that is given for a game/app by the ad network, So, AppId should be something like "ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx" for AdMob? There's also another key called Published Id. which is something like: "pub-xxxxxxxxxxxxxxxx".
- How does the reset work for the reward limit?
For example; I setup an ad and limit it to 2 impressions per hour. If a player watches an ad at 1:50 PM, will the limit reset at 2:00 PM or 2:50PM?
- Does RewardedAds feature verify if a player watched the rewarded ad?
Some players may close the ad before it's finished, and a hacked client can call RewardAdActivity without waiting the ad is finished.
- How to show ads and claim rewards?
Since this feature is built for every ad networks, I couldn't find any example code about this in the documents. (Maybe I missed it.)
A part of the document about coding says:
When your ad SDK reports that the ad view has successfully completed, call Client/RewardAdActivity to trigger the reward
We're using Unity for the game. I guess, I need to use Google Mobile Ads extension and show an ad normally. When the related event is fired (OnUserEarnedReward), I need to call the PlayFab API: RewardAdActivity.
The next sentence in the document says:
This call requires the PlacementId and RewardId returned by Client/GetAdPlacements
This is where my confusion starts. When should I call GetAdPlacements?
I guess, I need to load an ad and call GetAdPlacements at the same time or when the loading is finished, call GetAdPlacements; and when the ad is shown successfully, I need to call RewardAdActivity. Is this correct?
I wrote an example code to show what I understand so far. Also, there's a parameter called NameIdentifier in the GetAdPlacementRequest class. What info should I send there?
private RewardedAd currentAd; private string placementId; private string rewardId; public void ShowRewardedAd() { // Load the ad by using the Google Mobile Ads extension currentAd = new RewardedAd(/** Ad unit id here */); AdRequest adRequest = new AdRequest.Builder().Build(); currentAd.LoadAd(adRequest); // 1st option: Call GetAdPlacements while the ad is loading GetAdPlacementsRequest adPlacementRequest = new GetAdPlacementsRequest() { // I assume, the AppId is same as the Id I mentioned in the first question AppId = "ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx", Identifier = new NameIdentifier() { Id = // What info should I send here? Name = // What info should I send here? } }; PlayFabClientAPI.GetAdPlacements(adPlacementRequest, GetAdPlacementsSuccess, GetAdPlacementsFail); /** Setting up the events */ // If the 1st option is used, remove the 2nd option from the code currentAd.OnAdClosed += (sender, args) => { // 2nd option: Call GetAdPlacements after the ad is loaded GetAdPlacementsRequest adPlacementRequest = new GetAdPlacementsRequest() { // I assume, the AppId is same as the Id I mentioned in the first question AppId = "ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx", Identifier = new NameIdentifier() { Id = // What info should I give here? Name = // What info should I put here? } }; PlayFabClientAPI.GetAdPlacements(adPlacementRequest, GetAdPlacementsSuccess, GetAdPlacementsFail); }; currentAd.OnUserEarnedReward += (sender, args) => { RewardAdActivityRequest claimRewardRequest = new RewardAdActivityRequest() { PlacementId = placementId, RewardId = rewardId }; PlayFabClientAPI.RewardAdActivity(claimRewardRequest, (result) => { // Update the inventory on the client side by using the result.RewardResults variable }, (error) => { // Show error message }); }; } private void GetAdPlacementsSuccess(GetAdPlacementsResult result) { placementId = result.AdPlacements[0].PlacementId; rewardId = result.AdPlacements[0].RewardId; } private void GetAdPlacementsFail(PlayFabError error) { // Show error message }