Understand Smart Script Functions

As long as the setup is done according to the marketer’s requirements, the Smart script should work to provide accurate web-to-app attribution. However, the script is customizable if the developer needs to make additional changes. The section below walks you through the different properties and functions within the script and provides examples.

Smart scripts functions

Set log level

Use the setLogLevel function to set logging level in your browser's console, if required. Call this function before calling the createLink function. The arguments are debug, warn, error, or none. The default log level value is debug.

AdjustSmartScript.setLogLevel('warn')

Create link

Use the createLink function to create an Adjust link with the specified mapping object properties.

const mapping = { /* mapping object properties */ }
AdjustSmartScript.createLink(mapping)

Get script version

Use the getVersion function to check the Smart scripts version.

AdjustSmartScript.getVersion()

Mapping object properties

You must pass a mapping object to the createLink method. You MUST define the following properties in the mapping object.

defaultLinkToken (string)
Link token to be used when no network link token is applicable or no network configuration has been provided.

campaign (object)
An object containing campaign information.
adgroup (object)
An object containing adgroup information.
creative (object)
An object containing creative information.

The campaign, adgroup, and creative objects MUST contain the following property:

in (string | string[])
A string or array of strings that are keys of URL search query strings to be used as a name of the campaign, adgroup, or creative.
If an array is passed, the script finds the names among GET parameters and passes all of them to the transform function, if present. Otherwise, the script writes the first non-empty value as the campaign, adgroup, or creative name.

You MAY also provide the following properties:

transform (function)
A function called with the value of in. It returns a string value that is the final name of the campaign, adgroup, or creative. If transform doesn't return a string or throws an error, the script writes the first non-empty value as the campaign, adgroup, or creative name.
defaultValue (string)
Used when value of in is not found by the transform function.

If you've implemented deep linking, you MUST define the following parameters in the mapping object.

domain (string)
The branded domain.
You can choose to define the branded domain if you haven't implemented deep linking. If no domain is specified, an app.adjust.com link is created.

iosAppSchema (string)
The iOS app scheme.

androidAppSchema (string)
The Android app scheme.

If you've implemented deep linking, you MAY define the following parameters.

iosDeeplinkPath (string)
The iOS deep link path.

androidDeeplinkPath (string)
The Android deep link path.

You MAY define the following parameters in the mapping object.

inputUrl (string)
The mobile web landing page URL. If you don't provide a value, the script uses window.location.href value as the current page URL.

label (object`) This parameter allows you to send custom data. Check Help center documentation for more details.


networks (object)
A key-value object containing network information.

The networks object MUST contain at least one key representing a network name. The following keys are supported:

  • meta
  • google_ads

The value MUST be an object containing the following property:

linkToken (string)
The link token of the network defined in the key.

customParameters (object)
An object containing custom parameter information.

The customParameters object MUST contain the following property:

in (string | string[])
A string or array of strings that are keys of URL search query strings to be used as a custom name.
If an array is passed, the script finds the names among GET parameters and passes all of them to the transform function, if present. Otherwise, the script writes the first non-empty value as the custom name.
out (string)
A string that specifies the name of the custom parameter to be written in the Adjust link.

You MAY also provide the following properties:

transform (function)
A function called with the value of in. It returns a string value that is the final custom name. If transform doesn't return a string or throws an error, the first non-empty value is written as the custom name.
defaultValue (string)
Used when value of in is not found by the transform function.

Examples

Use link token and campaign parameters

Set up link tokens for different partners with the networks property

Use transform and defaultValue properties to rewrite values in the Adjust link

Write custom parameters to the Adjust link

Create deep links

Test Smart scripts

Smart scripts outputs its logs in the browser's console. We recommended that you test how the script works with the specified mapping and ensure that correct links are generated.

  1. In your browser, go to the Developer Tools console.
  2. Navigate to the web page where you've implemented Smart scripts.
  3. If there are no logs with the [adjust-smart-script] prefix, refresh the page. If you still don't see any logs, ensure that:
    • Your code doesn’t suppress logging by calling AdjustSmartScript.setLogLevel('error') or AdjustSmartScript.setLogLevel('none').
    • Your code calls the AdjustSmartScript.createLink(params) function.

With different values of the inputUrl property, you can test different use cases. For example, if you're running a Meta campaign and you also expect organic users to visit your landing page, you can have the a URL with the campaign and Meta parameters, and another URL without any additional parameters.

Example logs:

[adjust-smart-script]: No networks configured
[adjust-smart-script]: Use defaultLinkToken to create adjust link
[adjust-smart-script]: Found value for campaign is new_campaign
[adjust-smart-script]: Found value for adgroup is some_adset
[adjust-smart-script]: Found value for creative is logo_image
[adjust-smart-script]: Transformed value for ref_code is id+my_product
[adjust-smart-script]: Misconfigured deep link: no valid androidAppSchema provided