@grainql/analytics-web). Grain Tag has
no remote configuration. Read Remote configuration for the cache-first
flow.
The two inputs
A rule reads properties from two places.setProperty converts every value to a string. The properties option accepts only strings
(Record<string, string>), so convert a number with toString() before you pass it. Rules
compare strings. Read User properties.
Set the user ID before you set properties, so that the properties attach to the right user.
setUserId.
A message by plan
The rule reads one property and returns one string per plan.hero_message with the default value Welcome. Then add one
rule per plan: if plan equals premium, return Welcome back, premium member. A user with no
matching rule receives the default.
A price by country
Two keys share the same property. Each key has its own rules.country equals US, currency returns $ and monthly_price
returns 29. If country equals GB, currency returns £ and monthly_price returns 24.
The price is a string. Parse it before you compute with it.
A tutorial by login count
A computed number goes in the request as a string. The rule compares it as a number.login_count is less than 5, show_tutorial returns true. The
default value is false.
Feature access by plan
The value is not a flag but a label, so the code can show a different state for each label.plan equals premium or enterprise, analytics_access returns
granted. The default value is denied. Read Feature flags for the
flag form of this pattern.
Rules for the client
- Set a default value for every personalized key. A user with no matching rule, and a client with no response yet, both receive the default.
- Send only the properties that a rule reads. A property that no rule reads has no effect on the value.
- Send only properties that the user consented to. Read Privacy and consent.
- Test every rule with one user per branch: one per plan, one per country, one per side of a numeric limit.
- To measure whether a personalized value converts better than the default, run it as an A/B test. Read A/B tests.