# Dynamic Payouts

Dynamic Payouts allow survey providers to offer variable rewards for completed surveys within a single session. DT adjusts payout amounts dynamically, which encourages users to complete multiple surveys and improves engagement and campaign performance.

## Setting Up a Dynamic Payout Campaign <a href="#h_01jgtty0mvm00bw3rpx7zyykpq" id="h_01jgtty0mvm00bw3rpx7zyykpq"></a>

To create a Dynamic Payout Campaign:

1. Create a [new campaign](https://docs.digitalturbine.com/dt-offer-wall/advertisers/acp-edge-advertiser-dashboard/campaign-setup).
2. Select **Survey Completion** from the **Campaign Type** drop-down list.
3. Select the **Dynamic payout enabled** checkbox in the **Budget** area.

<div align="left" data-with-frame="true"><img src="https://592572939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7drDlNSyycpmA7Zx8kgX%2Fuploads%2FTEJp4L43dewqWqeLIk9x%2F2025-01-05_11-09-10.jpg?alt=media&#x26;token=6e6624dc-5b65-4679-837e-37309f22d6d5" alt=""></div>

4. Enter the required values in the **Budget** and **Campaign Customizations** areas.

{% hint style="info" %}
The default bid set or micro-bidding bids must equal the total sum of the Advertiser's commission (their full payout).
{% endhint %}

5. Click **Next**.\
   The **Tracking** tab appears.
6. Copy the URL from the **Postback URL Template** field and incorporate it into your tracking provider, as described in [Generating and Implementing the Session Token (CPID)](#h_01fhczsferxhmd1z7v69axm9hc).

<div align="left" data-with-frame="true"><img src="https://592572939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7drDlNSyycpmA7Zx8kgX%2Fuploads%2F4bAzV6QYRcpgtY2wKibo%2F2025-01-05_12-33-40.jpg?alt=media&#x26;token=0d2aaafa-2540-4360-bded-d7829d825c96" alt=""></div>

{% hint style="info" %}
Dynamic Payouts allow the Advertiser to manage all surveys within a single campaign. You can include additional countries in the **Location Targeting** area on the **Targeting** tab and use [Micro Bidding](https://docs.digitalturbine.com/dt-offer-wall/advertisers/acp-edge-advertiser-dashboard/micro-bidding) to adjust your bids

The survey language updates automatically with the `[[CountryCode]]` macro when you enable localization.
{% endhint %}

## Generating and Implementing the Session Token (CPID) <a href="#h_01fhczsferxhmd1z7v69axm9hc" id="h_01fhczsferxhmd1z7v69axm9hc"></a>

The CPID (Conversion Postback ID) is a unique token that securely tracks survey completions in web campaigns. The CPID combines unique identifiers, applies a secure hash, and transmits the values through a postback URL.\
Follow these steps and refer to the required values to implement the CPID:

1. Navigate to **Account→Security Tokens** and copy the `Dynamic Payout Token` in the DT ACP Edge Console.

<div align="left" data-with-frame="true"><img src="https://592572939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7drDlNSyycpmA7Zx8kgX%2Fuploads%2FmGNYzyjWA2xVZmLef51K%2F2025-01-06_11-04-46.jpg?alt=media&#x26;token=52773362-4951-408f-9837-1bf92429b963" alt=""></div>

2. Concatenate the `ClickID` and the `Nonce`.\
   Ensure the `ClickID` appears first in the concatenation, followed by the `Nonce`.
3. Calculate the HMAC-SHA256 hash hexdigest of `ClickID`+`Nonce`, using the `Dynamic Payout Token` as the HMAC secret.
4. Use the hashed output as your `CPID`.
5. Send the `ClickID`, `Nonce` and the `CPID` parameters in the **Postback URL** callback.

**CPID Values**

| Value            | Description                                         | Postback Field          |
| ---------------- | --------------------------------------------------- | ----------------------- |
| `ClickID`        | Identifies the user's action or click event.        | `subid=`                |
| `Dynamic Payout` | 32 bytes of random data, hex-encoded.               | Not included in the URL |
| `Nonce`          | A random value generated uniquely for each request. | `nonce=`                |

### Ruby Example for Session Token <a href="#h_01jgtty0mvvekcs0yfrqf0gvta" id="h_01jgtty0mvvekcs0yfrqf0gvta"></a>

Step 1: DT creates the `Dynamic Payout Token`.

{% code title="Ruby" %}

```ruby
require 'securerandom'
advertiser_secret = SecureRandom.hex(32)
```

{% endcode %}

Step 2: The Advertiser creates a `CPID`.

{% code title="Ruby" %}

```ruby
#nonce can be created however you choose provided it's url safe
nonce = SecureRandom.urlsafe_base64(48)

require 'openssl'
cpid = OpenSSL::HMAC.hexdigest(
  OpenSSL::Digest.new('sha256'),
  advertiser_secret,
  "#{click_id}#{nonce}"
)
```

{% endcode %}

Step 3: Send `ClickID`, `Nonce`, and `CPID` as part of the callback.

{% code title="Ruby" %}

```ruby
uri = URI(
   "#{FYBER_URI}/actions/v2?#{query_params}" \
   "&subid=#{click_id}" \
   "&nonce=#{nonce}" \
   "&cpid=#{cpid}"
)
Net::HTTP.get(uri)
```

{% endcode %}

### Country Code Macro <a href="#h_01jgv2e9q1a5g2yw5a307ebzkx" id="h_01jgv2e9q1a5g2yw5a307ebzkx"></a>

Campaigns automatically translate based on the device's language and country code. For example, if `geo=US` (country code) and `lanuage=ES` (device language), the campaign and its description appear in Spanish (or the relevant language).

Use the `[[CountryCode]]` macro in your Click URL to include the country code and dynamically determine the campaign language on your platform or system.
