
If you’ve worked in Launch for any amount of time, you’ve likely written the same code multiple times across rules, conditions, and actions, especially for tasks like getting or setting cookies.
This duplication leads to:
- Harder maintenance
- Risk of inconsistent updates
- Slight performance overhead
- Less organized and readable implementations
One way to handle this is by creating helper functions using Custom Code Data Elements. This technique allows you to reuse common logic, such as cookie handling, throughout your implementation without duplicating code.
Implementation Steps
- Go to Data Elements in Launch.
- Create a new Data Element.
- Set the type to Custom Code.
- Paste your helper function inside.
- In your tags or other variables, reference the helper function using _satellite.getVar(‘dataElementName’).
- Assign it to a local variable before using it.
- Execute it, passing the parameters defined in the function.
Example 1: setCookie
This function sets a cookie with a name, value, and expiration date (in days). Follow the implementation steps defined above and use the next code for your setCookie data element:
var setCookie = function(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
return setCookie;
Your custom code data element should look like this:


Example2: getCookie
This function retrieves the value of a cookie by name. Follow the implementation steps defined above and use the next code for your getCookie data element:
var getCookie = function(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
};
return getCookie;
Your custom code data element should look like this:


How to Use These Functions
Anywhere in Adobe Launch where you can run JavaScript, inside tags or other data elements, you can reference your helper functions using _satellite.getVar()
.
Example:
var setCookie = _satellite.getVar('setCookie');
setCookie('userType', 'premium', 30);
Or
var getCookie = _satellite.getVar('getCookie');
var userType = getCookie('userType');
Best Practice: store the function in a local variable before calling it. This avoids executing _satellite.getVar()
multiple times and keeps your code clean.
Benefits of helper functions
- Centralized Logic – Update one data element, and all references use the latest version.
- Performance – Avoid redundant code execution by initializing once.
- Maintainability – Easier to read, update, and scale.
Conclusion
Using Custom Code Data Elements in Adobe Launch to define reusable functions is a simple but powerful way to optimize your implementation. Whether you’re handling cookies, query strings, or conditional logic, turning repeated patterns into helper functions can save time, reduce bugs, and improve long-term maintainability.