# Wix Integration

The Gamopanda Wix app adds three **Wix Flow actions**, two **Wix Triggers** and a **Embedded Script** to your store. Automation actions let you trigger streak and challenge progress from any Wix automation triggers — order paid, order fulfilled, checkout completed, loyalty event — without writing backend code. The Embedded script loads the Gamopanda loyalty widget directly into your storefront, surfacing progress and rewards to logged-in customers in real time.

---

## Installation

Install the Gamopanda app from the Wix App Store. Once installed, the triggers such as order_paid and order_fulfilled and actions such as Execute Streak, Execute Challenge, and Update Reward Log are immediately available in Wix Automations and Gamopanda configuration page is available under Manager Apps section.

---

## Floating widget

The Gamopanda **Embedded Script** embeds the loyalty widget into your storefront. It handles customer authentication automatically and renders the floating widget on every page where it is active.

### Adding the Gamopanda Embedded Script requires fields such as Account Id, Template Id, Theme Id, and Floating Widget Id to be configured.

1. In your Wix admin, go to **Apps → Gamopanda Configuration**.
2. Configure the screen (see [Settings](#widget-settings) below).
3. Save your configuration and the floating widget will be visible on the website for your customers to see.

#### Embedded Script block configuration

![Embedded Script Configuration in the Wix Apps menu showing Account Id, Template Id, Theme Id, and Floating Widget Id fields](/wix-embedded-script-configuration.png)

---

### Widget settings

Configure the widget appearance and behaviour by entering the IDs from your Gamopanda dashboard:

| Setting | Description |
|---|---|
| **Account Id** | The account Id which needs to be integrated.
| **Template Id** | Controls the widget's copy and localisation. Find this in **Gamopanda → Templates**. See [Template](/template) for field details. |
| **Theme Id** | Controls the widget's colours and typography. Find this in **Gamopanda → Themes**. See [Theme](/theme) for field details. |
| **Floating Widget Id** | Controls the launcher button style and position. Find this in **Gamopanda → Floating Widgets**. See [Floating Widget](/floating_widget) for field details. |

All four fields are compulsory.

---

### How authentication works

The embedded script detects whether a customer is logged in and handles authentication accordingly:

**Logged-in customers**
The embedded script calls the Gamopanda API server-side and fetches the user `accessToken`. The widget is initialised with the `accessToken`, giving the customer full access to their progress, milestones, and rewards.

**Guest visitors**
If no customer is logged in, the widget is initialised without an `accessToken`. The widget renders in guest mode — public content (e.g. how the programme works, available streaks and challenges) is visible, but personal progress is not shown until the customer logs in.

The locale of the storefront (`document.documentElement.lang`) is passed automatically — no extra configuration needed for multilingual stores.

---

### Rendered widget

#### Floating widget on storefront
![Floating Widget on Storefront](/floating-widget.png)

#### End User Display on storefront (logged-in customer)
![Logged In End User Display on Storefront](/loggedin-eud.png)

#### End User Display on storefront (guest visitor)
![Logged Out End User Display on Storefront](/loggedout-eud.png)

---

## Flow actions

### Execute Streak

**Logs a customer activity event that contributes to a streak.** Use this action in any Flow that tracks repeating behaviour — daily purchases, weekly visits, monthly workouts.

Internally, this action calls `POST /schema/streak_log/record` on your customer's behalf. See [Streak Logs](/streak-log) for field details.

#### Action fields

| Field | Required | Description |
|---|---|---|
| Contact Id | ✅ | The Wix customer performing the activity. Resolved to a Gamopanda member automatically. |
| Streak Id | ✅ | The ID of the Gamopanda streak to log against. Found in your Gamopanda dashboard. |
| Activity Id | ✅ | The type of activity — e.g. `order_paid`, `visited_store`. |
| Activity Value | ✅ | The numeric value of the activity. Use `1` for `count` streaks. For `sum` streaks, pass the relevant value (e.g. order total). |
| Activity At | ✅ | The datetime the activity occurred. Used to determine the aggregation period. |
| Unique Identifier | The idempotency key so that duplicate requests are rejected. |

#### Action output

The action returns the created `StreakLog` record along with `streakProgress`, `achievedMilestone`(if any), `nextMilestone`(if any), `taskProgress` for the current period and `achievedMilestoneRewardLog`. You can use these output fields in downstream Flow steps. See [Streak Logs](/streak-log) for field details.

:::tip
Use the `achievedMilestoneRewardLog.id` output to chain directly into the **Update Reward Log** action — no extra lookup needed.
:::

#### Execute Streak Flow Action
![Execute Streak Flow Action](/execute-streak-wix-action.png)

---

### Execute Challenge

**Logs a customer activity event that contributes to a challenge.** Use this action to track cumulative progress toward a spend, visit, or activity target — for example, a monthly $500 spend challenge.

Internally, this action calls `POST /schema/challenge_log/record` on your customer's behalf. See [Challenge Logs](/challenge-log) for field details.

#### Action fields

| Field | Required | Description |
|---|---|---|
| Contact Id | ✅ | The Wix customer performing the activity. Resolved to a Gamopanda member automatically. |
| Challenge Id | ✅ | The ID of the Gamopanda challenge to log against. Found in your Gamopanda dashboard. |
| Activity Id | ✅ | The type of activity — e.g. `order_paid`, `order_created`. |
| Activity Value | ✅ | The numeric value of the activity. Use `0` for `count` challenges. For `sum` challenges, pass the spend amount, step count, or other measurable value. |
| Activity At | ✅ | The datetime the activity occurred. |
| Unique Identifier | The idempotency key so that duplicate requests are rejected. |

#### Action output

The action returns the created `ChallengeLog` record along with `challengeProgress`, `achievedMilestone`(if any), `nextMilestone`(if any) for the current period and `achievedMilestoneRewardLog`. You can use these output fields in downstream Flow steps. See [Challenge Logs](/challenge-log) for field details.

:::tip
Connect the `achievedMilestoneRewardLog.id` output directly to the **Update Milestone Reward Log with Coupon** action to issue a coupon in the same Flow, with no additional API calls.
:::

#### Execute Challenge Flow Action
![Execute Challenge Flow Action](/execute-challenge-wix-action.png)


---

### Update Reward Log

**Stamps a coupon code and issuance timestamps onto a Reward Log.** Use this action immediately after **Execute Streak** or **Execute Challenge** detects a milestone crossing — it fulfils the reward by writing the coupon code back to the Reward Log record.

#### Action fields

| Field | Required | Description |
|---|---|---|
| Reward Log Id | ✅ | The ID of the Reward Log to update. Use the `achievedMilestoneRewardLog.id` output from **Execute Streak** or **Execute Challenge**. |
| Coupon Code | ✅ | The discount code issued to the customer. Generate this via Wix's built-in **Add a Coupon** action before this step. |
| Reward Issued At | ✅ | The datetime the reward was issued. |
| Reward Expiry At | ✅ | The datetime the reward expires. |

#### Typical Flow pattern

```
Trigger: Order paid
  → Execute Streak / Execute Challenge
    → Condition: achievedMilestoneRewardLog.id is not empty
      → Create Discount Code (Wix native)
        → Update Reward Log with Coupon
```

#### Update Milestone Reward Log with Coupon Flow Action
![Update Milestone Reward Log with Coupon Flow Action](/update-reward-log-wix-action.png)

---

| Resource | Description |
|---|---|
| [Streak](/streak) | Configure the streaks your Flow actions log against |
| [Challenge](/challenge) | Configure the challenges your Flow actions log against |
| [Milestone](/milestone) | Reward checkpoints that trigger the reward log |
| [Reward Log](/reward_log) | The reward record updated by **Update Milestone Reward Log with Coupon** |
| [Template](/template) | Widget copy and localisation settings |
| [Theme](/theme) | Widget visual styling |
| [Floating Widget](/floating_widget) | Launcher button configuration |
