[Legacy] OneLink Smart Script V1

At a glance: Customize OneLinks that are automatically generated and embedded behind a button or banner on your brand's website. Note: Although not mandatory, consider migrating to OneLink Smart Script V2.

1920

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.
2. Initialize the Smart Script object OneLinkUrlGenerator with the parameters and values.
3. [Optional] Run setters with additional parameters and values.
4. 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 object OneLinkUrlGenerator using the arguments (parameters).
ParameterTypeFunctionalityExample
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/A1b2
Branded domain example: click.yourbrand.com/A1b2
pidKeysListList 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']
pidOverrideListdictionary {string: string,
…}
Lists the media source values in the incoming URL, alongside what you want them to be replaced with.{
'twitter': 'twitter_int',
'snapchat': 'snapchat_int',
'some_social_net': 'some_social_net_int'
}
pidStaticValuestringIf a pid key is not found in the pidKeysList, the pidStaticValue is used as the pid value.- 'website'
- 'landing_page'
campaignKeysListList of stringsLists the campaign parameter/s in the incoming URL that will be placed as the c parameter in the outgoing URL.['af_campaign', 'utm_campaign']
campaignStaticValuestringIf a campaign key is not found in the campaignKeysList, the campaignStaticValue is used as the c value.- 'website'
- 'landing_page'
gclIdParamstring- 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'
skipListstringIf any strings in the skip list appear in the HTTP referrer, the Smart Script returns null.- '[‘facebook’, ‘twitter’]'
- Facebook is in the skipList by default.

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 template that follows:
onelinkGenerator.set[parameter]("parameter value", "optional static value");

For example:

onelinkGenerator.setAfSub1("original_url_sub1", "ram_afsub1");

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://appsflyersdk.github.io/appsflyer-onelink-smart-script/v1/examples/basic_url.html?af_c=gogo&af_pid=email

Script:

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

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

UTM parameters

Incoming URL:
https://appsflyersdk.github.io/appsflyer-onelink-smart-script/v1/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: ['incoming_media_source', 'utm_source'],
         campaignKeysList: ['incoming_campaign', '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://appsflyersdk.github.io/appsflyer-onelink-smart-script/v1/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: ['incoming_media_source'],
         pidStaticValue: 'my_static_pid',
         campaignKeysList: ['incoming_campaign'],
         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://appsflyersdk.github.io/appsflyer-onelink-smart-script/v1/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: ['incoming_media_source'],
         campaignKeysList: ['incoming_campaign'],
         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://appsflyersdk.github.io/appsflyer-onelink-smart-script/v1/examples/gclid.html?af_pid=sms&af_c=candles&gclid=1a2b3c

Script:

const onelinkGenerator =  new window.AF.OneLinkUrlGenerator(
        {oneLinkURL: "https://engmntqa.onelink.me/LtRd/",
         pidKeysList: ['incoming_media_source'],
         campaignKeysList: ['incoming_campaign'],
         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 to 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://appsflyersdk.github.io/appsflyer-onelink-smart-script/v1/examples/setters.html?af_c=gogo&af_pid=email

Script:

const onelinkGenerator =  new window.AF.OneLinkUrlGenerator(
        {oneLinkURL: "https://engmntqa.onelink.me/LtRd/",
         pidKeysList: ['incoming_media_source'],
         campaignKeysList: ['incoming_campaign']
      });
      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

Set additional attribution parameters

You can create a long link with additional attribution parameters. See the functions for passing parameters in the sample script that follows.

To add an attribution parameter:

  • Call the function setCustomParameter.
    The setCustomParameter accepts three arguments:
    1. [Mandatory] The key of the attribution parameter in the incoming URL from which the script takes the value to set in the outgoing URL.
    2. [Mandatory] The key of the attribution parameter 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.

Incoming URL:
https://appsflyersdk.github.io/appsflyer-onelink-smart-script/v1/examples/set_af_params.html?af_c=gogo&af_pid=email&partner_name=bigagency

Script:

onelinkGenerator.setCustomParameter("incoming_site_id", "af_siteid", "defaultSiteID");

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

Skip clicks from Twitter or Facebook

You can disable the Smart Script for a particular click (for example, from Twitter or Facebook) by creating a skip list. If any of the strings in the skip list appear in the HTTP referrer of the click, the Smart Script returns null.

Script:

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

Don't skip any clicks

You can ensure that OneLink Smart Script works for all clicks, and never skips any, by passing an empty skip list.

Script:

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