Login

Learning & Support

Documentation

Advanced Scripting | Sample App 8: Privacy Policy

Twixl Support Team Updated: - Created :

In the series Advanced Scripting Sample Apps we explain some use cases for the Advanced Scripting. For more general info, it's very important that you read this KB-article first.

Preview with the Twixl App

You can preview this app by scanning the QR code with the Twixl app.

Replace QR-Code

Use Case

In this example, we show how you can add a Privacy Policy to your app which users have to accept before they are granted access to your app.

Instructions

Preparations

  1. Create a new app
  2. Add a Cell Style for:
    • The Privacy Policy
    • The button to accept the Privacy Policy
    • The default content
  3. Add the following contents items to the Root Collection with the following properties:
    • Privacy policy
      • Type: Embedded Web Viewer
      • Name: privacy.policy
      • Title: Privacy Policy
      • Content: zipped .html file with the privacy policy
    • Button to accept the Privacy Policy
      • Type: Web link
      • Name: privacy.accept
      • Title: Accept & Continue
      • Link to URL: tp-set-custom-vars://?has_accepted=yes&version=20190125
    • The actual content (just ensure that the name doesn't start with privacy).
  4. Set up your Advanced Scripting (see below)

Advanced Scripting Settings

For the Root Collection

// Keep a variable to check if the user accepted the privacy policy
var hasAccepted = false;


// Executed once for every collection before the filtering of the items
function setupFilter(collection, environment) {
    hasAccepted = environment.CustomVar("has_accepted") == "yes";
}

// Executed once for every collection
// Root and hamburger are always shown
function shouldShowCollection(collection) {
    return hasAccepted;
}

// Executed for every single content item
function shouldShowItem(contentItem, collection, environment) {
    if (contentItem.Name.startsWith("privacy.")) {
        return !hasAccepted;
    }
    return hasAccepted;
}

// Executed once for every collection after the filtering of the items
function teardownFilter(collection, environment) {
}

Extra exercise 1 - Clearing the setting

Preparations

  1. Add a the following content item to the Hamburger Menu Collection
    • Button to accept the Privacy Policy
      • Type: Web link
      • Name: <default>
      • Title: Clear Privacy Policy
      • Link to URL: tp-set-custom-vars://
  2. Set up your Advanced Scripting (see below)

Advanced Scripting Settings

For the Hamburger Menu Collection:

// Executed once for every collection before the filtering of the items
function setupFilter(collection, environment) {
}

// Executed for every single content item
function shouldShowItem(contentItem, collection, environment) {
    var hasAccepted = environment.CustomVar("has_accepted") === "yes";
    return hasAccepted;
}

// Executed once for every collection after the filtering of the items
function teardownFilter(collection, environment) {
}

Extra exercise 2

Try to improve the code and add an extra check to find out which version of the privacy policy was accepted. If it's different than what has been accepted before, you should force the user to agree to it again…

Was this article helpful?

0 out of 0 found this helpful