{"id":2498,"date":"2023-05-24T16:20:50","date_gmt":"2023-05-24T16:20:50","guid":{"rendered":"https:\/\/obo.zoj.mybluehost.me\/uncategorized\/scriptlet-server-scriptlets-for-global-sets-of-page-rules-advanced-functionality\/"},"modified":"2025-09-25T17:05:51","modified_gmt":"2025-09-25T17:05:51","slug":"scriptlet-server-scriptlets-for-global-sets-of-page-rules-advanced-functionality","status":"publish","type":"post","link":"https:\/\/ioninteractive.com\/ionacademy\/scriptlet-server-scriptlets-for-global-sets-of-page-rules-advanced-functionality\/","title":{"rendered":"Scriptlet: Server scriptlets for global sets of page rules &amp; advanced functionality"},"content":{"rendered":"\n<p class=\"\">The power behind scriptlets is that you can write code for advanced, custom logic on your pages, store it centrally then plug it into creatives as needed!<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. Add Scriptlet(s) to your Ion console<\/strong><\/h4>\n\n\n\n<p class=\"\">You&#8217;ll create your scriptlet outside of Ion and then add it to the library.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li class=\"\">Navigate to Libraries > Server Scriptlets<\/li>\n\n\n\n<li class=\"\">Click green \u201cNew scriptlet category\u201d and give it a label<\/li>\n\n\n\n<li class=\"\">Click green \u201cNew scriptlet\u201d button and label the scriptlet<\/li>\n\n\n\n<li class=\"\">Paste or write custom Javascript into the scriptlet field\n<ul class=\"wp-block-list\">\n<li class=\"\">Note, use server-side Javascript (ECMAScript Version 3) to process data. The script should return a string or null.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li class=\"\">Save<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. Use rules to run your scriptlet(s) on your Ion pages<\/strong><\/h4>\n\n\n\n<p class=\"\">Now that your custom Javascript has been added to your console, you can use rules to trigger the script and base actions off of its response.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li class=\"\">Navigate to the page you want your script to run on<\/li>\n\n\n\n<li class=\"\">Click on the \u201crules\u201d button in the Page tab of your creative studio if you want the scriptlet to run on page load. If you would like the scriptlet to run on form submission, click the form\u2019s submit button and then open the rules editor from within the Edit tab of your creative studio.<\/li>\n\n\n\n<li class=\"\">Add a rule condition to trigger the scriptlet. If you want the scriptlet to run unconditionally upon page load or form submission, select \u201cNo conditions required\u201d.<\/li>\n\n\n\n<li class=\"\">Add the action labeled \u201cRun server scriptlet\u201d and select the scriptlet from the dropdown to the right.<\/li>\n\n\n\n<li class=\"\">To base action(s) from the scriptlet\u2019s result(s), add a new rule with the condition being \u201cServer scriptlet result\u201d, select the scriptlet, and input the result value.<\/li>\n\n\n\n<li class=\"\">Add an action to trigger based on the scriptlet\u2019s result value.<\/li>\n<\/ol>\n\n\n\n<p class=\"\">Let\u2019s say you added a scriptlet to your console that calculates the respondent\u2019s age based on a birth date value they input on an ion form. You would run the scriptlet using form-level rules. You could drive respondents under eighteen, for example, to a page explaining they are not qualified to register.&nbsp;Here\u2019s an example of what your rules might look like to accomplish this:<\/p>\n\n\n\n<div class=\"hs-callout-type-tip\" data-hs-callout-type=\"tip\">\n<p><strong>Condition<\/strong>: No conditions required<\/p>\n<p><strong>Action<\/strong>: Run server scriptlet &#8211; Age Calculation<\/p>\n<\/div>\n\n\n\n<div class=\"hs-callout-type-tip\" data-hs-callout-type=\"tip\">\n<p><strong>Condition<\/strong>: Server scriptlet result &#8211; Age Calculation &#8211; less than \u2013 19<\/p>\n<p><strong>Action<\/strong>: Go to next page \u2013 \u201cNot qualified to register\u201d<\/p>\n<\/div>\n\n\n\n<p class=\"\"><strong>Mobile detection Scriptlet<\/strong><\/p>\n\n\n\n<p class=\"\">We&#8217;ve attached a server scriptlet to this post. This scriptlet identifies if the respondent is on a smartphone and assigns a true\/false value accordingly. Using rules, you can run the scriptlet and redirect respondents with a &#8220;true&#8221; value to a <a href=\"https:\/\/ioninteractive.com\/ionacademy\/redirect-options\/\" target=\"_blank\" rel=\"noreferrer noopener\">mobile-optimized page<\/a>. The scriptlet also saves the smartphone type into a data collection field and <a href=\"https:\/\/ioninteractive.com\/ionacademy\/tags-conversions-and-tracking-in-ion\/\" target=\"_blank\" rel=\"noreferrer noopener\">tags<\/a>\u00a0the respondent, giving you heightened visibility into the devices your smartphone audience uses.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li class=\"\"><a href=\"https:\/\/f.hubspotusercontent30.net\/hubfs\/355484\/Mobile_Detection.rtf\" target=\"_blank\" rel=\"noopener\">Mobile_Detection.rtf<\/a><\/li>\n<\/ul>\n\n\n\n<div class=\"attachment-meta meta-group\">Please feel free to contact help@ioninteractive.com for support if you have any questions about leveraging this powerful feature.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The power behind scriptlets is that you can write code for advanced, custom logic on your pages, store it centrally then plug it into creatives as needed! 1. Add Scriptlet(s) to your Ion console [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":5519,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[2082,2078],"tags":[2173,2190],"class_list":["post-2498","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scriptlets","category-the-advanced-capabilites","tag-advanced","tag-scriptlets"],"_links":{"self":[{"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/posts\/2498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/comments?post=2498"}],"version-history":[{"count":4,"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/posts\/2498\/revisions"}],"predecessor-version":[{"id":7866,"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/posts\/2498\/revisions\/7866"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/media\/5519"}],"wp:attachment":[{"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/media?parent=2498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/categories?post=2498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/tags?post=2498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}