> For the complete documentation index, see [llms.txt](/llms.txt)

# Ads

Tracks ad views and manages the points you can use to reward players for watching them.




**About this demo**

The demo signs in automatically with an anonymous account. The account is shared across every demo in the showroom, so items and currency you get in one demo carry over to the others. Loading takes a moment. If the frame is too small, open the demo in a new tab.

## Overview

This demo banks one point each time an ad view completes and spends one point when a reward is claimed. The showroom runs as a WebGL page in the browser, where the mobile-only ad SDKs (Unity Ads, LevelPlay, AdMob) cannot run, so no real advertisement plays. Instead a panel stands in for the ad placement, and everything after the title decides "the view finished", which is GS2's part, runs for real.

## How to try it

1. **Balance** under **Ad view point** shows the banked points, e.g. **0 view(s) banked**.
1. Press **Ad break**; an **Advertisement** panel opens and explains why no ad plays. Wait for the **You can continue in 5s.** countdown to finish.
1. Press **I finished watching**; the page tells GS2 the view completed and asks for the point, and **Balance** goes up by 1. Pressing **Close** instead grants nothing.
1. Press **Spend**; one point is consumed and **Balance** goes down by 1.

In a shipped title, the point is granted from the ad network's completion callback where **I finished watching** sits here. Deciding that a view really happened is the title's job.

## GS2 services used

- [GS2-AdReward](/microservices/ad_reward/): A GS2-AdReward namespace holds each player's view points. Points are granted with `Gs2AdReward:AcquirePointByUserId` and consumed with `Gs2AdReward:ConsumePointByUserId`; granting does not verify the view itself.
- [GS2-Exchange](/microservices/exchange/): Two GS2-Exchange rates define the transactions that grant one point (**I finished watching**) and consume one point (**Spend**), and run them server-side automatically.

## Use it in GS2 Studio

In GS2 Studio's Simple mode, open **Add features** and press **Add** on **Ads** to bring this feature into your own project. To point at the package directly, choose **Add from GitHub** and enter the package below.

```text
https://github.com/gs2io/gs2-studio-package/tree/main/foundation-economy-ad/packages/foundation-economy-ad
```

- Owner: `gs2io`
- Repository: `gs2-studio-package`
- Subdirectory: `foundation-economy-ad/packages/foundation-economy-ad`

## Source code

- Demo project: <https://github.com/gs2io/gs2-studio-package/tree/main/foundation-economy-ad/live-demo>
- Feature package: <https://github.com/gs2io/gs2-studio-package/tree/main/foundation-economy-ad>



