Quickstart: from an empty project to a purchase
You will install the Stores module, fill a store with a sample, publish it to staging and buy two offers from a game: a free welcome pack of 100 gems, then a starter pack for 10 of them.
Download the rudder CLI first. The SDK of your engine installs from the
Rudder package registry in the steps below.
Set up the project
Section titled “Set up the project”-
Open the Rudder Dashboard, enter your email and open the link that comes to it; that creates your account and signs you in.
-
In your game repository, sign the CLI in and create a project.
Terminal window rudder loginrudder project create "My Game" --jsonUse the returned project ID to select it, then install the agent instructions if you want an agent to carry out the following steps.
Terminal window rudder project use --environment staging <project-id>rudder agent init -
Save the following currency objects as
gems.jsonandgold.json.{"slug":"gems","name":"Gems","clientVisible":true}{"slug":"gold","name":"Gold","clientVisible":true}Terminal window rudder currency create --file gems.jsonrudder currency create --file gold.json -
Read the ready modules and install Stores. Inventory is installed with it.
Terminal window rudder module show stores --jsonrudder module install storesrudder module apply-sample inventory starterrudder module apply-sample stores starter -
Check the configured draft. Use the returned revision for publication.
Terminal window rudder release check --jsonrudder release publish --expected-revision <revision> --jsonIf the check reports a problem, correct the catalog through the CLI or Dashboard and check again. Record the published staging version for client generation.
-
Read the staging SDK key.
Terminal window rudder environment show --env staging --json
Generate the client of your project
Section titled “Generate the client of your project”project use writes rudder.json at the root of your repository. Commit it: every later command
reads the project from it.
The client is typed code written for your project: a class per module and a method per function a client may call. Generate it from the staging version returned by publication.
rudder client generate --lang csharp --output Assets/Rudder/Rudder.g.cs \ --game-address https://api.rudder.build --release-version <version>Then add the SDK to Packages/manifest.json of your Unity 6 project, from the Rudder package
registry:
{ "scopedRegistries": [ { "name": "Rudder", "url": "https://hub.rudder.build/api/packages/rudder/npm/", "scopes": ["@rudder"] } ], "dependencies": { "@rudder/unity": "1.3.0" }}rudder client generate --lang ts --output src/rudder.ts \ --game-address https://api.rudder.build --release-version <version>echo "@rudder:registry=https://hub.rudder.build/api/packages/rudder/npm/" >> .npmrcnpm install @rudder/sdkThe browser calls Rudder from the origin of your game. Read the existing origins with
environment show, then retain the ones you need and add the local game origin in
origins.json.
{"allowedOrigins":["http://localhost:5173"]}rudder environment set-origins --env staging --file origins.jsonThe project owner changes this full list. The Dashboard environment settings offer the same operation.
Buy an offer
Section titled “Buy an offer”using Game;using Game.Stores;using RudderSdk;using UnityEngine;
public class FirstPurchase : MonoBehaviour{ [SerializeField] private string sdkKey;
private async void Start() { var rudder = await Rudder.SignInDevice(sdkKey, SystemInfo.deviceUniqueIdentifier);
foreach (var offer in new[] { "welcome", "starter" }) { try { var bought = await rudder.Stores.Buy(new BuyArguments { Offer = offer }); Debug.Log($"Bought {bought.Name}, {bought.Remaining} more allowed"); } catch (RudderException exception) when (exception.Code == "limit_reached") { Debug.Log($"This player bought {offer} already"); } }
var balances = await rudder.Session.Wallet(); Debug.Log($"gems {balances["gems"]}, gold {balances["gold"]}"); }}import { RudderError } from '@rudder/sdk';import { Rudder } from './rudder';
const sdkKey = '...'; // the SDK key of stagingconst deviceId = localStorage.getItem('deviceId') ?? crypto.randomUUID();localStorage.setItem('deviceId', deviceId);
const rudder = await Rudder.signInDevice(sdkKey, deviceId);
for (const offer of ['welcome', 'starter']) { try { const bought = await rudder.stores.buy({ offer }); console.log(`Bought ${bought.name}, ${bought.remaining} more allowed`); } catch (error) { if (!(error instanceof RudderError) || error.code !== 'limit_reached') { throw error; } console.log(`This player bought ${offer} already`); }}
const balances = await rudder.session.wallet();console.log(`gems ${balances.gems}, gold ${balances.gold}`);The first run prints 90 gems and 300 gold: the welcome pack gave 100 gems, the starter pack
cost 10 and gave 300 gold and two potions. The next run on the same device gets
limit_reached for both packs: each sells once per player.
See it in the Dashboard
Section titled “See it in the Dashboard”Open Players, choose Staging in the header and open the newest player. Its card shows the
balances, the potions under Inventory and the purchases under Stores. History lists both
calls of stores.buy with every change they made: the gems paid, the currencies and items
granted, the purchases counted.
Your own module
Section titled “Your own module”The marketplace covers the common features. What is unique to your game, such as a daily bonus or a battle pass on the purchases of Stores, is a module of your own: see Own modules. Your first module walks through writing one; a project on the Free plan writes and tests it locally and needs Pro to publish it.
- Sample: Lanternmoor Expeditions: a complete game on Rudder that you can play.
- Client SDK: sign-in, errors, retries and idempotency.
- Stores: what a store and an offer can do.
- Releases: promote staging to production.