Skip to main content
Tags, counters, attributes, and tiers store state on participants, programs, and groups. Rules read this state in CEL conditions and update it through actions. Tiers are covered in their own guide. See Tiers for qualification, retention, and downgrade policies. Ledger balances are separate from state, but conditions can read them through participant.balance.<symbol>. See CEL expressions.

Update state with one request

Use PATCH /v1/participants/{participant_id} and PATCH /v1/groups/{group_id} to change tags, attributes, and counters from your application. One request can change all three, along with profile fields and status. Scrip applies every change in the request together or none of them. Programs keep their state through rules only.
Removing a key that does not exist succeeds and changes nothing, so you can retry a removal safely. An increment adds again every time you send it. To retry one safely, send an Idempotency-Key header: a repeat with the same key returns the first response and changes nothing. Counters need an ACTIVE participant. The response is 200 with the full participant. These are its state fields after the request above, for a participant with no earlier state:
Counter values come back as strings, and tags come back in alphabetical order. tags, attributes, counters, and counter_settings are always on the participant and group detail, so a read is GET /v1/participants/{participant_id} or GET /v1/groups/{group_id}.

Tags

Boolean flags. A tag either exists on an entity or it doesn’t. Useful for one-time gates, status markers, and segmentation labels. Tags are a list on the participant or group. To add vip, send the full list with PATCH:
Send an empty list to remove every tag. Read the current list from the tags field of GET /v1/participants/{participant_id}. To show a tag as a badge, with a label and an icon, give it display fields. Tags are trimmed and de-duplicated on write, stored verbatim, and matched case-sensitively in CEL: "VIP" and "vip" are different tags. Pick one casing convention, such as lowercase, and use it consistently.

Using tags in conditions

Setting tags from rules

The TAG action adds a tag and UNTAG removes one. Both apply to the event’s participant by default. This rule grants a one-time welcome bonus and tags the participant to prevent re-triggering:
Use UNTAG to remove a tag when a condition is no longer met. This rule removes a promotional flag when the promo period ends:
To tag or untag a different entity, add a target:

Counters

Numeric accumulators stored as high-precision decimals and exposed as numbers in CEL expressions. Choose one of four time behaviors depending on how the total should accumulate: Set, increment, or remove counters in the counters map of a PATCH:
set replaces the value and the last write wins. increment adds atomically, so concurrent writers never lose updates, and a negative amount subtracts. Sending null for a key removes the counter. Read counters from the counters field of the participant, and each counter’s reset setting from counter_settings.

Using counters in conditions

Prefer the dot-access shorthand: a missing counter defaults to 0, so no get() is needed:

Updating counters from rules

The COUNTER action adds its value to the current value. This rule tracks purchase count and lifetime spend on every purchase:
If a participant has purchase_count: 7 and lifetime_spend: 340.00, and a purchase event arrives with event.amount: 49.99, after this rule fires:
  • purchase_count becomes 8
  • lifetime_spend becomes 389.99
The value field accepts static values ("1") or ${{ }} CEL expressions ("${{ event.amount }}"). To replace the value instead of adding to it, set operation to SET:
Every rule condition and action expression in an event reads participant, group, and program state as it was when processing started. A change a rule makes shows in the next event, not in later rules or actions of the same event. See State snapshot evaluation.

Auto-resetting counters

A counter can reset to 0 on its own after a set time. Set reset_after in the counter’s PATCH entry. It takes a duration such as 30d or 24h; see Durations for the units. For a total per calendar day, week, or month, use a calendar counter instead. For a rolling total, such as the last 12 months, use a counter window.
Each participant’s counter has its own reset window. The window starts on the first write that sends reset_after, whether you send it with set, with increment, or alone. Later writes can repeat the same duration or leave it out. Neither moves the start of the current window. 30d and 720h are the same duration. A different duration starts a new window from that request. When the window runs out, the counter reads 0. The next write to the counter starts a new window, so an increment counts up from 0. To change the duration and keep the value, send reset_after alone:
To remove auto-reset, send reset_after as an empty string. Leave reset_after out to keep the current window. The participant’s counters map shows the current value, which is 0 once the window has run out. counter_settings shows each auto-reset counter’s reset_after in hours or minutes (30d reads back as 720h) and last_reset_at, the time its current window started. A COUNTER action can send reset_after too, with the same window rules. A rule that sends the same duration on every run keeps the current window and does not extend it. This spin count resets 24 hours after the first spin, and the first spin after that starts a new 24-hour window:

Calendar counters

A calendar counter keeps a separate total for each day, week, or month. Set reset_period in place of reset_after:
timezone is an IANA time zone name, such as America/Chicago. Each period starts at local midnight in that zone and follows its daylight saving changes. Leave timezone out for UTC. A new period starts at 0, so nothing has to run at the boundary. A rule writes to the period that contains the event’s event_timestamp, the time CEL reads as now, not the time Scrip processes the event. Rule conditions read that same period. A March 31 purchase that arrives on April 2 adds to March’s total and leaves April’s alone. It does not rerun later events or change the rewards they already earned. Everything outside rule conditions and actions reads the current period: the counters map, participant list filters, automation thresholds, and tier qualification. A tier with PERIODIC retention is the exception: it uses how much was added to the counter during the tier’s own periods. A PATCH with set or increment writes the current period. The setting belongs to the counter on that participant or group, across all of its programs. Leave reset_period out of later writes to keep it: In this table, the period is the current one for a PATCH and the event’s period for a rule. counter_settings shows each calendar counter’s reset_period, with timezone set to UTC when you left it out. A calendar counter has no reset_after or last_reset_at:
A COUNTER action takes the same reset_period. This rule totals each participant’s spend per calendar month in Chicago:
A condition such as participant.counter.monthly_spend >= 2500.0 then reads the total for the event’s month. See the spend threshold pattern for a complete program. To compare dates in a condition, use the calendar helpers.

Counter windows

A counter window keeps a rolling total, such as spend over the last 12 months. Declare window once on the counter’s entry in state_definitions during a rule-configuration preview and apply:
Rules write spend_12m with a normal COUNTER action and no reset_period or reset_after fields. The value of spend_12m is the total of one month plus the 11 months before it. Which month the window ends in depends on the reader: unit is DAY (up to 90), WEEK starting Monday (up to 52), or MONTH (up to 36); omit timezone for UTC. A tier with PERIODIC retention ignores the window. To qualify a tier on the last 12 months, set the period on the tier and use a counter with no window. See Periods.
  • Constraints: Add a window only to a counter key that has no existing values on any participant, group, or program (409 counter_window_has_values). Saved windows cannot change or be removed; create a new counter key for a different window. Rules writing a windowed counter cannot send reset_period or reset_after (409 counter_window_rule_policy / 400 counter_has_window).
  • Period writes: Rules write to the period of event_timestamp; PATCH writes to the current period (SET replaces only that period). Old periods drop out automatically when they leave the window. counter_settings shows window in place of reset_period.

Attributes

Key-value strings for arbitrary metadata. Useful for segmentation, preferences, and profile data referenced in rules. Attributes are a merge patch. Keys you send are set, keys you leave out keep their value, and a key sent as null is removed:
Read attributes from the attributes field of the participant.

Using attributes in conditions

Setting attributes from rules

The SET_ATTRIBUTE action sets a key-value pair on the event’s participant. Unmarked values are always stored as literal strings: "high" is stored as the text high. For dynamic values, wrap CEL in ${{ ... }}: "value": "${{ event.category }}" stores the evaluated result.

Display fields

A counter’s or tag’s state definition can carry display metadata that your app uses to render it, such as showing a tag as a badge. Display fields do not affect rule evaluation and apply across your organization for a given scope, kind, and key.

Set display fields

Send the fields to the definition’s path (scope is participant, group, or program; kind is counter or tag):
PUT replaces all four fields (omitted optional fields are cleared) and returns 200 with the saved definition. You can also set description, icon_url, and category inside state_definitions during a rule-configuration apply (which merges omitted fields).
PUT /v1/state-definitions/... creates a tag definition automatically if none exists. A counter must already have a saved definition from a rule-configuration change (which supplies its unit), or PUT returns 404 state_definition_not_found.

List the badges

GET /v1/state-definitions lists definitions (filtered by scope, kind, or category, sorted by scope, kind, key). Counter definitions also include unit and window:

Show earned badges

Pass expand[]=tag_details when reading a participant to include each earned tag’s display fields and added_at timestamp (tags without a definition return only key and added_at):
Filter tag_details by category: "badges" to render earned badges. Because expand[] selects optional sections, include programs, tiers, or balances in expand[] if you also need them. The event.completed webhook includes label and category on each added or removed tag so you can announce badges without a follow-up read.

Program and group state

Programs and groups support the same state types as participants. Access them in CEL via program.* and groups[*].*. Update group state with PATCH /v1/groups/{group_id}, which takes the same tags, attributes, and counters fields.
To update program or group state from a rule, add a target to the action:
Because the rule that reads total_claims also writes it, concurrent claims from different participants cannot pay out more than 1,000 times. See Shared program and group state.

State history

Scrip records every change to tags, counters, attributes, and tiers. Query the history to see what changed, when, and what made the change:
state_type is TAG, COUNTER, ATTRIBUTE, or TIER. operation is SET when a value is written, DELETE when a key is removed, and AUTO_RESET when a counter’s reset window ran out. An AUTO_RESET entry appears the next time the counter is written. An entry for a calendar counter carries counter_period, with the type, the timezone, and the period’s UTC start (inclusive) and end (exclusive). When a change of reset_period resets a nonzero value to 0, that entry has no counter_period. For a counter with a window, old_value and new_value are window totals. Its counter_period adds window_count and the changed period’s own totals in period_old_value and period_new_value. A change made by a rule carries the event_id and rule_id that caused it, and rule_name, the rule’s current name. A change you make with PATCH carries none of them. Tier entries also carry program_id. A group’s history is at GET /v1/groups/{group_id}/activity/state-history.

State updates on inactive participants

You can change tags and attributes through the API while a participant is ACTIVE or SUSPENDED. For a CLOSED participant, reactivate them first or in the same request. Counter changes need an ACTIVE participant; otherwise they return 409 participant_inactive. Rule actions follow different status rules. See Allowed actions by status for every operation.

Tiers

Levels that advance on counter thresholds.

Groups

Shared balances and group state.

State actions

Every field of TAG, COUNTER, and SET_ATTRIBUTE.