> For the complete documentation index, see [llms.txt](https://ub-docs.adster.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ub-docs.adster.tech/how-to-render-an-ad/rewarded-ad.md).

# Rewarded Ad

Before loading ads, have your app initialize Adster Unity Bridge SDK.\
This needs to be done only once, ideally at app launch.

1. Call `LoadRewardedAd()`method as per below format

```csharp
AdsterBridgeUtil.LoadRewardedAd("Your_placement_name", "gameobject_name_goes_here");
```

2. Declare `OnRewardedAdEvent()` method as per below format

{% tabs %}
{% tab title="C#" %}

```java
public void OnRewardedAdEvent(string message)
    {
        switch (message)
        {
            case "AdLoaded":
                Debug.Log("Rewarded ad loaded.");
                // Trigger any Unity logic for ad loaded here
                break;

            case "VideoStart":
                Debug.Log("Rewarded ad video started.");
                // Handle video start logic
                break;

            case "VideoClosed":
                Debug.Log("Rewarded ad video closed.");
                // Handle video closed logic
                break;

            case "VideoComplete":
                Debug.Log("Rewarded ad video completed.");
                // Handle video completion logic
                break;

            case "AdImpression":
                Debug.Log("Rewarded ad impression recorded.");
                // Handle ad impression logic
                break;

            case "AdClicked":
                Debug.Log("Rewarded ad clicked.");
                // Handle ad click logic
                break;

            default:
                if (message.StartsWith("RewardEarned:"))
                {
                    // Parse reward type and amount from the message
                    string[] rewardData = message.Substring("RewardEarned:".Length).Split(':');
                    string rewardAmount = rewardData[0];
                    Debug.Log($"User earned reward: Amount = {rewardAmount}");
                }
                else if (message.StartsWith("AdFailed:"))
                {
                    string error = message.Substring("AdFailed:".Length);
                    Debug.LogError($"Rewarded ad failed to load: {error}");
                }
                else if (message.StartsWith("AdRevenuePaid"))
                {
                    Debug.Log(message);
                    string[] parts = message.Split('|');
                    if (parts.Length == 4)
                    {
                        string revenue = parts[1];
                        string adUnit = parts[2];
                        string network = parts[3];
                        Debug.Log($"[AdRevenue] Revenue: {revenue}, AdUnit: {adUnit}, Network: {network}");
            
                    return;
                    }
                }
                break;
        }
    }
```

{% endtab %}
{% endtabs %}

3. Inside the `AdLoaded` callback method invoke `ShowRewardedAd()` method as below to show AdSter rewarded ad above any scene/view.

{% tabs %}
{% tab title="C#" %}

```csharp
AdsterBridgeUtil.ShowRewardedAd("gameobject_name_goes_here");
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ub-docs.adster.tech/how-to-render-an-ad/rewarded-ad.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
