---
updatedAt: 2026-09-22T09:42:10.000Z
---

# Smart script for PC, console, and Steam

Smart Script can generate direct click URLs that redirect users to non-mobile stores, where they can download, install, or purchase PC, CTV, or console apps.

This is a different flow from the mobile setup in [OneLink Smart Script V2](https://dev.appsflyer.com/hc/docs/dl_smart_script_v2). The mobile flow calls `generateOneLinkURL` and returns a OneLink URL that leads to the app store. The CTV, PC, and console flow described here calls `generateDirectClickURL` and returns a direct click URL that redirects straight to the platform-specific storefront you specify.

**Prerequisites**

* The platform value for each storefront you're integrating (see the supported list below).
* The `app_id` and `redirectURL` for each platform's storefront.

## Implementation steps

### Create a direct click URL

To create a direct click URL, follow these steps:

1. [Download the Smart Script](https://onelinksmartscript.appsflyer.com/onelink-smart-script-latest.js).
2. Get the arguments to call the script, mapping the incoming parameters to the marketer's parameters.
3. Initialize the Smart Script [arguments](#arguments) and [configuration objects](https://dev.appsflyer.com/hc/docs/onelink-smart-script-v2web-to-app-url-generator#configuration-object) as in the following example:

   ```jsx
   var mediaSource = { keys: ["my_media_source"], defaultValue: "my_default_media_source" };

   var campaign    = { keys: ["my_campaign"],     defaultValue: "my_default_campaign" };
   ```
4. Generate the URLs by calling the script in your web or landing page HTML, using the following method:

   ```jsx
    var result = window.AF_SMART_SCRIPT.generateDirectClickURL({
      afParameters: afParameters,
      platform: platform.platformName,
      app_id: platform.appid,
      redirectURL: platform.redirectURL,
    })
   ```
5. Check the return value in `result`. Possible return values are:

   * An outgoing Direct URL (`https://engagements.appsflyer.com`). For additional Direct URL examples, see the demo page below. Use the `result` value as needed, for example, to place it as a link under a call to action (CTA) on your website.
   * A `null` value. If the script returns `null`, implement your error-handling flow. For example, when the existing URL of the web or landing page is not changed.

   For example:

   ```javascript
    //In  itializing Smart Script arguments
    // If a media source key is NOT FOUND on the link and NO default value is found, the script will return a null string 
    var mediaSource = {keys: ["my_media_source"], defaultValue: "my_default_media_source"};
    var campaign = {keys: ["my_campaign"], defaultValue: "my_default_campaign"};

    //Calling the function after embedding the code will be through a global parameter on the window object called window.AF_SMART_SCRIPT
    //Onelink URL is generated

    var result = window.AF_SMART_SCRIPT.generateDirectClickURL({
      afParameters:{
        mediaSource: mediaSource,
        campaign: campaign
      },
      platform: 'steam',
      app_id: '123456',
      redirectURL:'https://store.steampowered.com/app/123456/Team_Fortress_2/'
    })

    var result_url = "No output from script"
    if (result) {
      result_url = result.clickURL;            
    }
   ```

   See [example](https://appsflyersdk.github.io/appsflyer-onelink-smart-script/examples/direct_click.html?incmp=gogo\&inmedia=new_source) of the conversion of an incoming URL to an outgoing direct click URL for a Steam game.

<Callout icon="📘" theme="info">
  ### Note

  In order to ensure incoming URL parameters will be mapped to the generated outgoing URL, it is recommended to import the Smart Script in every website page, whether an outgoing URL is generated in the page or not.

  For more information and a full example, see [here](https://dev.appsflyer.com/hc/docs/dl_smart_script_v2#preserve-incoming-url-parameters-across-pages).
</Callout>

6. Validate the generated URL using the [Direct Click URL test page](https://appsflyersdk.github.io/appsflyer-onelink-smart-script/examples/direct_click.html), editing the input URL and confirming the output resolves to the correct platform's storefront.

### Enable deterministic PC attribution

Deterministic PC attribution lets you attribute installs and events on PC destinations by carrying AppsFlyer attribution parameters through the direct click URL beyond the final landing page. When a user clicks, the Engagements API logs the click, generates a referrer ID, and redirects (HTTP 302) to your `redirectURL` with the referrer ID appended as a query parameter.

To enable it:

1. Add `af_generate_referrer` as a custom parameter inside `afParameters.afCustom`, with `keys: []` so the value is always forced:

```jsx
   var mediaSource = {keys: ["my_media_source"], defaultValue: "my_default_media_source"};
   var campaign = {keys: ["my_campaign"], defaultValue: "my_default_campaign"};

   var af_generate_referrer = {
     paramKey: "af_generate_referrer",
     keys: [],
     defaultValue: "true"
   };

   var result = window.AF_SMART_SCRIPT.generateDirectClickURL({
     afParameters: {
       mediaSource: mediaSource,
       campaign: campaign,
       afCustom: [af_generate_referrer]
     },
     platform: 'steam',
     app_id: '123456',
     redirectURL: 'https://store.steampowered.com/app/440/Team_Fortress_2/'
   });
```

2. On the landing page (where `redirectURL` points), read the referrer ID from the URL's query parameters.
3. In your download or packaging pipeline, attach the referrer ID to the game package before serving it.
4. In the game's first-launch (first open) event, send the referrer ID back to AppsFlyer.

<Callout icon="🚧" theme="warn">
  ### Required: set af_generate_referrer to true

  `af_generate_referrer` must be set to `true`, and `redirectURL` must be provided, since the referrer ID is appended to that URL. Without both, the referrer ID isn't generated.
</Callout>

### Create a QR code with the Smart Script result

The `displayQrCode` method works the same way for direct click URLs as it does for mobile OneLinks. For setup steps, see [Create a QR code with the Smart Script result](https://dev.appsflyer.com/hc/docs/dl_smart_script_v2#create-a-qr-code-with-the-smart-script-result) in the mobile article.

### Fire an impression

`fireImpressionsLink` works the same way for direct click URLs as it does for mobile OneLinks. For setup steps and the cross-platform example, see [Impressions, OneLink template with cross-platform support](https://dev.appsflyer.com/hc/docs/dl_smart_script_v2#impressions----onelink-template-with-cross-platform-support) in the mobile article.

## Arguments

<HTMLBlock>{`
<table class="table--hover table--striped table--color-header unsortable" style="height: 532px; width: 842px;">
  <thead>
    <tr style="height: 40px;">
      <th style="width: 272.312px;" colspan="2">Argument</th>
      <th style="width: 291.5px; height: 40px;">Remarks</th>
      <th style="width: 268.188px; height: 40px;">Example</th>
    </tr>
  </thead>
  <tbody>    
    <tr style="height: 19px;">
      <td style="width: 119.953px;" rowspan="6">
        <p>afParameters</p>
        <p>(required)</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <span style="font-weight: 400;"><br></span>
      </td>
      <td style="width: 133.359px; height: 19px;">
        <p>mediaSource</p>
        <p>(required)</p>
      </td>
      <td style="width: 283.5px; height: 19px;">
        <p>Configuration object for media source</p>
      </td>
      <td style="width: 260.188px; height: 19px;">
        <ul>
          <li>Keys: ['incoming_mediasource’' 'utm_source']</li>
          <li>
            Override values: {twitter: 'twitter_int', orig_src: 'new_src'}
          </li>
          <li>Default value: ['any_source']</li>
        </ul>
      </td>
    </tr>
    <tr style="height: 40px;">
      <td style="width: 133.359px; height: 40px;">
        <p>campaign</p>
      </td>
      <td style="width: 283.5px; height: 40px;">
        <p>Configuration object for campaign</p>
      </td>
      <td style="width: 260.188px; height: 40px;">
        <ul>
          <li>Keys: ['incoming_campaign', 'utm_campaign']</li>
          <li>Override values: {campaign_name: 'new_campaign_name'}</li>
          <li>Default value: ['any_campaign_name']</li>
        </ul>
      </td>
    </tr>
    <tr>
      <td style="width: 133.359px;">
        <p>channel</p>
      </td>
      <td style="width: 283.5px;">
        <p>Configuration object for channel</p>
      </td>
      <td style="width: 260.188px;">
        <ul>
          <li>Keys: ['incoming_channel', 'utm_channel']</li>
          <li>Override values: {video: 'new_video'}</li>
          <li>Default value: ['any_video']</li>
        </ul>
      </td>
    </tr>
    <tr style="height: 83px;">
      <td style="width: 133.359px; height: 83px;">
        <p>ad</p>
      </td>
      <td style="width: 283.5px; height: 83px;">
        <p>Configuration object for ad</p>
      </td>
      <td style="width: 260.188px; height: 83px;">
        <ul>
          <li>Keys: ['incoming_ad', 'utm_ad']</li>
          <li>Override values: {ad_name: 'new_ad_name'}</li>
          <li>Default value: ['any_ad_name']</li>
        </ul>
      </td>
    </tr>
    <tr style="height: 62px;">
      <td style="width: 133.359px; height: 62px;">adSet</td>
      <td style="width: 283.5px; height: 62px;">
        <p>Configuration object for adset</p>
      </td>
      <td style="width: 260.188px; height: 62px;">
        <ul>
          <li>Keys: ['incoming_adset', 'utm_adset']</li>
          <li>Override values: {'adset_name': 'new_adset_name'}</li>
          <li>Default value: ['any_adset_name']</li>
        </ul>
      </td>
    </tr>      
    <tr style="height: 83px;">
      <td style="width: 133.359px; height: 83px;">
        <span style="font-weight: 400;">Other (custom) query parameters</span><span style="font-weight: 400;"><br></span>
      </td>
      <td style="width: 283.5px; height: 83px;">
        <ul>
          <li>
            List of any other parameters you want to be included in the
            outgoing OneLink URL for attribution or deep linking, along
            with their configuration objects.
          </li>
          <li>
            The name of the custom parameter is listed by the developer
            as <code>paramKey</code> in the configuration object.
          </li>
        </ul>
      </td>
      <td style="width: 260.188px; height: 83px;">
        <ul>
          <li>paramKey: 'deep_link_sub1'</li>
          <li>Keys: ['page_id']</li>
          <li>Override values: {page12: 'new_page12'}</li>
          <li>Default value: 'page1'</li>
        </ul>
      </td>
    </tr>
    <tr>
      <td style="width: 119.953px;" colspan="2">
        <span style="font-weight: 400;">platform</span>
      </td>
      <td style="width: 283.5px;">
        A string describes the platform. MUST be from this list:
        <ul><li>smartcast</li>        
        <li>tizen</li>
        <li>roku</li>
        <li>webos</li>
        <li>vidaa</li>
        <li>playstation</li>
        <li>android</li>
        <li>ios</li>
        <li>steam</li>
        <li>quest</li>
        <li>battlenet</li>
         <li>nativepc</li>
         <li>epic</li>
          <li>switch</li></ul>
      </td>
      <td style="width: 260.188px;">"steam"</td>
    </tr>
    <tr>
      <td style="width: 119.953px;" colspan="2">
        <span style="font-weight: 400;">app_id</span>
      </td>
      <td style="width: 283.5px;">
        <span>The app or game's unique identifier on the platform's store (for example, a Steam App ID or console Title ID). Required for each platform you integrate.</span>
      </td>
      <td style="width: 260.188px;">"123456"</td>
    </tr>
    <tr>
      <td style="width: 119.953px;" colspan="2">
        <span style="font-weight: 400;">redirectURL</span>
      </td>
      <td style="width: 283.5px;">
        <span>The full destination URL for the platform's storefront listing. Required for each platform you integrate.</span>
      </td>
      <td style="width: 260.188px;">"https://store.steampowered.com/app/123456/Team_Fortress_2/"</td>
    </tr>
  </tbody>
</table>
`}</HTMLBlock>

## UTM parameter mapping

If your PC or Steam campaigns use standard UTM parameters, Smart Script maps them to AppsFlyer dimensions as follows:

| UTM parameter | AppsFlyer dimension | Configuration object |
| ------------- | ------------------- | -------------------- |
| utm\_source   | Media source        | mediaSource          |
| utm\_campaign | Campaign            | campaign             |
| utm\_channel  | Channel             | channel              |
| utm\_ad       | Ad                  | ad                   |
| utm\_adset    | Ad set              | adSet                |

## Game landing page demo

You can find here a fully functional [demo landing page](https://appsflyersdk.github.io/appsflyer-sample-app-smartscript-demo-page/) which demonstrates integrating the `generateDirectClickURL` [Smart Script code](https://github.com/AppsFlyerSDK/appsflyer-sample-app-smartscript-demo-page/blob/master/index.html#L340-345).