This article provides information on the APIs and libraries available for functions.
Functions can use the following APIs and libraries:
Crypto-ES.js is a library of encryption algorithms available that provides hashing, encoding, and cipher algorithms. For more information, see Crypto-ES.
The following example shows how to encrypt and decrypt text:
import CryptoES from 'crypto-es'; var encrypted = CryptoES.AES.encrypt("Message", "Secret Passphrase"); console.log(encrypted); var decrypted = CryptoES.AES.decrypt(encrypted, "Secret Passphrase"); console.log(CryptoES.enc.Utf8.stringify(decrypted));
TweetNaCl is a crypto library that implements secret-key authenticated encryption, public-key authenticated encryption, and hashing and public-key signatures. The TweetNaCl library is available only for event and visitor functions.
Import the TweetNaCl.js module into your event or visitor function as follows:
import nacl from 'tweetnacl';
For more information, see NPM TweetNaCl.js.
console.debug() log messages go to the info output stream.
console.error() log messages go to the error output stream.
The info and error output streams are each limited to 10 Kb of data per function invocation. If log messages exceed this limit, the log file will contain the first 10 Kb of data and end with the following message:
Output was too large and has been truncated.
Console API output
The output from most console functions is shown in the Messages section of the Logs display. For example:
Messages: Function Start
console.error() is shown in the Errors section, below the Messages output, as follows:
Errors: Warning - page not found Error - variable not defined
If a function is triggered on EventStream and
console.assert() is called as follows:
console.assert(visitor, "visitor not defined");
visitor object is only defined when the trigger is AudienceStream, so the assertion is false and the output is as follows:
Assertion failed: visitor not defined
console.group() and console.groupEnd()
console.groupEnd() can be used to format related messages in the log.
console.log() messages that follow
console.group() are indented in the log. The indentation ends after
console.groupEnd() is called.
If the function code contains the following:
console.group("Event info:"); console.log("Account: ", event.account); console.log("Visitor ID: ", event.visitor_id); console.groupEnd();
The output is as follows:
Event info: Account: Acme Mfg Visitor ID: 017407a1d9e50019633c3cea732703079011607100bd6
console.time() and console.timeLog()
When a function calls
console.time(), there is no output. The time that
console.time() was called with that string is noted. When
console.timeLog() is called with the same string,
"Current Time: " in this example, the output is the specified string followed by the time elapsed since
console.time() was called:
Current Time: : 1ms
After a function calls
console.timeLog() cannot be called until
console.time() is called again.
console.count() and console.countReset()
console.count() is called with the same string, the count is incremented. The output of
console.count() is the string followed by the count. If
console.count("Current count: "); is called twice, the output is as follows:
Current count: : 1 Current count: : 2
console.countReset() resets the count for the specified string to zero.
Thank you for your feedback!
This page was last updated: January 7, 2023