Notification

Please make sure to visit Your AdSense Page where you can find personalized information about your account to help you succeed with AdSense.

Set up a rewarded ad unit (beta)

You can show rewarded ads to users in exchange for additional value on your site, such as access to premium content, pages without ads, or coupon codes.

Advanced content Advanced: Setting up a rewarded ad unit is a multi-step process that requires you to create an ad unit in your AdSense account and implement your own JavaScript code. We do not recommend using this feature unless you're confident with JavaScript.

On this page:

Before you start

Before you implement rewarded ad units on your page:

  • Decide what will trigger your rewarded ad and what reward you'd like to offer your users for watching the rewarded ad. For example, you could trigger a rewarded ad when users visit a recipe page, and the reward for watching the ad could be coupon codes for the ingredients.
  • Make sure you review the Policies for ad units that offer rewards.

Instructions

Create a rewarded ad unit

  1. Sign in to your AdSense account.
  2. Click Ads.
  3. Click By ad unit.
  4. Click Rewarded ads.
  5. Give your rewarded ad unit a name.
  6. (Optional) Complete the reward settings for this ad unit. If you choose to use the reward settings, you can include a callback in your code for AdSense to return these values back to you when the user closes the rewarded ad. For details, review the implement the rewarded ad code on your site section below.
    • Ad reward type: Enter the name of the reward type the user will receive. Examples: premium content, coupons, etc.
    • Ad reward amount: Enter the number of reward items the user will receive. Must be a whole number.
  7. Click Create.
  8. In the "Add the rewarded ad HTML code" dialog, click Copy.
  9. Click Done.

Implement the rewarded ad code on your site

  1. Paste the rewarded ad code between the <body> and </body> tags of your page where you want the rewarded ad to appear.

    Code example 1

    Here's an example showing the rewarded ad code pasted between the <body> and </body> tags.

    <!doctype html>
    <html>
    <head>
      <title>Rewarded ad unit page</title>
    </head>
    <body>
      <script async src="https://pagead2.googlesyndication.com/pagead/js/
    adsbygoogle.js?client=ca-pub-123456" crossorigin="anonymous"></script>
      <script>
        slotVars = {
         google_ad_loaded_callback: {{enter your callback function}},
         google_ad_slot: 123456789,
      google_ad_format: "rewarded",
        };
        adsbygoogle = window.adsbygoogle || [];
        adsbygoogle.push({params: slotVars});
      </script>
    </body>
    </html>
  2. Implement a JavaScript callback function to pass in a google_ad_loaded_callback parameter. This callback function will be called when the rewarded ad is loaded.

    Code example 2

    Here's an example of the rewarded ad code with a loadRewardedAd callback function added:

    <script async src="https://pagead2.googlesyndication.com/pagead/js/
    adsbygoogle.js?client=ca-pub-123456" crossorigin="anonymous"></script>
    <script>
      slotVars = {
        google_ad_loaded_callback: loadRewardedAd, // your JavaScript 
        callback function
        google_ad_slot: 1234567890, // replace with your ad slot ID
        google_ad_format: "rewarded",
      };
      adsbygoogle = window.adsbygoogle || [];
      adsbygoogle.push({params: slotVars});
    </script>

    Explanation:

    • google_ad_loaded_callback: The callback function you create to handle the loading of the rewarded ad. The function receives the rewardedAd object as input, allowing you to handle ad-related events.
    • googld_ad_slot: The unique ad slot ID of the rewarded ad unit you created in AdSense.
    • google_ad_format: Indicates that this is the rewarded ad format.
  3. Implement a call to the show() function to display the rewarded ad. You need to pass in a JavaScript callback function as a parameter to handle the reward after the ad is closed. When the ad is viewed, the callback function retrieves the reward.

    Code example 3

    Here's an example that shows using the loadRewardedAd callback function to display the loaded ad and handle the reward once the ad is viewed and closed by the user.

    function loadRewardedAd(rewardedAd) {
        // handle case where ad fails to load.
        if (rewardedAd == null){
          alert("No rewarded ad loaded");
          return; 
        }

        if(confirm('show reward ads')){
           rewardedAd.show(result => {
            const closeStatus = result.status;
            const rewardPayload = result.reward;
      
            if(closeStatus == 'viewed') {
              // Grant reward to the user (e.g., update in-app currency)
              alert("Reward viewed");
            } else {
              alert("Ad closed without reward");
            }
          });
        }
    }

    Explanation:

    • The loadRewardedAd function receives the rewardedAd object when the ad is loaded.
    • If the ad is not loaded successfully, loadRewardedAd handles the no ad case and returns.
    • If the ad is loaded successfully and the ad is ready to be shown, loadRewardedAd calls show() to display the ad.
    • rewardedAd.show() displays the ad and takes a callback function as an argument to handle the result after the ad is closed.
    • The callback function receives AdClosedResult as the parameter which contains the close status and reward payload.
Note: It usually takes a few minutes for ads to appear on the page, but can occasionally take up to an hour.

Examples

To use these examples, copy and paste the HTML code, and replace the publisher code and ad slot ID before testing.

Example 1: Reward button appears when ad is loaded

This code demonstrates how to reward users for watching an ad after clicking on a button. The initial button will only be shown after an ad has successfully loaded.

<!DOCTYPE html>
<html>
<body>
  <!-- replace with your pub code -->
  <script async
    src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-123456" crossorigin="anonymous">
  </script>

  <button id="rewarded-button" hidden>Get Reward!</button>

  <script>
    function loadRewardedAd(rewardedAd) {
      if (rewardedAd != null) {
        var button = document.getElementById("rewarded-button");
        button.hidden = false;
        button.onclick = function() {
          rewardedAd.show(result => {
            if (result.status == 'viewed') {
              console.log('Reward was granted successfully:', 
result.reward);
            } else {
              console.log('Reward was not granted');
            }
          });
         button.hidden = true;
        };
      }
    }

    window.adsbygoogle = window.adsbygoogle || [];
    slotVars = {
      google_ad_loaded_callback: loadRewardedAd,
      google_ad_format: "rewarded",
      google_ad_slot: 234567890, // replace with your ad slot ID
    };
    window.adsbygoogle.push({params: slotVars}); 
  </script>
</body>
</html>

Example 2: Reward button is enabled when ad is loaded

This code demonstrates how to reward users for watching an ad after clicking on a button. The initial button will remain disabled until an ad has been successfully loaded.

<!DOCTYPE html>
<html>
<body>
  <!-- replace with your pub code -->
  <script async
    src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-123456" crossorigin="anonymous">
  </script>

  <button id="rewarded-button" disable"true">Get Reward!</button>

  <script>
    function loadRewardedAd(rewardedAd) {
      if (rewardedAd != null) {
        var button = document.getElementById("rewarded-button");
        button.disabled = false;
        button.onclick = function() {
          rewardedAd.show(result => {
            if (result.status == 'viewed') {
              console.log('Reward was granted successfully:', 
result.reward);
            } else {
              console.log('Reward was not granted');
            }
          });
          button.disabled = true; 
        };
      }
    }

    window.adsbygoogle = window.adsbygoogle || [];
    slotVars = {
      google_ad_loaded_callback: loadRewardedAd,
      google_ad_format: "rewarded",
      google_ad_slot: 234567890, // replace with your ad slot ID
    };
    window.adsbygoogle.push({params: slotVars}); 
  </script>
</body>
</html>

Rewarded ad function reference

The following table describes the rewarded ad functions.

Function Parameters Description
show adClosedCallback (callback function)

The callback function that receives a result object containing the following fields.

status Returns the status of ad closure.
  • viewed: The user viewed the ad.
  • dismissed: The user dismissed the ad.
  • error: The ad was closed with an unhandled error.
reward A JSON object containing information about the reward. This field is only used if you specify the "Ad reward settings" in your rewarded ad unit in AdSense.
  • type: The type of reward.
  • amount: The amount of the reward.
This method is called to make ads visible to the user. The callback function receives a result object containing the status of the ad closure and the reward payload you specified in your rewarded ad unit settings in AdSense.
disposeAd None This method is called to dispose of unused rewardedAd objects.

Test your rewarded ad unit

You can use the adtest parameter to test that your rewarded ad unit is working correctly. When the adtest parameter has a value of "on", Google treats the ad request as a test. You don't generate any revenue and Google doesn't count the ad impressions or track the clickthrough results, which means you can test your implementation.

Here's an example of the rewarded ad code with the adtest parameter set to "on":

<script async src="https://pagead2.googlesyndication.com/pagead/js/
adsbygoogle.js?client=ca-pub-123456" crossorigin="anonymous"
data-adtest="on"></script>

<script>
  slotVars = {
    google_ad_loaded_callback: loadRewardedAd, // your JavaScript callback
    google_ad_slot: 1234567890, // replace with your ad slot ID
    google_ad_format: "rewarded",
  };
  adsbygoogle = window.adsbygoogle || [];
  adsbygoogle.push({params: slotVars});
</script>

adtest parameter

(String) Specifies whether this is a test implementation. Possible values are "on" or "off". If set to "on", impressions and clicks won't be recorded in your account. This parameter must be used during testing. Defaults to "off" if not set.

Values:

  • off – (Default) All ads generate revenue normally. This is the setting that should be used for production.
  • on – Ensures that no ads log impressions or clicks. This setting is for use during testing.

Run a report on your rewarded ads

To track the performance of your rewarded ad units:

  1. Visit the Reports page in AdSense.
  2. Create a custom report, and add the "Ad format" and "Placement method" breakdowns.

    In the report, your rewarded ads units are shown with the ad format "Rewarded" and the placement method "Manual".

Tip: You can also create custom channels to track the performance of rewarded ad units.

Was this helpful?

How can we improve it?
true
Unlock your revenue with personalized tips today!

Visit the Optimization tips for AdSense page to see personalized suggestions to maximize your revenue.

Unlock now

Search
Clear search
Close search
Google apps
Main menu
17695349023171553527
true
Search Help Center
false
true
true
true
true
true
157
false
false
false
false
false