OneLink Smart Script—Web-to-app URL generator

At a glance: Customize OneLinks that are automatically generated and embedded behind a button or banner on your brand's website.

About OneLink Smart Script

Users arrive at your mobile website before reaching your app store page, either organically, or via advertising campaigns. However, since there are two clicks (the first that directs to the web page and the second that directs from the web page to the app store), collecting click conversion metrics and deep linking is problematic. 

OneLink Smart Script solves these problems. The script:

  • Uses the incoming URLs leading to the webpage to automatically generate unique outgoing OneLink URLs leading to the app store. 
  • Provides accurate web-to-app metrics collection for all media sources. 
  • Can be used for deep linking.
  • Runs seamlessly on any webpage or landing page.

Procedures

To set up the Smart Script, the following action checklist of procedures need to be completed.

Procedure checklist

  1. Import the script to your website.
  1. Initialize the Smart Script object with the parameters and values.
  1. [Optional] Run setters with additional parameters and values.
  1. Generate the URLs.

Import the script

To import the script to your website:

  1. Download the script.
  2. Import it into the mobile site/pages on which you want it to run.

Initialize the script

To initialize the script:

  1. Get from the marketer: The parameters/values that the outgoing OneLink URL should contain (based on what is contained in the incoming URL). See the table that follows for details.
  2. Initialize the Smart Script using the arguments (parameters).

Parameter

Type

Functionality

Example

oneLinkURL [required]

string

  • Serves as the base for all links generated by the script.
  • It is the OneLink template domain + template ID.

yourbrand.onelink.me/mylp
Branded domain example: yourbrand.com/mylp

pidKeysList

List of strings

  • Lists the media source parameter/s in the incoming URL that will be placed as the pid parameter in the outgoing URL.
  • If there are multiple media source params in the incoming link (for example af_pid and utm_source), the pidKeysList scans the params from first to last, and uses the first match found.

['af_pid', 'utm_source']

pidOverrideList

dictionary {string: string,
…}

Lists the media source values in the incoming URL, alongside what you them to be replaced with.

{
'twitter': 'twitter_int',
'snapchat': 'snapchat_int',
'some_social_net': 'some_social_net_int'
}

pidStaticValue

string

If a pid key is not found in the pidKeysList, the pidStaticValue is used as the pid value.

  • 'website'
  • 'organic'

campaignKeysList

List of strings

Lists the campaign parameter/s in the incoming URL that will be placed as the c parameter in the outgoing URL.

['af_campaign', 'utm_campaign']

campaignStaticValue

string

If a campaign key is not found in the campaignKeysList, the campaignStaticValue is used as the c value.

  • 'website'
  • 'organic'

gclIdParam

string

  • Defines which parameter in the outgoing URL carries the GCLID.
  • Any parameter can be chosen. Note! To display in AppsFlyer raw data reports, the param must be one of af_sub[1-5].

'af_sub5'

Run setters

To run setters:

  1. Get from the marketer: Any other parameters and values that the outgoing OneLink URL should contain (based on what is contained in the incoming URL).
  2. Run the setters using the sequence that follows:
onelinkGenerator.set[parameter]("parameter value", "optional static value");

Generate URLs

To generate outgoing OneLink URLs:

  • Run the method generateURL in the web/landing page HTML that calls the script.
    Possible return values are:
    • An outgoing Onelink URL
    • Null. If the script returns null, the web/landing page's existing URL is not be changed.

Examples

Basic attribution

Incoming URL:
https://liaz-af.github.io/af-onelink-smart-script/examples/basic_url.html?af_c=gogo&af_pid=email

Script:

const onelinkGenerator =  new window.AF.OneLinkUrlGenerator(
        {oneLinkURL: "https://engmntqa.onelink.me/LtRd/",
         pidKeysList: ['af_pid'],
         campaignKeysList: ['af_c']
      });
      const url = onelinkGenerator.generateUrl();

Outgoing URL:
https://engmntqa.onelink.me/LtRd/?pid=email&c=gogo&af_js_web=true

UTM parameters

Incoming URL:
https://liaz-af.github.io/af-onelink-smart-script/examples/utm_params.html?utm_source=email&utm_campaign=summer_sale

Script:

onst onelinkGenerator =  new window.AF.OneLinkUrlGenerator(
        {oneLinkURL: "https://engmntqa.onelink.me/LtRd/",
         pidKeysList: ['af_pid', 'utm_source'],
         campaignKeysList: ['af_c', 'utm_campaign']
      });
      const url = onelinkGenerator.generateUrl();

Outgoing URL:
https://engmntqa.onelink.me/LtRd/?pid=email&c=summer_sale&af_js_web=true

PID and campaign static values

Incoming URL:
https://liaz-af.github.io/af-onelink-smart-script/examples/static_val.html?af_not_c=gogo&af_not_pid=email

Script:

const onelinkGenerator =  new window.AF.OneLinkUrlGenerator(
        {oneLinkURL: "https://engmntqa.onelink.me/LtRd/",
         pidKeysList: ['af_pid'],
         pidStaticValue: 'my_static_pid',
         campaignKeysList: ['af_c'],
         campaignStaticValue: 'my_static_cmpn',
      });
      const url = onelinkGenerator.generateUrl();

Outgoing URL:
https://engmntqa.onelink.me/LtRd/?pid=my_static_pid&c=my_static_cmpn&af_js_web=true

Override PIDs

Incoming URL:
https://liaz-af.github.io/af-onelink-smart-script/examples/override_pid.html?af_pid=twitter&af_c=big_social

Script:

const onelinkGenerator =  new window.AF.OneLinkUrlGenerator(
        {oneLinkURL: "https://engmntqa.onelink.me/LtRd/",
         pidKeysList: ['af_pid'],
         campaignKeysList: ['af_c'],
         pidOverrideList: { twitter: 'twitter_out',
                            snapchat: 'snapchat_out'
                          }
      });
      const url = onelinkGenerator.generateUrl();

Outgoing URL:
https://engmntqa.onelink.me/LtRd/?pid=twitter_out&c=big_social&af_js_web=true

Google Click ID passthrough to af_sub

Incoming URL:
https://liaz-af.github.io/af-onelink-smart-script/examples/gclid.html?af_pid=google_lp&af_c=candles&gclid=1a2b3c

Script:

const onelinkGenerator =  new window.AF.OneLinkUrlGenerator(
        {oneLinkURL: "https://engmntqa.onelink.me/LtRd/",
         pidKeysList: ['af_pid'],
         campaignKeysList: ['af_c'],
         gclIdParam: 'af_sub4'
      });
      const url = onelinkGenerator.generateUrl();

Outgoing URL:
https://engmntqa.onelink.me/LtRd/?pid=google_lp&c=candles&af_js_web=true&af_sub4=1a2b3c

Set OneLink parameters

To create a long link top be used for deep linking, you can pass both custom parameters and predefined parameters. See the functions for passing parameters in the sample script that follows.

To pass a custom parameter:

  • Call the function setCustomParameter.
    The setCustomParameter accepts three arguments:
    1. [Mandatory] The key in the incoming URL from which the script takes the value to set in the outgoing URL.
    2. [Mandatory] The key to be specified in the outgoing URL.
    3. [Optional] A static fallback value, in case the key in the first argument isn’t found in the URL.

If the key in the first argument isn’t found, and no static fallback is defined, the parameter is skipped.

To pass a predefined parameter

  • Call the function(s) in the sample script that follows (except setCustomParameter).
    Each function accepts two arguments:
    1. [Mandatory] The key in the incoming URL from which the script takes the value to set in the outgoing URL.
    2. [Optional] A static fallback value, in case the key in the first argument isn’t found in the URL.

If the key in the first argument isn’t found, and no static fallback is defined, the parameter is skipped.

Incoming URL:
https://liaz-af.github.io/af-onelink-smart-script/examples/setters.html?af_c=gogo&af_pid=email

Script:

const onelinkGenerator =  new window.AF.OneLinkUrlGenerator(
        {oneLinkURL: "https://engmntqa.onelink.me/LtRd/",
         pidKeysList: ['af_pid'],
         campaignKeysList: ['af_c']
      });
      onelinkGenerator.setDeepLinkValue("original_url_deeplinkvalue", "yessss");
      onelinkGenerator.setChannel("original_url_channel", "new_channel");
      onelinkGenerator.setAdset("no_adset", "adset");
      onelinkGenerator.setAd("original_url_ad", "new_ad");
      onelinkGenerator.setAfSub1("original_url_sub1", "ram_afsub1");
      onelinkGenerator.setAfSub2("original_url_sub2");
      onelinkGenerator.setAfSub3("no_sub3", "new_afsub3");
      onelinkGenerator.setAfSub4("original_url_sub4");
      onelinkGenerator.setAfSub5("neverfind_sub5", "new_afsub5");
      onelinkGenerator.setCustomParameter("original_url_fruit_name", "onelink_my_custom_param", "apples");
      const url = onelinkGenerator.generateUrl();

Outgoing URL:
https://engmntqa.onelink.me/LtRd/?pid=email&c=gogo&af_js_web=true&deep_link_value=yessss&af_channel=new_channel&af_adset=adset&af_ad=new_ad&af_sub1=ram_afsub1&af_sub3=new_afsub3&af_sub5=new_afsub5&onelink_my_custom_param=apples

Updated about a month ago


OneLink Smart Script—Web-to-app URL generator


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.