Use prebuilt transformations to implement specific use cases on your event data.
RudderStack’s transformation templates provide prebuilt JavaScript functions that you can use to create transformations and implement use cases on your event data. These include event filtering and sampling, replacing or hashing PII (Personally Identifiable Information), anonymizing IPs, and more.
Currently, transformation templates are available only for JavaScript. Python support (applicable for Growth/Enterprise customers) is coming soon.
Using templates
To use transformation templates, go to Collect > Transformations and click Create Transformation.
Under Transformation templates, select the prebuilt template depending on your use case:
To write a transformation from scratch, click Custom transformation.
Transformation templates
RudderStack provides the following prebuilt templates:
Templates for PII management
Use the following templates to easily apply rules for PII management.
IP Anonymization
This transformation changes the last octet of the IP address to zero. For example, the IP 12.214.31.144 is transformed to 12.214.31.0. This protects the privacy rights of your users and reduces the risk of accidentally disclosing their IP addresses.
This transformation replaces or masks sensitive personal data, for example, email, birthday, or social security number, reducing the risk of accidentally disclosing Personally Identifiable Information (PII). You can specify the properties to be masked or replaced and define the masking logic in the code.
The following transformation masks a social security number with zeros:
Templates for data management, enrichment, and quality enforcement
Allowlist
This transformation allows events to reach a downstream destination only if a specific property contains certain values.
Some examples of how you can use this template are:
Allow only certain event names, like Product Added or Order Completed.
Send certain event types to a particular destination, like identify or track.
Send only the events that have a tracking plan linked to the source.
The allowlist transformation is shown below:
exportfunctiontransformEvent(event,metadata){constproperty=event.event;// Edit property; here it is event name
constallowlist=["<VALUE>","<OTHER_VALUE>"];// Edit allowlist contents
if(!property||!allowlist.includes(property))return;returnevent;}
Denylist
This transformation blocks the events from reaching a downstream destination if a specific property contains certain values. For example, you can block all Product Added and Order Completed events or block certain event types (identify, track, etc.).
The denylist transformation is shown below:
exportfunctiontransformEvent(event,metadata){constproperty=event.event;// Edit property, here it is event name
constdenylist=["<VALUE>","<OTHER_VALUE>"];// Edit denylist contents
if(property&&denylist.includes(property))return;returnevent;}
Geolocation Enrichment
This transformation enriches events with the geolocation data using an IP-to-geolocation API. This lets you easily query your events based on the geolocation data, for example, country or city.
The transformation is shown below:
exportasyncfunctiontransformEvent(event,metadata){if(event.request_ip){try{constres=awaitfetchV2("<YOUR_API_ENDPOINT>"+event.request_ip);// Use your paid IP-to-geolocation API endpoint.
event.context.geolocation=res.body;}catch{}}returnevent;}
Parse User Agent
This transformation lets you add the user’s browser, engine, OS, device, and CPU-related information to the events. Adding this user metadata to your user events is helpful when you want to perform downstream actions later, for example, filter events coming from mobile devices.
This template uses the standard RudderStack library User Agent Parser which you can use for your custom transformations.
This transformation sends only a subset of events to a downstream destination. You can anonymize the events and select a random subset from the anonymous events; this allows you to work with a small, manageable amount of data in the destination.
This transformation sets the HTTP headers for your webhook destinations dynamically. It lets you set the headers based on the values in your data.
The transformation is shown below:
exportfunctiontransformEvent(event,metadata){event.header={Authorization:"Basic <credentials>",// Change headers and values
header_2:"value"};returnevent;}
Dynamic Path
This transformation dynamically appends to the URL specified in your webhook destination configuration. This lets you send events to different paths based on the values in your event data. For example, you can send identify events to only to the /users URL path and the group events only to /organizations.
The following transformation appends a /search?email=${email} path to the webhook URL based on the email property present in the event:
exportfunctiontransformEvent(event,metadata){constemail=event.context?.traits?.email;// Change property
if(email)event.appendPath=`/search?email=${email}`;// Change property and appendPath
returnevent;}
Remove Null Properties
This transformation removes all event properties with null values; this is helpful when you want to reduce the number of unnecessary fields generated in downstream destinations.
This transformation enriches the events by fetching user data like location, employment, or social media details using the Clearbit API and their email address. It is helpful when sending events with additional user metadata to various downstream destinations.
This transformation renames the properties to conform with the appropriate naming convention expected by the downstream destination, for example, first_name to firstName.
This transformation lets you programmatically extract the query parameters from a URL. For example, in the URL rudderstack.com/transformations?publish=true, this transformation identifies the query parameter publish.
When using the Auth0 source to generate events from your website, the userId is prefixed with characters containing Auth0 followed by a pipe (|). This transformation removes any Auth0 userId prefixes.
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.