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
You’ll create your scriptlet outside of Ion and then add it to the library.
- Navigate to Libraries > Server Scriptlets
- Click green “New scriptlet category” and give it a label
- Click green “New scriptlet” button and label the scriptlet
- Paste or write custom Javascript into the scriptlet field
- Note, use server-side Javascript (ECMAScript Version 3) to process data. The script should return a string or null.
- Save
2. Use rules to run your scriptlet(s) on your Ion pages
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.
- Navigate to the page you want your script to run on
- Click on the “rules” 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’s submit button and then open the rules editor from within the Edit tab of your creative studio.
- Add a rule condition to trigger the scriptlet. If you want the scriptlet to run unconditionally upon page load or form submission, select “No conditions required”.
- Add the action labeled “Run server scriptlet” and select the scriptlet from the dropdown to the right.
- To base action(s) from the scriptlet’s result(s), add a new rule with the condition being “Server scriptlet result”, select the scriptlet, and input the result value.
- Add an action to trigger based on the scriptlet’s result value.
Let’s say you added a scriptlet to your console that calculates the respondent’s 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. Here’s an example of what your rules might look like to accomplish this:
Condition: No conditions required
Action: Run server scriptlet – Age Calculation
Condition: Server scriptlet result – Age Calculation – less than – 19
Action: Go to next page – “Not qualified to register”
Mobile detection Scriptlet
We’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 “true” value to a mobile-optimized page. The scriptlet also saves the smartphone type into a data collection field and tags the respondent, giving you heightened visibility into the devices your smartphone audience uses.