Blink

Blink

    ›Blink Javascript SDK

    Getting started

    • Overview
    • Quick Start
    • Environments
    • Support

    Panels

    • Basics
    • Panel options
    • Custom content

    User Journeys

    • The basics
    • Conditions
    • Actions
    • Throttles
    • Journey Groups
    • Complete Examples

    Guides

    • How to enable donations

    Blink Javascript SDK

    • Load the SDK
    • Blink managed functions
    • Blink managed variables
    • Reference

      • showDonationModal()
      • promptDonationPopup()
      • promptSubscriptionPopup()
      • isSubscribed()
      • getSubscription()
      • onSubscriptionChange()

    Blink notifications

    • Webhooks
    • Events

      • Subscription created
      • Subscription canceled
      • Subscription reactivated
      • Subscription unpaid
      • Subscription finished
      • Payment created
      • Payment refunded

      Objects

      • Event
      • Subscription
      • Donation
      • Payment
      • Amount
      • User
      • Merchant

    Blink managed variables

    User Journeys are a powerful tool to control Blink behaviour on your website, but on their own they have the drawback of being static, meaning that it's hard for multiple semi-dependent journeys to interoperate seamlessly. This can be solved through the use of the Blink SDK's variables API.

    The Blink SDK offers an API to set, retrieve and delete custom JavaScript variables. These variables can be used in a variety of places such as User Journey conditions, in template expressions within panel custom content and more.

    API

    blinkSDK.setVariable(key, value, scope="memory")

    Set the variable at key key to value value. The third parameter, scope, controls the storage scope of the variable: can be one of "permanent", "tab" or "memory" (default). If scope is "permanent", the variable is stored until the user clears their browser cookies and is available on all tabs. If scope is "tab", the variable is stored on the current tab. Is scope is "memory", the variable is stored only during the current page view and disappears on page refresh.

    _Note: the key of the variable should be a string consisting of dot-separated valid JavaScript identifiers.

    Example:

    // Consider the following journey is active on the current page:
    const journey = {
        condition: {
            type: "variable",
            key: "donate_popup.can_be_displayed",
            equal: true,
        },
        action: {
            type: "createPG",
            panelType: "donation",
            gateType: "popup",
            selector: "body",
        },
    }
    
    // Set the variable to indicate the donate popup can be displayed on the
    // current tab from now on.
    blinkSDK.setVariable("donate_popup.can_be_displayed", true, "tab")
    // The journey automatically gets re-evaluated and the donation
    // popup is displayed.
    

    blinkSDK.getVariable(key)

    Returns the value of the variable at key key, or undefined if the variable isn't set. This function also looks at builtin variables, such as counters created automatically by the Nth page visit condition.

    Example:

    blinkSDK.setVariable("user_token", "beef1337", "tab")
    blinkSDK.getVariable("user_token")  // -> "beef1337"
    // page refresh
    blinkSDK.getVariable("user_token")  // -> "beef1337"
    // different tab
    blinkSDK.getVariable("user_token")  // -> undefined
    

    blinkSDK.hasVariable(key)

    Returns true or false based on whether the variable at key key exists. This function also looks at builtin variables, such as counters created automatically by the Nth page visit condition.

    Example:

    blinkSDK.hasVariable("user_token")  // -> false
    blinkSDK.setVariable("user_token", "beef1337", "tab")
    blinkSDK.hasVariable("user_token")  // -> true
    // page refresh
    blinkSDK.hasVariable("user_token")  // -> true
    // different tab
    blinkSDK.hasVariable("user_token")  // -> false
    

    blinkSDK.deleteVariable(key)

    Delete the variable at key key. Note that this function does not delete a built-in variable. Also, if you create a variable with the same key as a built-in variable, and delete it afterwards, the variable will still exist and will revert to the value of the built-in variable.

    Example:

    blinkSDK.hasVariable("user_token")  // -> false
    blinkSDK.setVariable("user_token", "beef1337", "tab")
    blinkSDK.hasVariable("user_token")  // -> true
    blinkSDK.deleteVariable("user_token")
    blinkSDK.hasVariable("user_token")  // -> false
    blinkSDK.getVariable("user_token")  // -> undefined
    
    // Consider the built-in variable "banners.count" exists and is equal to 5
    blinkSDK.getVariable("banners.count")  // -> 5
    blinkSDK.setVariable("banners.count", 16)
    blinkSDK.getVariable("banners.count")  // -> 16
    blinkSDK.deleteVariable("banners.count")
    blinkSDK.getVariable("banners.count")  // -> 5
    

    blinkSDK.allVariables()

    Returns an object containing key: value pairs for all variables available, including all built-in variables.

    Example:

    blinkSDK.setVariable("user_token", "beef1337", "tab")
    blinkSDK.allVariables()  // -> {user_token: "beef1337", ...}
                             // (may include other keys for builtin variables).
    
    ← Blink managed functionsshowDonationModal() →
    Blink
    Docs
    Getting StartedPublic API
    Integration
    Donation
    Blink
    Copyright © 2021 Blink Ledger Systems Inc. All rights reserved