Test functions
This article provides information on testing functions and obtaining data for test payloads.
Use the Test tab in the code editor to test functions. The Test tab shows a sample event payload for the function, which you can modify as needed. You can get test data from your website and save it to use as a test payload. When you run a function in the Test tab, the test payload is sent to the function.
Test a function
Follow these steps to test a function:
- In the code editor, click the Test tab. Modify the test payload as needed.
- To load a saved test payload, click Load Saved Payload and select a test payload from the list.
- To run the function, click Run Test.
The execution result is shown below Test Input. Execution Output and Test Logs are shown below the result.
For data transformation functions, running a test also verifies that the trigger rule matches the test payload. If the rule and payload do not match, the function cannot be triggered and the following message is displayed:
Modify the rule or the payload so that they match and run the test again. - To view a log, click Test Logs, then click a log in the list.
Save a test payload
You can save a maximum of 10 test payloads for testing a function. For information on getting test data, see Get Test Payload Data.
Follow these steps to save a test payload:
- To save a Test Payload for future use, click Save As.
You can save a maximum of 10 test payloads. - Enter a name for the test payload and click Save As.
- Click Apply.
- Click Save/Publish.
Set a saved test payload as the default
- Click Load Saved Payload and select a payload.
- Click the payload menu and select Set Default.
- Click Apply.
- Click Save/Publish.
Delete a saved test payload
You may need to delete a test payload if you have already saved the maximum of 10 test payloads, and need to save another. Follow these steps to delete a test payload:
-
Click the payload menu and then click Delete.
Use caution when deleting saved test payloads. There is no confirmation dialog.
-
Click Apply.
-
Click Save/Publish.
Get test payload data
Suggested test data is shown on the Test tab of the code editor, under Test Input. You can modify the suggested test data as needed. You can also get test data from a log file or use a function to get real data from your website.
To get data from a log file or from your website, make sure you have done the following:
- Configured Tealium IQ to collect data from a website or other source.
- Configured data sources, event feeds, and audiences.
- Verified that the event feed or audience contains the correct data to trigger the function.
Get test data from a log file
This section provides instructions for the following steps to get test data from a log file:
- Create a function to write data to the log.
- Copy the data from the log file to the Test tab.
Create a function to write data to the log file
Follow these steps to write event and visitor data to the log file:
- Create a new function, then delete the example code and enter the following code, which writes the event and visitor data to the console log.
import { event, visitor } from "tealium";
console.log('Event object:' + JSON.stringify(event));
console.log('Visitor object:' +JSON.stringify(visitor));
- Click the Configuration tab, and set Status to ON.
- Click Done, then click Save/Publish.
Wait briefly for the changes to apply.
Copy and format log file data
- Go to your website and do the actions required to trigger the function.
Wait 1 to 2 minutes to allow the data to be collected. - In the Functions Overview, click the function that you created to write data to the log.
- Click the Logs tab, then open a log entry to see the JSON object.
- Copy the JSON code and format it in any JSON formatting tool.
- Click the Test tab, and paste the formatted JSON code into the Test Input editor.
- Click Save As, enter a name for the test input in the pop-up, and click Save As.
Get test data using trace
- In the code editor, create any JavaScript code. For example:
console.log("Hello World!");
- Click the Configuration tab and set the Status to ON, then click Done.
- Save and publish.
- Start the Trace tool. For more information, see Trace.
- On your website, do the actions required to trigger the function.
- In the Trace tool, click the Action Processed notification, then locate the event or visitor object under payload, and copy the object.
- Go to the Test tab, delete the current code, and paste the event or visitor object into the Test Input editor.
- Click Save As, enter a name for the test input in the dialog, and click Save As.
Trace can also be used if you need to test functions that have been published to your site. The trace log includes information for functions.
This page was last updated: May 24, 2023