At a glance: Set up OneLink Smart Script to convert and attribute your mobile website visitors, coming from any source, into mobile app users.
Setup
There are two versions of OneLink Smart Script:
OneLink Smart Script V2 (recommended): If you are setting up OneLink Smart Script for the first time, this is the preferred version to use. It can be generated in the AppsFlyer UI without developer assistance. If for some reason, a developer is needed, their work portion is easier. And it can also be set up using Google Tag Manager. See developer instructions
OneLink Smart Script V1 (legacy): If you already have Onelink Smart Script set up, use the documentation for this version to maintain and edit this script. Note: Although not mandatory, consider migrating to V2 to properly get view-thorough attributions using the OneLink Smart Script.
Set up OneLink Smart Script
To set up the Smart Script, you can either:
- Embed the script in your website.
- Use Google Tag Manager.
Scope of work
Who's involved
|
Prerequisites
|
How to create a OneLink Smart Script
- In AppsFlyer, from the side menu, select Engage > Web-to-app > Smart Script.
-
For new users
- Click on the Get started button.
- Follow steps 4 and onwards.
- Click on the + New Smart Script button at the top of the page.
- Follow the onscreen instructions to name your Smart Script.
- Select a OneLink template to base the script. The template contains the basic redirection settings.
- Map the parameters that the outgoing URL should contain. These parameters are based on the parameters of the incoming URL. Note: The media source (pid) parameter is mandatory.
- Select the outgoing parameter/dimension to map.
Often, this is an AppsFlyer parameter name that can't be changed, but in some cases, you need to enter your parameter name. - Decide and configure what the value of the outgoing parameter should be based on either:
- Incoming URL parameters: List one or more possible incoming URL parameters that you want replaced by the outgoing URL parameter. The values of the incoming URL parameters will be the values of your outgoing URL parameter.
- Example: any_param_name, utm_param_name. If utm_param_name is found in the incoming URL, its value will be used as the value of your selected outgoing URL parameter.
- The Smart Script searches the list of parameters from left to right and maps the first match to the outgoing parameter URL.
- This list of parameters is referred to by developers as keys.
- Default value: Enter your desired default value for the outgoing parameter value for when an incoming URL parameter isn't found or if you don’t list any incoming URL parameters.
- Example: For the outgoing parameter, if the incoming URL parameter lists any_paramname, utm_paramname, when neither parameter in the list is found, the default value will be used as the value of the outgoing parameter.
- Override values: Configure one or more values from the incoming URL alongside the values of the outgoing URL you want them to be replaced with.
- Example: For the campaign parameter, if the value in the incoming URL is campaign_name, the value in the outgoing URL can be changed to new_campaign_name.
- Incoming URL parameters: List one or more possible incoming URL parameters that you want replaced by the outgoing URL parameter. The values of the incoming URL parameters will be the values of your outgoing URL parameter.
- [Optional] Click + New parameter to map additional parameters. See all the additional arguments (parameter configurations) you can use.
- Select the outgoing parameter/dimension to map.
-
Select how to implement the Smart Script on your website:
- Embed the script in your website.
- Use Google Tag Manager.
- Click on Test to test the script on the Smart Script test page. Make sure the correct outgoing URL is generated.
- Click
- Save to save your changes
-
Save and Generate to save and generate the script
- Click Download script.
- If you selected to embed the script in your website: Send the script to your web developer to implement and tell them what to do with the generated outgoing URL. For example, place it under a CTA button on your mobile site or present a QR code on your desktop site. Developer instructions
- If you selected to use Google Tag Manager:
- In Google Tag Manager, create a new tag, name the tag, click Tag Configuration, and select Custom HTML.
- In the HTML box, paste the generated Smart Script code.
- Click Triggering, create a new trigger, name it, and choose a Trigger Configuration (for example, all page views). See GTM documentation to learn more
- Click Save
- Tell your web developer what to do with the generated outgoing URL. For example, place it under a CTA button on your mobile site or present a QR code on your desktop site. Developer instructions
- Saved scripts can be viewed in the dropdown menu.
Important!
Every time you update the script, it needs to be implemented again
How to edit or delete a script
- Click the dropdown arrow next to the Smart Script name.
Here you can see all your saved scripts - Click on the pen icon next to the script you want to edit
- Follow the steps in How to create a OneLink Smart Script
- Click on the trash bin icon to delete the Smart Script
Important!
Every time you update the script, it needs to be implemented again
How to duplicate a script
- Go to the Smart Script you want to duplicate
- Click on the duplicate button on the top banner
- Follow the steps in How to create a OneLink Smart Script
Argument structure
The OneLink Smart Script uses arguments to generate an outgoing URL based on the parameters of the incoming URL and the arguments defined in the script. The afParameters argument has a structure made up of several other arguments (parameters) used for attribution and deep linking, each of which contains a structure (referred to by developers as a configuration object) that has keys, override values, and a default value, as described in the table that follows.
Argument | Description | Example |
---|---|---|
Incoming URL parameters (referred to by developers as keys) |
|
|
Default value |
|
Example: ['web_video'] For the channel parameter in the script, if you have the param in_channel is not found, web_video is used as the channel value. |
Override values |
|
Example: {'video': 'video_new'} For the channel parameter in the script, anytime the incoming value is video, the script changes it to video_new on the outgoing link. |
Arguments
The OneLink Smart Script uses arguments to generate an outgoing URL based on the parameters of the incoming URL and the arguments defined in the script.
Arguments (parameters and values) to implement the Smart Script
Argument | Remarks | Record your responses (for you or your developer to use) | |
---|---|---|---|
oneLinkURL (required) |
|
||
afParameters (required)
|
mediaSource (required) |
|
Keys: Default value: Override values: |
campaign |
|
Keys: Default value: Override values: |
|
channel |
|
Keys: Default value: Override values: |
|
ad |
|
Keys: Default value: Override values: |
|
adSet |
|
Keys: Default value: Override values: |
|
deepLinkValue |
|
Keys: Default value: Override values: |
|
afSub1-5 |
Configuration object for af_sub[1-5]. |
Keys: Default value: Override values: |
|
googleClickIdKey |
State what to call the parameter that carries the GCLID. |
||
Other (custom) query parameters |
|
Param key: Keys: Default value: Override values: |
Advanced arguments
The following table describes arguments that technical-savvy marketers or developers can implement in the Smart Script.
Advanced arguments (parameters and values) to implement in the Smart Script
Argument | Remarks | Record your responses (for you or your developer to use) | |
---|---|---|---|
referrerSkipList |
|
|
|
urlSkipList |
|
|
Use cases
The following sections provide Smart Script use cases for some common campaign/media source scenarios.
UTM parameters
To set up the script for UTM parameters:
- Make a list of UTM parameters on the incoming URL (for example: utm_source and utm_campaign)and match them to the parameters for the outgoing URL (for example: media_source and campaign).
-
Provide these in the list of arguments to the web developer.
Result: The values in the incoming parameters (utm_source and utm_campaign) are used to populate the values of the (media_source and campaign) parameters in the outgoing link.
Google Ads GCLID
The usual process for install attribution of Google Ads campaigns (which carry a GCLID parameter) requires users who click your ad to be redirected to the app store page URL.
Since in this case, you are redirecting leads from Google Ads to a web/landing page, the script takes the GCLID parameter from the Google Ads install campaign URL and puts it into the outgoing URL. From Smart Script version 2.9.0, GCLID, WBRAID, and GBRAID parameters, when available, are automatically forwarded "as is" on outgoing URLs generated by the Smart Script.
You can also map Click IDs to other outgoing parameters (af_sub[1-5]) to have them available in AppsFlyer raw data reports.
Note!
- This applies to install campaigns. For non-ACI search campaigns, meaning re-engagement campaigns, Google may be attributed as the media source, despite the Smart Script output.
- If a GCLID is found, the script looks for the incoming parameter keyword. If found, it puts the keyword value in the outgoing URL as the value of af_keywords.
Prerequisite: On the Google dashboard, enable auto-tagging.
With auto-tagging enabled, the URL contains the GCLID parameter.
To set up the script to map Google Ads GCLID to other parameters:
- Select a parameter in the outgoing URL to contain the GCLID.
Best practice: Select af_sub[1-5], so that the data displays in AppsFlyer raw data reports. -
Provide this in the list of arguments to the web developer. The result will be that in the outgoing URL, the GCLID will be the value of the af_sub[1-5] param.
To notify Google Ads about these installs:
- Get the GCLID data from the param af_sub[1-5] via CSV, or Push API in real-time for every install.
- Upload the GCLID data to Google either manually or via Google Ads API.
Note
This GCLID solution is not officially supported or recommended by Google. In case Google deprecates the GCLID parameter we will change the script to support the changes. Follow this article, by clicking the Follow button in the article header, to get informed when there is an update to the article or attached script.
Facebook FBCLID
Meta ads carry click IDs, called FBCLID. Starting in Smart Script version 2.8.1, when available, FBCLID will automatically be forwarded "as is" on outgoing URLs generated by the Smart Script. You can also map Click IDs to other outgoing parameters to have them available in AppsFlyer raw data reports.
To set up the script to map FBCLID to other parameters:
- Select a parameter in the outgoing URL to contain the FBCLID.
Best practice: Select af_sub[1-5], so that the data displays in AppsFlyer raw data reports. -
Provide this in the list of arguments to the web developer. The result will be that in the outgoing URL, the FBCLID will be the value of the af_sub[1-5] param.
SRNs, owned media, and other media source links
SRNs like Snapchat or X Ads, work differently than Google Ads or a cross-platform like Meta ads. Campaigns from these SRNs lead your users to the web/landing page, and you are billed according to clicking leads, unrelated to any derived mobile users.
For these SRNs, script setup is the same as for links from owned media, or other media sources you might use.
To set up the script:
- Make a list of the media source and campaign parameter names that are in the incoming links.
-
Provide these in the list of arguments to the web developer.
The SRN/media source type should be the media source value in the incoming URL, and the script finds it and uses it as the media_source value in the outgoing OneLink URL behind the download button on the web/landing page. If you want to change the outgoing media_source, provide the incoming media source value and the override media_source value in the list of arguments you give to the web developer.
Result: For these SRNs/media sources, the values in the media source and campaign parameters in the incoming link are used to populate the values for the media_source and campaign parameters in the outgoing link.
Example
Incoming URL: https://hotel.me/incoming_mediasource=twitter&incoming_campaign=big_social
Outgoing URL: https://hotel.onelink.me/Ac4G?pid=twitter&c=big_social
AppsFlyer attribution links
AppsFlyer attribution links can be used when the media source is a click ad network. When you set up such a link in AppsFlyer, you have the option to add a Redirection URL path (af_r) parameter with the desired URL path to your mobile website for web campaign-to-app attribution. You may not want the Script to create an outgoing OneLink URL, as then, some of the data from the original click may be lost.
Action: Use the urlSkipList argument to list the af_r parameter.
Result: When the Smart Script finds the af_r parameter on the incoming link, the Smart Script doesn't produce an outgoing URL and the developer must decide what link to place as the outgoing URL and implement it.
Example
Incoming URL: https://app.appsflyer.com/id123456789?pid=click_ad_network_int&c=orlando&af_r=hotel.me
Outgoing URL: No outgoing URL.
Web referrer mapping
Web referrer mapping enables you to learn from what page users arrived at your website (for example, from organic search results), and therefore enrich the data at your disposal for analyzing installs and re-engagements originating from your Smart Script web-to-app flow.
You can set the Smart Script to collect this information from your landing page or website HTTP header Referer
field. This field contains the base URL of the page from which users clicked a link that sent them to your web page.
To set up the script to collect the web referrer
- Open the Smart Script page
- Under the Web referrer mapping area section select the outgoing URL parameter key for the web referrer value:
- af_channel - Parameter is available in dashboards and raw data
- af_sub1-5 - Parameter is available in raw data under the af_sub1-5 columns and in the original URL column.
- Custom parameter - This is made up of the parameter name and value. The parameter is shown in raw data in the original URL column.
To learn about organic search attribution for re-engagements using Universal Links and App Links, see here.
Desktop
Most use cases in this article are of users coming from mobile devices. Therefore, when directed from the mobile website to an app store, they can immediately download your app.
However, desktop users shouldn't immediately be sent to an app store, because their device (a desktop or laptop) isn't compatible with mobile app downloads.
To set up the script for desktop users:
- In your OneLink template, set a destination URL for When link is clicked on desktop. The URL should redirect to a dedicated web/landing page. The landing page can contain a web form where they fill in their details to get an SMS or an email with a link to download the app. It's up to you to create the web form and provide the URL to it in the script.
Result: The script detects the device or platform the user is on. If it's desktop, the script generates an outgoing OneLink URL that redirects the user to your dedicated web/landing page.
See also Desktop-to-app conversion.
QR codes
Smart Script displays a QR code on your web page, instead of a button with a link behind it.
To display a QR code:
- Make sure you use Smart Script 2.6+ when you set up your Smart Script.
- Tell your developer to follow their instructions to create a QR code with the Smart Script result.
-
[Best practice] Tell the developer to:
- Customize the QR code by adding your app logo to the QR code center and customizing the color.
- Show the QR code when users are on desktop and show the button with the link when users are on mobile.
Result: The script displays a QR code instead of a button with a URL behind it.
Example
Incoming URL:
https://hotel.me/qr_code.html?incmp=gogo&inmedia=email
Outgoing URL:
https://hotel.onelink.me/LtRd/?af_js_web=true&af_ss_ver=2_1_0&pid=email&c=gogo
Outgoing QR code:
Impressions
The OneLink Smart Script can be used to count impressions on your website. To do so, the developer needs to call the impression function. Installs are then attributed to the impressions via view-through attribution.
Note:
- Counting impressions is in addition to the normal Smart Script-produced URL that counts clicks. Smart Script can be used to count clicks, impressions, or both.
- View-through attribution via Smart Script only works on mobile devices; not on desktop.
To attribute new installs to these impressions (which is view-through attribution):
- Make sure you use Smart Script 2.3+ when you set up your Smart Script.
- Tell your developer to call the impression function in the Smart Script.
- Make sure view-through attribution is turned on.
Important!
As of February 1st, 2023 (Chrome 110 stable release), Google has made some changes to reduce User-Agent data. In order to properly get view-thorough attributions using the OneLink Smart Script, you should use the OneLink Smart Script version 2.3 and above.
Additional information
FAQ
Will the incoming URL for OneLink link generation work if the user browses to a different page on the website?
Yes. Incoming URL parameters are stored for the duration of the browsing session and applied to the outgoing parameters of the Smart Script-generated OneLink link. For more implementation info, see our developer hub.
Why do I get an error when implementing Smart Script via Google Tag Manager?
Sometimes when you generate the Smart Script in AppsFlyer and try to insert it into Google Tag Manager (GTM), a "JavaScript too long" error displays. If this occurs, delete the GTM tag and create a new one.
Can I add parameters that are not listed?
Yes. In your OneLink Smart Script page, click on + New parameter to map additional parameters.
- New parameters can be custom parameters or AppsFlyer reserved parameters that are not listed in the dropdown.
- See all the additional arguments (parameter configurations) you can use.
- Use the Custom option from the dropdown and your parameter to the Outgoing URL parameters field.
For example, to add is_retargeting as a parameter, Custom parameter would be selected in the mapping for field, and then our is_retargeting parameter to the Outgoing URL parameters field.
Adset and other parameters are not showing in the dropdown
We recommend turning off any ad blockers you have on your browser when creating or adding new parameters. Sometimes ad blockers will remove an option if it has the word 'Ad' in it.
What browsers does Smart Script work on?
Smart Script uses Javascript and should work on all browsers.
Specs and limitations
Spec |
Remarks |
---|---|
URI scheme |
Even if a URI scheme is set in the OneLink template to open the app for existing users, for links created using Smart Script, the af_dp parameter with the URI scheme must be added by the developer to URLs as a custom parameter. |
# in incoming URL |
Smart Script encounters issues when handling incoming URLs that include a hash ('#') symbol preceding the query parameters (indicated by a '?' sign). In such cases, Smart Script reverts to default values. |