quests: QuestMetrics helpers (purchaseOffer/purchaseItem), README quests section
This commit is contained in:
@@ -61,7 +61,7 @@ client.dispose();
|
|||||||
| Storage | `client.storage` (observable) + `.save(items)` / `.delete(type)` |
|
| Storage | `client.storage` (observable) + `.save(items)` / `.delete(type)` |
|
||||||
| Leaderboards | `client.leaderboards.findBySlug(slug)` → `handle.submit(score)` / `handle.list(limit?)` |
|
| Leaderboards | `client.leaderboards.findBySlug(slug)` → `handle.submit(score)` / `handle.list(limit?)` |
|
||||||
| Battle pass | `client.battlePass` (getProgress / addXp / claimReward / purchasePremium) |
|
| Battle pass | `client.battlePass` (getProgress / addXp / claimReward / purchasePremium) |
|
||||||
| Quests | `client.quests.list()` / `client.quests.claim(id)` |
|
| Quests | `client.quests.list()` / `client.quests.claim(id)` / `client.quests.reportProgress(metric, amount)` |
|
||||||
| Scenario effects | `client.effects.on*` |
|
| Scenario effects | `client.effects.on*` |
|
||||||
|
|
||||||
Type the remote config for `client.remoteConfig`:
|
Type the remote config for `client.remoteConfig`:
|
||||||
@@ -75,6 +75,37 @@ const client = new RudderClient<GameConfig>({ /* … */ });
|
|||||||
client.remoteConfig.get('player_speed', 200); // number
|
client.remoteConfig.get('player_speed', 200); // number
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Quests
|
||||||
|
|
||||||
|
`client.quests` covers the player's global quests — list with per-objective
|
||||||
|
progress, claim, and metric reports. These are distinct from scenario quest
|
||||||
|
nodes, which advance through the `onQuest` effect's `QuestSession`. Global
|
||||||
|
quests have no live sync: re-list after a claim or report.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const quests = await client.quests.list();
|
||||||
|
for (const quest of quests) {
|
||||||
|
if (quest.status === 'completed' && quest.id) {
|
||||||
|
await client.quests.claim(quest.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom metrics advance matching objectives server-side; the call returns
|
||||||
|
// the ids of quests completed by this report.
|
||||||
|
const completedIds = await client.quests.reportProgress('kills', 1);
|
||||||
|
```
|
||||||
|
|
||||||
|
Purchase metrics are reported automatically when a purchase goes through
|
||||||
|
`client.stores`; the `QuestMetrics` helpers name the format so quest configs
|
||||||
|
and client code agree on it:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { QuestMetrics } from '@rudder/js-sdk';
|
||||||
|
|
||||||
|
QuestMetrics.purchaseOffer('starter-pack'); // "purchase.offer:starter-pack"
|
||||||
|
QuestMetrics.purchaseItem('moonberry'); // "purchase.item:moonberry"
|
||||||
|
```
|
||||||
|
|
||||||
## Scenario effects
|
## Scenario effects
|
||||||
|
|
||||||
The scenario runtime is not exposed directly; scenario nodes surface through
|
The scenario runtime is not exposed directly; scenario nodes surface through
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export type {
|
|||||||
export type { LeaderboardsService, LeaderboardHandle } from './leaderboards/LeaderboardsService.js';
|
export type { LeaderboardsService, LeaderboardHandle } from './leaderboards/LeaderboardsService.js';
|
||||||
export type { BattlePassService } from './battlepass/BattlePassService.js';
|
export type { BattlePassService } from './battlepass/BattlePassService.js';
|
||||||
export type { QuestsService } from './quests/QuestsService.js';
|
export type { QuestsService } from './quests/QuestsService.js';
|
||||||
|
export * as QuestMetrics from './quests/QuestMetrics.js';
|
||||||
|
|
||||||
// Observable state primitives
|
// Observable state primitives
|
||||||
export { SyncedState } from './state/SyncedState.js';
|
export { SyncedState } from './state/SyncedState.js';
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* QuestMetrics — builders for the quest metric strings known to the platform.
|
||||||
|
*
|
||||||
|
* Purchase metrics are reported automatically by the shop purchase fan-out,
|
||||||
|
* so these helpers exist mainly to name the format instead of hardcoding it.
|
||||||
|
* Any other metric is a custom string reported via
|
||||||
|
* {@link QuestsService.reportProgress}.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Metric for purchasing a store offer; auto-reported on purchase. */
|
||||||
|
export function purchaseOffer(offerId: string): string {
|
||||||
|
return `purchase.offer:${offerId}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Metric for purchasing a catalog item; auto-reported on purchase. */
|
||||||
|
export function purchaseItem(itemId: string): string {
|
||||||
|
return `purchase.item:${itemId}`;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user