About data transformation functions

This article provides an overview of data transformation functions.

Data transformation functions are invoked after an event is collected from the data source and before the event is processed and can be used for a variety of purposes, including the following:

  • Flattening the event object passed to the function.
  • Removing sensitive data, such as a phone number or an email address.
  • Modifying variables in the event object. For example, you can change variables to lower-case.
  • Populating variables in the event object based on other values.
  • Renaming variables, which is done by assigning the value to a different variable and deleting the original variable.

File import events are not currently supported for data transformation functions.

Input to a data transformation function

Data transformation functions have one input parameter, event, which contains the event data from Tealium Collect. The event parameter is a metadata object that contains several properties and nested objects describing the event. The actual event data is referenced in the event.data.udo object. For more information, see Event Input Parameter

In addition, the Tealium module exports the flatten() utility for data transformation functions, which converts a nested object into a new object with no nesting.

Custom triggers

Data transformation functions are invoked based on the custom trigger for the function. A custom trigger is a rule you create to specify when to execute a function. The conditions can be based on any property of the event parameter, but are commonly based on the data source key, data source platform, and the tealium_event attribute. For more information on the event parameter, see Event Parameter.

Custom trigger rules are similar to load rules and use boolean logic to combine conditions in a rule. For example, in the following rule, the function is triggered when a purchase event comes from a specific data source (r2rbm8).

transfm-conditions-example.png

A condition is based on a selector that specifies a property in the event parameter object, a comparison operator, and a comparison value. A selector is a JSONPath expression (see JSONPath) and can reference any property in event.

An event can trigger only one function. If an event matches more than one function trigger, the function with the oldest Date Modified is the only function that is triggered.

For information on creating a data transformation function and a custom trigger, see Create a function.

For examples of data transformation functions, see Example Code.

Rule limitations

  • Selector and Value fields are limited to 128 characters.
  • The regular expression operator is not available.
  • The size of a rule is limited to 10 KB.
  • The number of OR blocks is limited to 10.
  • The number of conditions in an AND block is limited to 10.

Default function code

When you create a data transformation function, default code is shown in the Code tab. The default code imports the flatten library and calls transform(event), where the event parameter is a metadata object for the incoming event, then flattens the incoming event object. Change the default transform() code as needed to modify the event attributes in the event.data.udo object.

import flatten from "tealium/util/flatten";
// "transform" function allows you to access event and apply changes

transform((event) => {
    // changes are applied via mutation of the original event
    event.data.udo = flatten(event.data.udo);
    console.log(JSON.stringify(event, null, 2));
})

Conversion of existing functions to custom triggers

Custom triggers were introduced after the initial release of data transformation functions. For any data transformation functions that existed before custom triggers were introduced, a condition similar to the following is automatically created:

transfm-conversion-edit-cond.png

This new condition specifies the data source ID, which is set to the ID of the data source associated with the function. The function is triggered for every event from the data source. You can edit this condition to trigger the function for more specific events.

Was this page helpful?

This page was last updated: January 7, 2023