> ## Documentation Index
> Fetch the complete documentation index at: https://help.maestra.io/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Add a Game Mechanic with a Random Prize

A game pop-up — like a spin-the-wheel — lets visitors win one of several prizes in exchange for subscribing. Here's how to set up the form, store each win, and send customers the prize they got. You can use any set of prizes you like.

To launch the mechanic, you need to:

1. Create and start a form from a game mechanic template.
2. Create a custom field to store the win.
3. Set up a flow that issues and sends the prize.
4. Add a campaign that shows the win.

## Create the pop-up

[Create](https://help.maestra.io/personalization/pop-up-forms-and-embedded-blocks/how-to-create-pop-ups.md) a new pop-up. The mechanic needs a specific form — use the **With game mechanic** filter to find one.

## Pop-up settings

Open the template editor and adjust the pop-up's design to match your site.

### Prizes

Open the game element's settings and find the sector and probability settings.

1. Edit the set of prizes: remove or add prizes.
2. Click a prize to open its settings, and set:
   * The prize name or image.
   * **Win ID** — the prize name. The ID is passed to the action or the customer field and used to identify the prize in the flow. See [how data reaches your account](#set-up-data-transfer-to-your-account).
   * The text shown when the customer wins this prize.
3. Set the odds of each prize:
   * **Simple** — quickly spread the odds with chance levels. The percentages are **redistributed automatically** across the options.
   * **Enter as percentage** — set the exact percentage by hand.

> [!WARNING]
>
> This setting runs on the front end, so visitors can tamper with it through your site's code. We don't recommend using it to give away expensive or especially valuable prizes.

### Contact fields

Open the form element settings and choose the fields that ask for the customer's details, so you can send them the prize.

> [!WARNING]
>
> We don't recommend removing the contact fields entirely, to keep the form from being abused. Either way, the pop-up report is always built as a contact collection form report, even when these fields are missing.

### Targeting

Narrow the form's [targeting](https://help.maestra.io/personalization/pop-up-forms-and-embedded-blocks/how-to-configure-form-targeting.md) so it doesn't show on every visit. For the basic pop-up settings, see [How to create pop-ups](https://help.maestra.io/personalization/pop-up-forms-and-embedded-blocks/how-to-create-pop-ups.md).

## Set up data transfer to your account

Data transfer works as described in [How to pass form data to your account](https://help.maestra.io/personalization/pop-up-forms-and-embedded-blocks/how-to-pass-form-data-to-your-project.md).

First, add a [custom field](https://help.maestra.io/api-integrations/how-to-create-a-custom-field.md) to store the win. You can create it on the action or on the customer.

An action field has two advantages: a new value doesn't overwrite the previous win, so you keep the history of every play; and since customer custom fields get used more often, too many of them can clutter the interface.

> [tab] Through an action field
>
> 1. Create a custom field on the **Action** entity, with the *String* type.
> 2. In the pop-up's **Actions after the customer submits the form** settings, set it up to create a customer with a contact and to issue an action whose custom field stores the win:
>    * **Maestra field** — the action custom field you created earlier.
>    * **Form field** — *Result*.
>
> After playing, the customer gets a registration action and an action with the prize.

> [tab] Through a customer field
>
> 1. Create a custom field on the **Customer** entity, with the *String* type.
> 2. In the pop-up's **Actions after the customer submits the form** settings, set it up to create a customer with a contact and the field from step 1, and add an action:
>    * **Maestra field** — the customer custom field you created earlier.
>    * **Form field** — *Result*.
>
> After playing, the customer gets a registration action, and the prize is stored in their custom field.

## Issue and send the prize in a flow

The form is the game part of the mechanic. You set up issuing and sending prizes separately, in a flow.

The flow starts on the action that issues the prize. A **Condition** block then checks the prize (stored in the action's or customer's custom field), the flow issues the matching prize, and it sends a campaign.

Create these in advance:

* An [automated campaign](https://help.maestra.io/campaigns/email-campaigns/how-to-create-automated-email-campaign.md) to send the prize. You'll see how to show the win in it [below](#show-the-prize-in-a-campaign).
* [Promo code pools](https://help.maestra.io/loyalty/how-to-import-promo-codes-into-a-project.md). Prizes are issued as promo codes the customer can use as a benefit on their next purchase. Each prize type needs its own pool.

If you use other kinds of prizes, the flow setup may differ.

To set up the flow:

**1. Choose the trigger event**

Use the prize being issued as the trigger. Pick the action template from the pop-up.

**2. Check the win**

Check the win value with the [**Multibranches** mode](https://help.maestra.io/flows/how-the-multibranches-mode-work-in-the-condition-block-of-the-flow.md). Add every prize option exactly as written in the **Win ID**. The condition checks either the action field or the customer field, depending on where you pass the prize.

**3. Issue the prize and send the campaign**

Issue the matching prize and send the campaign.

**4. Repeat for every prize and start the flow**

Add a prize send for each prize option, then start the flow.

## Show the prize in a campaign

To show the prize in your email markup, use an [`if` block](https://help.maestra.io/campaigns/message-template-engine/adding-a-condition-ifelse-ifend-if): depending on the win value, it inserts a promo code from the right pool and the matching text.

For example, you want to show this message:

```
Use promo code PROMO to get PRIZE on your next purchase.
```

Here, `PROMO` is the customer's code and `PRIZE` is the prize type.

> [tab] Through an action
>
> Parameters:
>
> * `CustomerAction.CustomField.{Action_custom_field_system_name}.Name` — the prize won in the form, from the action's custom field.
> * `Recipient.LastReceivedPromoCode.{Promo_code_pool_system_name}.Value` — the customer's promo code from a specific pool.
>
> Example:
>
> ```
> Use promo code
>
> @{if CustomerAction.CustomField.Gift = "Discount 5"}
>     ${Recipient.LastReceivedPromoCode.WithTypePromoCodePool1.Value} to get 5% off
>
> @{else if CustomerAction.CustomField.Gift = "Shipping"}
>     ${Recipient.LastReceivedPromoCode.WithTypePromoCodePool2.Value} to get free shipping
>
> @{else if CustomerAction.CustomField.Gift = "Points 400"}
>     ${Recipient.LastReceivedPromoCode.WithTypePromoCodePool3.Value} to get 400 points
>
> @{else if CustomerAction.CustomField.Gift = "Points 500"}
>     ${Recipient.LastReceivedPromoCode.WithTypePromoCodePool4.Value} to get 500 points
>
> @{end if}
>
> on your next purchase.
> ```

> [tab] Through a customer field
>
> Parameters:
>
> * `Recipient.CustomField.{Customer_custom_field_system_name}` — the prize won in the form, from the customer's custom field.
> * `Recipient.LastReceivedPromoCode.{Promo_code_pool_system_name}.Value` — the customer's promo code from a specific pool.
>
> Example:
>
> ```
> Use promo code
>
> @{if Recipient.CustomField.Gift = "Discount 5"}
>     ${Recipient.LastReceivedPromoCode.WithTypePromoCodePool1.Value} to get 5% off
>
> @{else if Recipient.CustomField.Gift = "Shipping"}
>     ${Recipient.LastReceivedPromoCode.WithTypePromoCodePool2.Value} to get free shipping
>
> @{else if Recipient.CustomField.Gift = "Points 400"}
>     ${Recipient.LastReceivedPromoCode.WithTypePromoCodePool3.Value} to get 400 points
>
> @{else if Recipient.CustomField.Gift = "Points 500"}
>     ${Recipient.LastReceivedPromoCode.WithTypePromoCodePool4.Value} to get 500 points
>
> @{end if}
>
> on your next purchase.
> ```

Here's what the customer gets:

> Use promo code 1234ABCD to get 400 points on your next purchase.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.