question

Ozan Yilmaz avatar image
Ozan Yilmaz asked

Setting up Rewarded Ads for AdMob?

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
    }
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

The Rewarded Ads feature is designed to allow you to provide rewards to players for watching ads in your game, and to control how frequently they can get them, but it does not have direct integration with any ad provider. For your questions:

- What is AppId?

The unique ID of your application in the ad provider's service. In the case of Ad Mob, it's the App ID: App ID - Google AdMob Help.

- How does the reset work for the reward limit?

It's a rolling windows. So in your example, the player could not be rewarded again until an hour after the first ad was rewarded (so, not until 2:50 PM).

- Does RewardedAds feature verify if a player watched the rewarded ad?

No. That's why I call out that this service does not have a direct integration with any ad provider (which would be required, for us to have that information).

- How to show ads and claim rewards?

This feature specifically enables the reward part of the process. Showing the ad would be down to whatever logic you choose to use. There are three API calls to be concerned with, on the Microsoft side:

GetAdPlacements - returns the set of available placements and an example reward (note that if you're using a result table with a weighted set of possible rewards, this may not match what the player gets when you call to reward the ad watched).

ReportAdActivity - this is an optional call for tracking on when players open, close, start, and end ads, for purposes of analytics.

RewardAdActivity - this is the call to attempt to reward the player for having watched an ad.

- When should I call GetAdPlacements?

Whenever you want an updated list of the ad placements you've defined in the game. This might be when you're coming to the end of a level, if you use non-optional interstitial ads, or it might be just at the start of the player's session - there's no specific requirement around this, and calling it does not affect how RewardAdActivity works.

- 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?

Calling GetAdPlacements isn't required - it's there to allow you to get the updated list of ads, so that the client has the latest info when you need it. Two examples: 1. You may have changed the ad placements since the player's session started. 2. The player may have changed the time on their device, in an attempt to get a reward faster. So, in 1, the ads may have changed out from under them, while in 2, a locally-computed time may not be valid.

- There's a parameter called NameIdentifier in the GetAdPlacementRequest class. What info should I send there?

That's an optional parameter you can use to filter the results down to a specific ad placement. You can use either the Id or Name parameter to specific a placement.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ozan Yilmaz avatar image Ozan Yilmaz commented ·

Thank you for the detailed answer.

0 Likes 0 ·
Jeremy Rose avatar image
Jeremy Rose answered

Is there a way to setup the RewardAdActivity to only be called by server API?

I am assuming most ad SDKs have a server to server ad completed callback url.

It would be much nicer to point this url to playfab to have it reward the item instead of having the client call it.

Seems that having the client call the reward function is open and easily abused.

Right now I am having to track this ad data in our own server. Along with the rewards.

It would be much nicer from what I have seen so far to have playfab provide a server side completed url instead of client side.

We are using Vungle at the moment for ads.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mark-4 avatar image
mark-4 answered

This would be useful for us too. Most ad providers do indeed have server side verification that an ad was watched, and we can point it to a URL. I wish we could point this to playfab so we could check the data later via cloudscript etc. How many ads were watched, rewards given out etc.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]