Configure your RudderStack destination dynamically via event payload properties.
4 minute read
The dynamic settings configuration feature is supported in the RudderStack destinations that allow sending data via cloud mode. This way, you can configure the destinations based on data in an event payload.
Use this feature to configure multiple instances of the same destination programmatically with different configurations for specific fields.
Create the configuration setting template
To use this feature, enter the path of your desired configuration value from the event payload using object notation in a handlebars.js expression, as well as a default value for the setting in case the value is not present:
For example: {{ event.path.to.key || "default_config_value" }}, where
event is the top level object for the event payload
path.to.key is the location of the property you want to make configurable for your destination, e.g., properties.url
"default_config_value" is the default value for the property
If event.path.to.key exists, its value will be passed as a configuration setting to your destination. If not present, RudderStack will send the default value that you supply in the expression.
To set a number as the default value, set it as a string.
In case of a multi-word string, we recommend setting the value within double quotes, e.g. "default value".
The next section walks through an example of dynamic configuration using multiple Google Analytics tracking IDs.
Use Case: Dynamically configure your Google Analytics destination using Tracking ID
Suppose you have implemented two web properties with rudderanalytics.js, each with a unique Universal Analytics (UA) tracking ID. You don’t want to set up different RudderStack destinations for each property; rather, you would like to pass the event data to the appropriate tracking ID in your Google Analytics instance.
To achieve this you will:
Create a transformation that:
adds a trackingId property to your event
sets the appropriate trackingId value based on the RudderStack sourceId for the given web property.
Configure your Google Analytics destination in the RudderStack dashboard with a template that dynamically updates the trackingId property for each event, routing the data to the appropriate GA property.
The following sample code uses the transformation’s metadata() function to determine the sourceId from the metadata object. If the sourceId matches one of your provided IDs, then the associated trackingId is sent to Google Analytics.
If there is no match for the sourceId, the default value that you define in the next step will be passed to Google Analytics.
In the Connection Settings, configure the Tracking ID field:
With the transformation in place and the dynamic tracking ID configured in the connection settings, RudderStack will route the event data to Google Analytics based on the tracking ID in the payload.
FAQ
How should I use this feature? What if I don’t want to use it?
In the text field of a particular connection setting that you want to configure, enter the path of the payload along with a default value in the following format:
If you don’t want to use this feature, you can enter the configuration setting in the dashboard as you normally would.
Can I specify only the payload path without a default value?
We highly recommend setting a payload path along with a default value. This is because if, for some reason, the payload path does not have any value, the default value is passed as the connection setting. If both the values are absent, you will get an error.
My default value is a number starting with 0. What happens if I don’t set it as a string?
If your default value is a number starting with 0, you need to set it as a string. Otherwise, the value will not be accepted and you may encounter an error.
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.