{"id":257,"date":"2025-06-18T13:37:04","date_gmt":"2025-06-18T19:37:04","guid":{"rendered":"https:\/\/blog.alejandrobecerril.com\/?p=257"},"modified":"2026-03-02T18:58:10","modified_gmt":"2026-03-03T00:58:10","slug":"create-helper-functions-in-adobe-launch-data-collection","status":"publish","type":"post","link":"https:\/\/blog.alejandrobecerril.com\/es\/create-helper-functions-in-adobe-launch-data-collection\/","title":{"rendered":"Create Helper Functions in Adobe Launch (Data Collection)"},"content":{"rendered":"<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"385\" src=\"https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-17-125708-1024x385.png\" alt=\"\" class=\"wp-image-255\" srcset=\"https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-17-125708-1024x385.png 1024w, https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-17-125708-300x113.png 300w, https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-17-125708-768x289.png 768w, https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-17-125708-18x7.png 18w, https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-17-125708.png 1290w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p>If you&#8217;ve worked in Launch for any amount of time, you&#8217;ve likely written the same code multiple times across rules, conditions, and actions, especially for tasks like getting or setting cookies.<\/p>\n\n\n\n<p>This duplication leads to:<\/p>\n\n\n\n<ul>\n<li>Harder maintenance<\/li>\n\n\n\n<li>Risk of inconsistent updates<\/li>\n\n\n\n<li>Slight performance overhead<\/li>\n\n\n\n<li>Less organized and readable implementations<\/li>\n<\/ul>\n\n\n\n<p>One way to handle this is by creating <strong>helper functions<\/strong> using <strong>Custom Code Data Elements<\/strong>. This technique allows you to reuse common logic, such as cookie handling, throughout your implementation without duplicating code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation Steps<\/h2>\n\n\n\n<ul>\n<li>Go to <strong>Data Elements<\/strong> in Launch.<\/li>\n\n\n\n<li>Create a new Data Element.<\/li>\n\n\n\n<li>Set the type to <strong>Custom Code<\/strong>.<\/li>\n\n\n\n<li>Paste your helper function inside.<\/li>\n\n\n\n<li>In your tags or other variables, reference the helper function using _satellite.getVar(&#8216;dataElementName&#8217;).<\/li>\n\n\n\n<li>Assign it to a local variable before using it.<\/li>\n\n\n\n<li>Execute it, passing the parameters defined in the function.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 1<\/strong>: setCookie<\/h3>\n\n\n\n<p>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:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var setCookie = function(cname, cvalue, exdays) {\n     var d = new Date();\n     d.setTime(d.getTime() + (exdays*24*60*60*1000));\n     var expires = \"expires=\"+ d.toUTCString();\n     document.cookie = cname + \"=\" + cvalue + \";\" + expires + \";path=\/\";\n }\n return setCookie;<\/code><\/pre>\n\n\n\n<p>Your custom code data element should look like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"857\" height=\"522\" src=\"https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-4.png\" alt=\"\" class=\"wp-image-260\" srcset=\"https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-4.png 857w, https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-4-300x183.png 300w, https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-4-768x468.png 768w, https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-4-18x12.png 18w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"695\" height=\"231\" src=\"https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-2.png\" alt=\"\" class=\"wp-image-258\" srcset=\"https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-2.png 695w, https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-2-300x100.png 300w, https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-2-18x6.png 18w\" sizes=\"(max-width: 695px) 100vw, 695px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example2:&nbsp;<\/strong>getCookie<\/h3>\n\n\n\n<p>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:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var getCookie = function(cname) {\n    var name = cname + \"=\";\n    var decodedCookie = decodeURIComponent(document.cookie);\n    var ca = decodedCookie.split(';');\n    for (var i = 0; i &lt; ca.length; i++) {\n        var c = ca&#91;i];\n        while (c.charAt(0) == ' ') {\n            c = c.substring(1);\n        }\n        if (c.indexOf(name) == 0) {\n            return c.substring(name.length, c.length);\n        }\n    }\n    return \"\";\n};\nreturn getCookie;<\/code><\/pre>\n\n\n\n<p>Your custom code data element should look like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"826\" height=\"509\" src=\"https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-5.png\" alt=\"\" class=\"wp-image-261\" srcset=\"https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-5.png 826w, https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-5-300x185.png 300w, https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-5-768x473.png 768w, https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-5-18x12.png 18w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"693\" height=\"372\" src=\"https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-6.png\" alt=\"\" class=\"wp-image-262\" srcset=\"https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-6.png 693w, https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-6-300x161.png 300w, https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/image-6-18x10.png 18w\" sizes=\"(max-width: 693px) 100vw, 693px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">How to Use These Functions<\/h2>\n\n\n\n<p>Anywhere in Adobe Launch where you can run JavaScript, inside tags or other data elements, you can reference your helper functions using <code>_satellite.getVar()<\/code>.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var setCookie = _satellite.getVar('setCookie');\nsetCookie('userType', 'premium', 30);<\/code><\/pre>\n\n\n\n<p>Or<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var getCookie = _satellite.getVar('getCookie');\nvar userType = getCookie('userType');<\/code><\/pre>\n\n\n\n<p><strong>Best Practice:<\/strong> store the function in a local variable before calling it. This avoids executing <code>_satellite.getVar()<\/code> multiple times and keeps your code clean.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Benefits of helper functions<\/h2>\n\n\n\n<ul>\n<li><strong>Centralized Logic<\/strong> \u2013 Update one data element, and all references use the latest version.<\/li>\n\n\n\n<li><strong>Performance<\/strong> \u2013 Avoid redundant code execution by initializing once.<\/li>\n\n\n\n<li><strong>Maintainability<\/strong> \u2013 Easier to read, update, and scale.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Final Thoughts<\/h2>\n\n\n\n<p>Using <strong>Custom Code Data Elements<\/strong> in Adobe Launch to define reusable functions is a simple but powerful way to optimize your implementation. Whether you&#8217;re handling cookies, query strings, or conditional logic, turning repeated patterns into helper functions can save time, reduce bugs, and improve long-term maintainability.<\/p>","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve worked in Launch for any amount of time, you&#8217;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: One way to handle this is by creating helper functions using Custom Code Data Elements. This technique allows you to &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.alejandrobecerril.com\/es\/create-helper-functions-in-adobe-launch-data-collection\/\" class=\"more-link\">Continuar leyendo<span class=\"screen-reader-text\"> &#8220;Create Helper Functions in Adobe Launch (Data Collection)&#8221;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[36],"tags":[12,19],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Create Helper Functions in Adobe Launch (Data Collection) - Alejandro Becerril<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.alejandrobecerril.com\/es\/create-helper-functions-in-adobe-launch-data-collection\/\" \/>\n<meta property=\"og:locale\" content=\"es_MX\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create Helper Functions in Adobe Launch (Data Collection) - Alejandro Becerril\" \/>\n<meta property=\"og:description\" content=\"If you&#8217;ve worked in Launch for any amount of time, you&#8217;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: One way to handle this is by creating helper functions using Custom Code Data Elements. This technique allows you to &hellip; Continuar leyendo &quot;Create Helper Functions in Adobe Launch (Data Collection)&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.alejandrobecerril.com\/es\/create-helper-functions-in-adobe-launch-data-collection\/\" \/>\n<meta property=\"og:site_name\" content=\"Alejandro Becerril\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-18T19:37:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-03T00:58:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-17-125708-1024x385.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.alejandrobecerril.com\/#website\",\"url\":\"https:\/\/blog.alejandrobecerril.com\/\",\"name\":\"Alejandro becerril - Marketing, C\\u00f3digo y Negocios\",\"description\":\"Data Solutions | Marketing Intelligence | Technology\",\"publisher\":{\"@id\":\"https:\/\/blog.alejandrobecerril.com\/#\/schema\/person\/3967f8b514fab90a660d896cbf407486\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/blog.alejandrobecerril.com\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"es-MX\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/blog.alejandrobecerril.com\/create-helper-functions-in-adobe-launch-data-collection\/#primaryimage\",\"inLanguage\":\"es-MX\",\"url\":\"https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-17-125708.png\",\"contentUrl\":\"https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-17-125708.png\",\"width\":1290,\"height\":485},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.alejandrobecerril.com\/create-helper-functions-in-adobe-launch-data-collection\/#webpage\",\"url\":\"https:\/\/blog.alejandrobecerril.com\/create-helper-functions-in-adobe-launch-data-collection\/\",\"name\":\"Create Helper Functions in Adobe Launch (Data Collection) - Alejandro Becerril\",\"isPartOf\":{\"@id\":\"https:\/\/blog.alejandrobecerril.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/blog.alejandrobecerril.com\/create-helper-functions-in-adobe-launch-data-collection\/#primaryimage\"},\"datePublished\":\"2025-06-18T19:37:04+00:00\",\"dateModified\":\"2026-03-03T00:58:10+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/blog.alejandrobecerril.com\/create-helper-functions-in-adobe-launch-data-collection\/#breadcrumb\"},\"inLanguage\":\"es-MX\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.alejandrobecerril.com\/create-helper-functions-in-adobe-launch-data-collection\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.alejandrobecerril.com\/create-helper-functions-in-adobe-launch-data-collection\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Inicio\",\"item\":\"https:\/\/blog.alejandrobecerril.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Create Helper Functions in Adobe Launch (Data Collection)\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/blog.alejandrobecerril.com\/create-helper-functions-in-adobe-launch-data-collection\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/blog.alejandrobecerril.com\/create-helper-functions-in-adobe-launch-data-collection\/#webpage\"},\"author\":{\"@id\":\"https:\/\/blog.alejandrobecerril.com\/#\/schema\/person\/3967f8b514fab90a660d896cbf407486\"},\"headline\":\"Create Helper Functions in Adobe Launch (Data Collection)\",\"datePublished\":\"2025-06-18T19:37:04+00:00\",\"dateModified\":\"2026-03-03T00:58:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blog.alejandrobecerril.com\/create-helper-functions-in-adobe-launch-data-collection\/#webpage\"},\"wordCount\":356,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/blog.alejandrobecerril.com\/#\/schema\/person\/3967f8b514fab90a660d896cbf407486\"},\"image\":{\"@id\":\"https:\/\/blog.alejandrobecerril.com\/create-helper-functions-in-adobe-launch-data-collection\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/blog.alejandrobecerril.com\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-17-125708-1024x385.png\",\"keywords\":[\"adobe launch\",\"javascript\"],\"articleSection\":[\"Adobe Launch\"],\"inLanguage\":\"es-MX\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/blog.alejandrobecerril.com\/create-helper-functions-in-adobe-launch-data-collection\/#respond\"]}]},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/blog.alejandrobecerril.com\/#\/schema\/person\/3967f8b514fab90a660d896cbf407486\",\"name\":\"Alejandro Becerril\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/blog.alejandrobecerril.com\/#personlogo\",\"inLanguage\":\"es-MX\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/15ec3fc837a9f7ce7e24092347a222f4?s=96&d=retro&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/15ec3fc837a9f7ce7e24092347a222f4?s=96&d=retro&r=g\",\"caption\":\"Alejandro Becerril\"},\"logo\":{\"@id\":\"https:\/\/blog.alejandrobecerril.com\/#personlogo\"},\"sameAs\":[\"https:\/\/blog.alejandrobecerril.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/blog.alejandrobecerril.com\/es\/wp-json\/wp\/v2\/posts\/257"}],"collection":[{"href":"https:\/\/blog.alejandrobecerril.com\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alejandrobecerril.com\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alejandrobecerril.com\/es\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alejandrobecerril.com\/es\/wp-json\/wp\/v2\/comments?post=257"}],"version-history":[{"count":2,"href":"https:\/\/blog.alejandrobecerril.com\/es\/wp-json\/wp\/v2\/posts\/257\/revisions"}],"predecessor-version":[{"id":275,"href":"https:\/\/blog.alejandrobecerril.com\/es\/wp-json\/wp\/v2\/posts\/257\/revisions\/275"}],"wp:attachment":[{"href":"https:\/\/blog.alejandrobecerril.com\/es\/wp-json\/wp\/v2\/media?parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alejandrobecerril.com\/es\/wp-json\/wp\/v2\/categories?post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alejandrobecerril.com\/es\/wp-json\/wp\/v2\/tags?post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}