# Incentivize share of product links

> Customers often share links to promoted products with their friends. When such a referral converts into a new sale, the customer and their friend receive benefits.

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

Let's imagine the products we're promoting are
a black leather jacket, a red hat, and a blue tie. Let's also imagine
the customer shares the product link by clicking a **Share** button on the ecommerce website.

We can [create a standard campaign](/docs/product/campaigns/create-and-manage-campaigns.md#create-a-campaign-from-scratch)
and [build promotion rules](/docs/product/rules/create-and-manage-rules.md#create-a-promotion-rule)
in such a way that:

1. When the customer shares any of the promoted products, we generate a referral code.
1. When the customer's friend redeems the referral code on their first purchase:
   1. They receive a 10% discount on their total cart value.
   1. We generate a coupon code for the customer.
1. When the customer redeems it on their next purchase,
they also receive a 10% discount on their total cart value.

:::note
The [**Referrals** and **Coupons** features](/docs/product/campaigns/settings/manage-campaign-features.md)
must be enabled.
:::

To achieve this, let's create the following:

1. A custom [event](/docs/dev/concepts/entities/events.md) to capture the sharing of the product link.
1. A [promotion rule](/docs/product/rules/overview.md#promotion-rules) to generate the referral code.
1. A promotion rule to redeem the referral code.
1. A promotion rule to redeem the coupon code from the referral.

## Share the product link

All incoming data in Talon.One is connected to an event.
Talon.One provides [default events](/docs/dev/concepts/entities/events.md)
to capture customer profile and session updates.

In our case, we want to capture the action of a customer sharing a product link
when they click a **Share** button on the ecommerce website.
Because this action is not related to a customer session or profile,
we cannot use a default event to capture this action.

Let's [create a custom event](/docs/dev/concepts/entities/events.md#create-an-event) instead.

- Associated entity: `Event`
- Event type: `URL Share`
- Attribute type: `String`
- API name: `url_share`
- Rule Builder name: `Sharing of Product Link`
- Rule Builder description: `This event records the sharing of a product link by a customer.`
- Available in our Application.

When the customer clicks **Share** on the leather jacket, the website sends a request to
the [Track event V2](/integration-api/#tag/Events/operation/trackEventV2) endpoint with
the following payload:

```bash
{
  "profileId": "{{Integration_id}}",
  "type": "URL Share",
  "attributes": {
    "url_share": "jacket012345" // the SKU of the product that was just shared
  },
  "responseContent": [
    "triggeredCampaigns",
    "customerProfile"
  ]
}
```

## Generate a referral code

Let's open the Rule Builder to [build our first rule](/docs/product/rules/create-and-manage-rules.md#create-a-promotion-rule).
In the Rule Builder, we can do the following:

1. List the SKUs of the promoted products
   by [creating a collection](/docs/product/rules/manage-collections.md#create-a-campaign-level-collection)
   and naming it `promoted_sku_list`.

1. Create a rule so that Talon.One generates a referral code only when the link shared
   by the customer belongs to one of our promoted products.

   - The generated referral code has a redemption limit of `1000`.
   - Name the rule `Generate referral code on product share`. It has one condition and one effect.

### Rule 1: Condition

**Check for event types and custom event values:** **Event type** is `url_share`
and `Sharing of Product Link` **is in collection** `"promoted_sku_list"`.

### Rule 1: Effects

- **Create referral code:** `In the current campaign` and **Redemption limit** is `1000`.
- **Display an Info notification to your user, with the title:** **Type** is `Info`,
  **Title** is `Your referral code!` and **Message** is `The referral code for your friend
  is [GeneratedReferral]`.

## Redeem the referral code

To find potentially discounted products by their SKU, let's
apply a [cart item filter](/docs/product/rules/cart-item-filters/overview.md)
on the received sessions.
This step ensures that the referral works only for our promoted products.
Let's name the filter `promoted_products`.

- **Customer's cart items (Current Session):** **Condition** is `SKU of item (Item)`
  and **is in collection** is `promoted_sku_list`.

We can now build our second rule, which applies to the friend redeeming the referral code.
It checks if the code is valid and if the friend has made any previous purchases.
We want the referral offer to apply only to new customers who are making their first purchase.

Let's name the rule `Redeem the referral code`. It has two conditions and two effects.

### Rule 2: Conditions

- **Referral code is valid**
- **Check attribute value:** `Closed sessions (Customer Profile)` **is equal to** `0`

### Rule 2: Effects

- **Discount individual items: List of items** is `promoted_products`,
  **Discount name** is `10% off per promoted product` and **Discount Value** is
  <Attribute name="Item.Price" type="builtin" />`* 10%`.
- **Create coupon code:** `In the current campaign`, **Recipient** is `Advocate`
  and **Redemption Limit** is `1`.

## Redeem the coupon code from the referral

Our third rule applies to the customer, who redeems the coupon code from the referral.

Let's name the rule `Redeem coupon code from referral`. It has one condition and one effect.

### Rule 3: Condition

**Coupon code is valid**.

### Rule 3: Effect

**Discount session total:** **Discount name** is **"10% off"** and **Discount Value** is
`[Session.Total] * 10%`.

## Related pages

- [Create a basic referral campaign](/docs/product/tutorials/referrals/basic-referral.md)
- [Create a referral code](/docs/product/rules/effects/use-effects.md#create-a-referral-code)
