# Reward customers for every Nth purchase

> After you have created a loyalty program, you can define rules which allow you to use it as a counter. For example, you can use a loyalty program to count the number of purchases made by a customer.

> For the complete documentation index, see [llms.txt](https://docs.talon.one/llms.txt).

Let's set up a discount campaign. The objective is to reward customers with a 20% discount
for every fifth purchase they make. So, if a customer spends $200
on their tenth purchase, they are rewarded with a discount of $40.

To do this, let's create:

1. A [profile-based loyalty program](/docs/product/loyalty-programs/profile-based/create-pb-programs.md)
   to count the number of purchases per customer.
   :::important
   Before you create a loyalty program, [enable the loyalty feature](/docs/product/campaigns/settings/manage-campaign-features.md#enable-campaign-features)
   for your campaign.
   :::
1. A [promotion rule](/docs/product/rules/overview.md#promotion-rules) to use the loyalty
   program as a counter.
1. A promotion rule to verify if the customer
   purchase count is a multiple of 5 and to award a 20% discount on the session total.

## Use a loyalty program as a counter

In a [standard campaign](/docs/product/campaigns/overview#standard-campaigns), let's
[create a rule](/docs/product/rules/create-and-manage-rules.md#create-a-promotion-rule)
to count the number of purchases made by a customer. To do this, we count the number of
[closed sessions](/docs/product/applications/display-customer-sessions.md).

A session is closed when the customer completes the payment and places the order.
For each purchase the customer makes, we give them one point in the loyalty program.

Let's name the rule `Count number of purchases`. It has one condition and one effect.

### Rule 1: Condition

**Check for event types and custom event values:**
- **Event type** is `Customer Session Closing`.

### Rule 1: Effects

**Add loyalty points:**

- We select the **loyalty program** we have created. Let's imagine that it is
  called `Counter Program`.
- **Recipient** is `Current Customer`.
- **Reason** is `Count each purchase`.
- **Amount** of points is `1`.

## Verify purchase count and issue a discount

Let's build a second rule to verify if the customer is making their 5th, 10th, 15th... Nth
purchase. If they are, we issue a 20% discount on their session total.

Let's name the rule `Verify purchase and issue 20% off`. It has two conditions and one effect.

### Rule 2: Conditions

- **Check attribute value:**

  - Attribute is `Current Balance (Counter Program)`.
  - **Is equal to** `ROUND DOWN(Current Balance(Counter Program)/5)*5`.

- **Check attribute value:**

  - Attribute is `Current Balance (Counter Program)`.
  - **Is greater than** `0`.

## Rule 2: Effect

**Discount session total:**

- **Discount name** is `20% off`.
- **Discount value** is `[Session.Total]*20%`.

## Related pages

- [Display events](/docs/product/applications/display-events.md)
- [Create a point-based loyalty campaign](/docs/product/tutorials/loyalty/loyalty-points-program.md)
