Resources

Counters

Counters are integer-based values stored for account-specific statistics. (For instance, tracking how often an account uses a feature.)


How it works

Counters are defined in the Backstack dashboard and transactions are implemented in your application codebase. The current session.account.counters[id] contains an aggregate of the transacted values.

Counters can be configured to be time-based, allowing for aggregate totals for the past n days.


Codebase implementation

Initiate a counter on events you want to track for future usage assessment.

// pseudocode

if(session.account.counters.foo-downloads === 10)
  <button>Get More Foos</button>
else
  <button onClick="downloadFoo()">Download Foo</button>
  
function downloadFoo() {
  const result = await processDownload('Foo');
  if(result.success) {
    updateFooDownloads(1);
  }

Request

The updateFooDownloads() in the example code above would update the counter.

POST /v1/account/counters
{
  "id": "foo-downloads"
}
ParameterTypeDescription
idRequired stringThe counter ID.
integerOptional integerA positive or negative integer (e.g. 12345) you want added to the existing total. If empty the value of 1 will be used.

Response

The Session object is updated with the counter total value.

// session object
{
  ...
  "account": {
    "counters": {
      "foo-downloads": 1,
      ...
    }
    ...
  }
}

Subtracting values

Use negative integers to offset existing values.

POST /v1/account/counters
{
  "id": "foo-downloads",
  "integer": -1
}

Resetting counters

Post an action with the value reset to reset a counter value to zero.

POST /v1/account/counters
{
  "id": "foo-downloads",
  "action": "reset"
}
Previous
Account Stats