OfferKitDocs

Target customers with rules

Target OfferKit vouchers and promotions with customer, cart, date, and request conditions, using only the data available to the decision being evaluated.

A validation rule turns a broad offer into a targeted one: VIP customers only, carts over a certain amount, a particular product in the cart, orders from the mobile app. OfferKit checks the rule at decision time and only returns a success when it passes.

Rules are JSON Logic expressions with a few OfferKit operators added. The dashboard has a visual builder for common conditions and a raw JSON editor for everything else.

Where rules are enforced

You can attach a rule to a campaign and to a promotion tier.

  • A campaign rule applies to every voucher and every promotion tier in that campaign.
  • A promotion tier rule applies to that tier, in addition to its campaign’s rule. Both must pass.
  • Vouchers do not have a rule of their own. To target one voucher differently, put it in its own campaign.

Rules are not evaluated anywhere else. Loyalty earning rules can store a validation rule ID, but earning never checks it, and loyalty rewards and referral programs have no rule setting. Every rule has an Applies to field (voucher, promotion, earn, reward). It is a label for organizing your rules and does not control where the rule runs.

Start from the business sentence

Write the policy in plain words first:

Take 15.00 off automatically when a VIP customer spends at least 100.00 in the mobile app.

Then list the facts the rule needs and where each one comes from:

FactWhere it comes fromRule variable
The customer is a VIPCustomer metadata you upsertcustomer.metadata.vip
The cart is at least 100.00The order you sendorder.amount
The order is from the appRequest metadata on promotion qualificationmetadata.channel

The resulting rule, attached to the promotion tier:

{
  "and": [
    { "===": [{ "var": "customer.metadata.vip" }, true] },
    { ">=": [{ "var": "order.amount" }, 10000] },
    { "==": [{ "var": "metadata.channel" }, "app"] }
  ]
}

You don’t need the currency or dates in the rule. The campaign already rejects orders in a different currency, and campaign and tier start and end dates handle the time window more clearly than a rule can.

A rule can only use what the decision can see. Request metadata exists only in promotion qualification, so this exact rule would never pass on a voucher. The next section shows what each decision can see.

What each decision can see

VariableVoucher validate, qualify, redeemPromotion qualifySegment preview
customer.id, .email, .name, .phoneYes, when a customer is identifiedYes, when customerId is sentYes
customer.address.*YesYesYes
customer.metadata.*YesYesYes
order.amount, order.currencyWhen you send orderYesNo
order.items[] (productId, collectionId, quantity, unitPrice)When you send order.itemsWhen you send order.itemsNo
metadata.* (request metadata)No, always emptyYes, from the request’s metadataNo, always empty
voucher.id, voucher.codeYesNoNo
now (current time, ISO 8601 UTC)YesYesYes
customer.summary.*Always emptyAlways emptyAlways empty
customer.segments, customer.loyalty.*Not setNot setNot set

Some notes on the table:

  • Identifying the customer. Voucher calls accept customerId or customerExternalId. Promotion qualification accepts only customerId, the internal UUID, so look it up or upsert the customer first. If the ID matches no customer, promotion rules are evaluated with no customer at all.
  • Two kinds of metadata. customer.metadata.region is metadata stored on the customer. metadata.channel is request metadata sent with promotion qualification. Metadata on campaigns, vouchers, tiers, and orders is not visible to rules.
  • Customer summary. Customers have a summary object with totalSpent, redemptionCount, and lastRedeemedAt, but OfferKit does not fill it in today and the customer API does not let you set it. Rules on customer.summary.* see nothing. If you need lifetime spend in a rule, keep it in customer metadata, for example customer.metadata.lifetimeSpend, and update it from your order system.
  • Stored orders. Rules see the inline order you send with the request. Passing an orderId does not load a stored order into the rule.

Prepare customer data

Use your stable user ID as externalId and keep targeting fields in predictable metadata:

await offerkit.customers.upsert({
  externalId: user.id,
  email: user.email,
  metadata: {
    vip: user.plan === "vip",
    region: user.region,          // "AE", "DE", ...
    lifetimeSpend: user.spendCents,
  },
});

Treat these field names and types as a contract. Changing region: "AE" to region: { code: "AE" } quietly changes what your rules match. So does sending vip: "true" instead of vip: true: a rule comparing with true no longer passes.

OfferKit operators

OperatorPasses whenNotes
{ "order.total_above": [10000, "USD"] }order.amount is greater than 10000Strictly greater. A 100.00 order does not pass total_above 10000. The currency is optional and, when given, must match the order
{ "order.contains_product": ["prod_123"] }Some item has that productIdExact match
{ "order.contains_collection": ["summer"] }Some item has that collectionIdExact match
{ "date.between": ["2026-11-01T00:00:00Z", "2026-11-30T23:59:59Z"] }now is within the rangeBoth ends included
{ "customer.in_segment": ["…"] }Never, in live decisionsSee Segments
{ "redemption.count_for_customer_above": [2] }Never, todayThe redemption count is not provided to rules, so it is treated as 0

The visual builder’s Order total above condition uses order.total_above, so it is strict too. For “at least 100.00”, write it in raw JSON:

{ ">=": [{ "var": "order.amount" }, 10000] }

The builder also offers Customer is in segment and Customer redemptions above. Neither works in live decisions today, as the table shows. For “a customer can only use this offer N times”, use the per-customer redemption limit on the campaign or voucher instead of a rule.

The builder’s Metadata field equals condition compares request metadata (metadata.<field>), which only promotion qualification has. To compare customer metadata, write the rule in JSON with customer.metadata.<field>.

Recipes

Customer metadata flag:

{ "===": [{ "var": "customer.metadata.vip" }, true] }

Region list:

{ "in": [{ "var": "customer.address.country" }, ["AE", "SA", "QA"]] }

Cart of at least 50.00 that contains a product:

{
  "and": [
    { ">=": [{ "var": "order.amount" }, 5000] },
    { "order.contains_product": ["prod_espresso_beans"] }
  ]
}

Staff email domain:

{ "===": [{ "substr": [{ "var": "customer.email" }, -12] }, "@example.com"] }

Lifetime spend over 500.00, kept in customer metadata by your application:

{ ">": [{ "var": "customer.metadata.lifetimeSpend" }, 50000] }

App-only automatic promotion (promotion qualification only):

{ "==": [{ "var": "metadata.channel" }, "app"] }

Send complete context

Voucher validation:

const result = await offerkit.vouchers.validate({
  params: { code },
  body: {
    customerExternalId: user.id,
    order: {
      amount: cart.totalMinor,
      currency: cart.currency,
      items: cart.items.map((item) => ({
        productId: item.productId,
        collectionId: item.collectionId,
        quantity: item.quantity,
        unitPrice: item.unitPriceMinor,
      })),
    },
  },
});

Promotion qualification, with request metadata:

const promotions = await offerkit.promotions.qualify({
  customerId: customer.id,
  order: { amount: cart.totalMinor, currency: cart.currency, items },
  metadata: { channel: "app" },
});

If an offer is meant for specific customers, make identifying the customer mandatory in that checkout flow.

Missing values fail quietly

A variable that is not there reads as null. A strict comparison with boolean true returns false, so a rule like { "===": [{ "var": "customer.metadata.vip" }, true] } simply fails when there is no customer or no vip field. That is the safe direction.

“Less than” does not fail safe. null counts as 0 in < and <=, so { "<": [{ "var": "customer.metadata.riskScore" }, 50] } passes when riskScore is missing. Pair it with a check that the field exists.

Negations also pass on missing data. { "!": { "var": "customer.metadata.blocked" } } passes when blocked is missing, including when no customer was identified at all. When you exclude people, also require that the customer exists:

{
  "and": [
    { "!!": { "var": "customer.id" } },
    { "!": { "var": "customer.metadata.blocked" } }
  ]
}

Segments

A segment is a saved customer rule. Preview runs it against up to the 10,000 most recently created customers and shows how many match, with a sample. Use it to check that your customer data says what you think it says before you launch.

Segments are not linked to campaigns, and live decisions never look up segment membership. customer.in_segment therefore never passes in a voucher or promotion decision. To target the audience a segment describes, copy its conditions into the campaign or tier rule.

Segment previews have no order, no request metadata, and no voucher, so a segment rule that uses order.* or metadata.* will not match anyone.

Test the boundary, not just the happy path

For every condition, try:

  • a value that passes and one that fails;
  • a missing value and a missing customer;
  • a value of the wrong type, such as "true" instead of true;
  • the exact boundary: an order of exactly 100.00 against both >= and total_above;
  • combined conditions with both and and or.

Keep these fixtures and rerun them whenever you edit a live rule. Rules reference lists every variable and operator.

Diagnose failures

A failed campaign rule on a voucher returns validation_failed. If the rule could not be evaluated, for example because it uses an operator that does not exist or the rule has been deleted, the explanation includes that detail.

Promotion qualification reports rule_failed when the rule evaluated to false and rule_error when it could not be evaluated or the rule is missing. Treat rule_error as a configuration problem to fix, not as an ineligible customer. In both cases the offer is not applied.