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. 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_idandredirectURLfor each platform's storefront.
Implementation steps
Create a direct click URL
To create a direct click URL, follow these steps:
-
Get the arguments to call the script, mapping the incoming parameters to the marketer's parameters.
-
Initialize the Smart Script arguments and configuration objects as in the following example:
var mediaSource = { keys: ["my_media_source"], defaultValue: "my_default_media_source" }; var campaign = { keys: ["my_campaign"], defaultValue: "my_default_campaign" }; -
Generate the URLs by calling the script in your web or landing page HTML, using the following method:
var result = window.AF_SMART_SCRIPT.generateDirectClickURL({ afParameters: afParameters, platform: platform.platformName, app_id: platform.appid, redirectURL: platform.redirectURL, }) -
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 theresultvalue as needed, for example, to place it as a link under a call to action (CTA) on your website. - A
nullvalue. If the script returnsnull, implement your error-handling flow. For example, when the existing URL of the web or landing page is not changed.
For example:
//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 of the conversion of an incoming URL to an outgoing direct click URL for a Steam game.
- An outgoing Direct URL (
NoteIn 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.
- Validate the generated URL using the Direct Click URL test page, 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:
- Add
af_generate_referreras a custom parameter insideafParameters.afCustom, withkeys: []so the value is always forced:
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/'
});- On the landing page (where
redirectURLpoints), read the referrer ID from the URL's query parameters. - In your download or packaging pipeline, attach the referrer ID to the game package before serving it.
- In the game's first-launch (first open) event, send the referrer ID back to AppsFlyer.
Required: set af_generate_referrer to true
af_generate_referrermust be set totrue, andredirectURLmust be provided, since the referrer ID is appended to that URL. Without both, the referrer ID isn't generated.
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 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 in the mobile article.
Arguments
| Argument | Remarks | Example | |
|---|---|---|---|
|
afParameters (required)
|
mediaSource (required) |
Configuration object for media source |
|
|
campaign |
Configuration object for campaign |
|
|
|
channel |
Configuration object for channel |
|
|
|
ad |
Configuration object for ad |
|
|
| adSet |
Configuration object for adset |
|
|
|
Other (custom) query parameters |
|
|
|
| platform |
A string describes the platform. MUST be from this list:
|
"steam" | |
| app_id | 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. | "123456" | |
| redirectURL | The full destination URL for the platform's storefront listing. Required for each platform you integrate. | "https://store.steampowered.com/app/123456/Team_Fortress_2/" | |
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 which demonstrates integrating the generateDirectClickURL Smart Script code.
Updated 22 days ago