Ads

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.
  2. Press Ad break; an Advertisement panel opens and explains why no ad plays. Wait for the You can continue in 5s. countdown to finish.
  3. 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.
  4. 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: 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: 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.

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