Login

Help

Documentation

Advanced Scripting: Introduction

Twixl Support Team Updated: - Created :

    With Advanced Scripting you can decide to filter Content Items or Collections based on selected criteria.

    1. Advanced Scripting, what is it?

    Using Advanced Scripting, you can link a number of properties available in the app (bundle ID, language, geolocation, ...) and decide whether the Content Item or Collection should be visible or not.

    ENTITLEMENT PACK REQUIRED:

    To make use of the Advanced Scripting functionality, you need to have the Entitlement Pack activated. Contact the sales department for details.

    2. General info about Advanced Scripting

    Advanced scripting is a collection of JavaScript functions that will be evaluated for each collection and/or content item in the context of an application.

    It can be used to filter the content items shown in a collection based on a custom set of business rules.

    Where can I activate Advanced Scripting?

    Although Advanced Scripting is all about filtering Content Items and Collections, you define Advanced Scripting on a Collection level. As such you need to edit a Collection in order to add a script.

    Her's a sample script:

    // Executed once for every collection before the filtering of the items
    function setupFilter(collection, environment) {
    }
    
    // Executed for once for every collection
    function shouldShowCollection(collection, environment) {
        return true;
    }
    
    // Executed for every single content item
    function shouldShowItem(contentItem, collection, environment) {
        return true;
    }
    
    // Executed once for every collection after the filtering of the items
    function teardownFilter(collection, environment) {
    }
    Click to copy

    IMPORTANT:

    Each of the 4 base functions that get executed in the advanced filter currently have a maximum execution time of 2 seconds.

    TIP:

    You can find a complete syntax and lifecycle overview here. This info also can be found on the Twixl  platform, below the Advanced Scripting editor window.

    Debugging options

    In a mobile app

    2.1. App without a Hamburger Menu

    For apps without a Hamburger Menu:

    1. Tap the Gear Menu first
    2. Then select Advanced Filter Log
    2.2. App with a Hamburger Menu

    For apps with a Hamburger Menu:

    1. Activate the Hamburger Menu first
    2. Select the Gear Menu
    3. Then select Advanced Filter Log

    In the Browser Client

    For The Browser Client, you need to add the suffix ?debug=1 and then you'll notice the debugger icon in the toolbar.

    So this means, if your Browser Client url is:

    https://browserclient.twixlmedia.com/<app>
    Click to copy

    Then you'll need to add ?debug=1 in the following way:

    https://browserclient.twixlmedia.com/<app>?debug=1
    Click to copy