Overview
In this quick start guide we’ll demonstrate how to gate access to features. The functionality that’s included in each plan is defined by a combination of features and their configuration, referred to in Stigg as entitlements.Before we begin
In order to complete this guide in your application code, please make sure that you have:Initializing the client SDK
The first step is to initialize Stigg’s client SDK with the publishable key of the environment that’s integrated with Stigg, and the ID of the relevant customer. The customer ID can usually be retrieved after a customer signs-in or restores their session.TypeScript
Checking whether the customer can access the feature
Gating a metered feature is a 3-step flow: check, gate, and report usage. Doing these in order — and only reporting usage after the action actually happens — is what keeps access checks accurate, especially on features with a small or hard usage limit.1. Check
Retrieve the customer’s entitlement for the feature using the feature ID that’s defined in Stigg. Passoptions.requestedUsage set to the exact amount the customer is about to consume — this evaluates the check against that specific amount before it’s used, rather than against a possibly-stale currentUsage.
TypeScript
This example demonstrates a customer’s attempt to use 3 birds of their quota at once.
2. Gate
UsehasAccess on the result to decide whether to allow the action. Only proceed with the action if hasAccess is true — don’t perform the action first and check afterward.
TypeScript
3. Report usage
Only report usage for actions the customer actually performed — after step 2 has allowed them through, and after the action has completed. Usage reporting is a backend operation, so it’s done through a backend SDK or the Report Usage API, not the client SDK used for the check above.Node.js (backend)
Report usage exactly once per action, for the amount actually consumed. Reporting more than once for the same action, or reporting before the action completes, will overstate usage and can cause access to be denied earlier than expected. If the action fails or is rolled back, don’t report usage for it.
