Skip to main content
Skip table of contents

Custom JS Code - Function Interfaces

Within client- and server-side variables that are custom JavaScript functions you can access the runtime environment on the server and other variable values for example, which holds big potential for customization in your JENTIS Data Capture implementation. There you can access either data on frontend tracked documents, the actual runtime environment, a local storage on your server and many more. Here is a reference of all functions available to empower your code.

List of Elements

  • Local Storage Read

  • Local Storage Write

  • Log

  • Access Frontend Variable

  • Access Document Properties

Function Interfaces

Local Storage Read and Write Scopes

Please note that both storage functions (read and write) operate on a certain scope. 

The scopes applied are:

  • user
    per JENTIS user id for a website visitor, which is the single most unique value in the JENTIS Data Capturing platform (all other user-related data is derived from this root, ie. a client-id in a tool)

  • account
    your JENTIS account that consists of containers (see: JENTIS Accounts and Containers)

  • tool
    by default all data on the server is interpreted in the context of a tool (that executes a data stream with a triggered tag on any given event), this default can be adjusted to share data between tools.

Tools Shared Storage Option

You can now also share data between tools to enhance your data quality possibly. For more details, please see: Tools

The meaning of this scope is detrimental to what data can be accessed in a function server side (ie. in a server side variable or transformation function). Data will not be accessible across JENTIS accounts, users, or tools. Meaning that you can not reference a users "transaction id" on any other users session. Also you can not access a specific tools client id in another tool (ie. if you install "Facebook" and "GA4" they can not reference each other's server side variable values). 

Quota on storage write

With no restrictions, you can write as many key and value pairs on the server.

The only limitation is currently the max. length of a value that applies to storage write function calls. If the value you are trying to set is larger than 1MB (roughly a 240.000-character string), it will get truncated. 

Local Storage Read

Use this function to access the local storage to read a value from it.

Availability: Server-Side Variables, Transformation Functions

JS
await this.storage.read("storage_name");

Input Parameter:

  • storage_name (String): the key on which the value to be read is to be found.

Return Parameter:

  • (Object) the value found on the given key or false if nothing is found.

Local Storage Write

Use this function to write a value to the local storage.

Availability: Server-Side Variables, Transformation Functions

JS
this.storage.write("storage_name", "storage_name", Date.now() + 3000000);

Input Parameters:

  • storage_name (String): the key on which the value to be read is to be found.

  • storage_value (String): the value to be saved on this location.

  • expiration timestamp (Integer):  a lifetime expiration date definition in millisec format.

Return Parameter:

  • (void) no value is returned.

Log

Logs from Backend Functions will be displayed in the preview panel. To log a value you can use the following function call.

Availability: Server-Side Variables, Transformation Functions

JS
this.log("my log string");

Input Parameter:

  • message (String): a string value to be logged.

Output Parameter:

  • (void) no value is returned.

Access Frontend Variable

With the following function you can reference values that were calculated in a frontend variable.

Availability: Server-Side Variables, Transformation Functions, Client-Side Variables

JS
this.getFrontendVariable("window_location_href");

Input Parameter:

  • variable_id (String): the id of the frontend variable (this value is displayed in a frontend variable edit screen)
    ⚠️ The input to this function must be a static string and can not be a dynamic variable. 

Output Parameter:

  • (Object) the current content of the referenced frontend variable.

Access Document Data

The internal data model with JENTIS is structured as “documents”, where there is a document for user, session and event data. You’ll find those in the according streams from any application (ie. the website or a native app). This is the foundation for the JENTIS Data Capture Platform operation and the tag manager with all its elements (such as JTM States, Tags, Triggers, Variables, Vendors, etc).

If you’d like to access data from that model within a server-side custom JavaScript code variable you must use the following interface. This is only available with those and not with client-side code, variables or transformation functions.

Availability: Server-Side Variables

JS
this.package.documents

This is an object that contains all the document objects and structures.

Data type: Array.

Structure: Objects within array with properties such as “documentType” (indicating the type, ie. “user”, “session” or “event”). You’ll find all properties of such an object within the preview (Versions and Preview ) of a version in JTM when inspecting an individual stream on any state (States ).

Here is an example how to iterate that Array and look for a specific property, ie. the consent status of a vendor:

JS
async function(){
    let system_consent_googleanalytics;
    for(let iDocumentCounter = 0; iDocumentCounter < this.package.documents.length; iDocumentCounter++) {
      if(
        typeof this.package.documents[iDocumentCounter]["documentType"] !== "undefined" &&
        this.package.documents[iDocumentCounter]["documentType"] === "event"
      ) {
        system_consent_googleanalytics = this.package.documents[iDocumentCounter].system.consent ? this.package.documents[iDocumentCounter].system.consent.googleanalytics : "tool_googleanalytics_not_found";
        break;
      }
    }
    return system_consent_googleanalytics;
}
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.