Contents
Installation Workflow
Before you start: Make sure you can upload files in Libraries > Frameworks and create widgets in Libraries > Widgets. Create or identify a Text field in Data Collection > Data Fields to store the spin result, for example WheelResult.
Step 1: Prepare the minified assets locally
The CSS and JavaScript are in separate code blocks below. Copy each block into its own plain-text file and save it with the filename shown above that block.
Windows (Notepad):
- Launch Notepad.
- Copy the CSS code below and paste it into the file.
- Choose
File > Save As, set “Save as type” to “All Files”, select UTF-8 encoding, and save asixp-ps-widget-wheel-of-fortune.min.css. - Open a new Notepad window.
- Copy the JavaScript code below and paste it into the new file.
- Choose
File > Save As, select “All Files” and UTF-8, and save asixp-ps-widget-wheel-of-fortune.min.js.
macOS (TextEdit):
- Open TextEdit and select
Format > Make Plain Text. - Copy the CSS code below and paste it into the file.
- Save the document as
ixp-ps-widget-wheel-of-fortune.min.css. - Create a new plain-text document.
- Copy the JavaScript code below and paste it into the new file.
- Save the document as
ixp-ps-widget-wheel-of-fortune.min.js.
Linux (Gedit or another plain-text editor):
- Open your preferred plain-text editor (for example, Gedit).
- Copy the CSS code below and paste it into the file.
- Save the file as
ixp-ps-widget-wheel-of-fortune.min.css. - Create a second document.
- Copy the JavaScript code below and paste it into the new file.
- Save the file as
ixp-ps-widget-wheel-of-fortune.min.js.
Any plain-text editor that saves in UTF-8 works. Before uploading, check that the filenames end in .css and .js, with no extra .txt extension.
CSS for ixp-ps-widget-wheel-of-fortune.min.css
div.ixp-ps-widget-wheel-of-fortune{user-select:none;-moz-user-select:none;position:relative;max-width:100%;height:0;padding-bottom:100%}div.ixp-ps-widget-wheel-of-fortune svg{--offset:0;position:absolute;overflow:visible;transition:.2s;transition-timing-function:ease-out;width:100%;height:100%;top:0;left:0}div.ixp-ps-widget-wheel-of-fortune svg>g.wheel{transform:rotate(var(--offset))}div.ixp-ps-widget-wheel-of-fortune svg>g.wheel.spin{animation-name:spin;animation-duration:6s;animation-fill-mode:forwards}div.ixp-ps-widget-wheel-of-fortune svg>g.wheel>g.sector>path{stroke:#fff}div.ixp-ps-widget-wheel-of-fortune svg>g.wheel>g.sector>path:not([fill]){fill:#0c2032}div.ixp-ps-widget-wheel-of-fortune svg>g.wheel>g.sector>text{fill:#000;writing-mode:tb;text-orientation:upright}div.ixp-ps-widget-wheel-of-fortune svg>g.wheel>g.sector>path:not([fill])+text{fill:#fff}div.ixp-ps-widget-wheel-of-fortune svg>g.center>path{cursor:pointer;fill:#0c2032;stroke:#fff}div.ixp-ps-widget-wheel-of-fortune svg>g.center>text{cursor:pointer;fill:#fff}div.ixp-ps-widget-wheel-of-fortune svg>g.center>*{transition:.3s}div.ixp-ps-widget-wheel-of-fortune svg>g.center:hover>*{transform:scale(1.3)}@keyframes spin{from{transform:rotate(var(--offset))}to{transform:rotate(var(--target))}}
Updating a wheel you already installed? Replace the framework JavaScript with the version below. To use the optional spin flag, also update the widget embed in Step 3 and add the Spin Flag Field Name variable. Test in a creative before updating a shared widget.
JavaScript for ixp-ps-widget-wheel-of-fortune.min.js
!function(){const svgNamespace=["http:","www.w3.org/2000/svg"].join("//");const t=function({onClick:t=(()=>{}),items:e=[],playOnce:n=!1,hasPlayed:r=!1,parent:a}){if(!a)throw new Error("No target node provided");const o={onClick:t,items:e,playOnce:n,hasPlayed:r,parent:a,radius:200,sectorCount:Math.max(e.length,2)},s=(t=1,e=0)=>Math.floor(Math.random()*t)+e,l=({radius:t,sectorCount:e,items:n})=>{const r=document.createElementNS(svgNamespace,"svg");r.setAttribute("viewBox",`-${1.2*t} -${1.2*t} ${2.4*t} ${2.4*t}`);const a=360/e,l=a/2+180,p=i(n,e),u=document.createElementNS(svgNamespace,"g");u.setAttribute("class","wheel"),r.appendChild(u);for(let r=0;r<e;++r){const o=l+a*r,s=l+a*(r+1),c=f(e-r+p,e);d(o,s,u,n[c],t)}return c(r,"Spin"),r.addEventListener("click",function(t){switch(t.target.parentNode.getAttribute("class").split(" ")[0]){case"center":((t,{sectorCount:e,playOnce:n,hasPlayed:r,items:a,onClick:l})=>{if(o.spinning||1==n&&1==r)return;o.spinning=!0;const c=360/e,d=s(e),p=i(a,e),u=f(e-d+p,e),h=`${(e-u)*c+360*s(2,4)}`;t.style.setProperty("--target",h+"deg"),y(t,"spin").then(e=>{t.style.setProperty("--offset",Math.floor(h%360)+"deg"),e.target.classList.remove("spin"),l(a[u],saved=>{o.spinning=!1;if(saved)o.hasPlayed=!0})})})(r.querySelector("g.wheel"),o)}}),r},c=(t,e)=>{const n=document.createElementNS(svgNamespace,"g");n.setAttribute("class","center");const r=document.createElementNS(svgNamespace,"path");r.setAttribute("d","m -9 -24 l 9 -16 l 9 16 a 25 25 0 1 1 -18 0 z"),n.appendChild(r);const a=u(0,3,e);n.appendChild(a),t.appendChild(n)},i=(t,e)=>t.length<e&&length<4?-2:-1,d=(t,e,n,r,a)=>{const o=document.createElementNS(svgNamespace,"g"),s=document.createElementNS(svgNamespace,"path");if(s.setAttribute("class","sector-path"),r.backgroundColor&&s.setAttribute("fill",r.backgroundColor),s.setAttribute("d",p(t,e,a)),o.appendChild(s),o.setAttribute("class","sector"),o.setAttribute("data-id",r.id),r.label){const n=h(t,e,1.9*a),s=-1*(t+(e-t)/2-180),l=u(n.x,n.y,r.label,s,"start");o.appendChild(l)}n.appendChild(o)},p=(t,e,n)=>{const r=w(t,n);let a="M"+m(r);return a+=`A${n} ${n} 0 0 0 ${m(w(e,n))}`,a+="L 0 0",a+="Z"},u=(t,e,n,r,a)=>{const o=document.createElementNS(svgNamespace,"text");return t=g(t),e=g(e),r=r||0,a=a||"middle",o.setAttribute("text-anchor",a),o.setAttribute("transform",`rotate(${r}, ${t}, ${e})`),o.setAttribute("x",t),o.setAttribute("y",e),o.innerHTML=n,o},h=(t,e,n)=>w((t+e)/2,n/2),w=(t,e)=>({x:Math.sin(b(t))*e,y:Math.cos(b(t))*e}),m=t=>`${g(t.x)} ${g(t.y)}`,g=t=>{if(Number.isInteger(t))return t.toString();if(t){let e=(+t).toFixed(5);return e.match(/\./)&&(e=e.replace(/\.?0+$/,"")),e}},f=(t,e)=>(t<0&&(t=e+t),t>=e&&(t-=e),t<e?t:null),b=t=>t*(Math.PI/180),y=(t,e)=>new Promise(function(n){t.addEventListener("animationend",function e(r){t.removeEventListener("animationend",e),n(r)}),t.classList.add(e)});return{create:()=>{const t=l(o);o.parent.appendChild(t)}}};
const runtime = window.ixp.runtime;
function decodeJson(value) {
const div = document.createElement("div");
div.innerHTML = value;
return JSON.parse(div.textContent);
}
function followAction(action) {
if (!action) return;
const target = new URL(action, location.href);
const current = new URL(location.href);
const samePage = target.origin === current.origin &&
target.pathname === current.pathname && target.search === current.search;
location.assign(target.href);
if (samePage && (target.hash || current.hash)) location.reload();
}
function initialize({
scriptElement, data, dataField, sliceColors = "", hasPlayed = "",
playOnlyOnce = "", action = "", spinFlagField = ""
}) {
const parent = scriptElement.closest("div");
parent.classList.add("ixp-ps-widget-wheel-of-fortune");
const resultField = dataField.trim();
const flagField = spinFlagField.trim();
if (!resultField || (flagField && flagField.toLowerCase() === resultField.toLowerCase())) {
console.warn("Wheel of Fortune needs a result field and a separate field for the optional spin flag.");
return;
}
let colors = [];
if (sliceColors.trim()) {
try {
colors = decodeJson(sliceColors);
} catch (error) {
console.warn("Wheel of Fortune could not read the optional colors.", error);
}
}
let items;
try {
const slices = decodeJson(data);
if (!Array.isArray(slices) || slices.length < 2) {
throw new Error("Wheel Contents needs at least two slices.");
}
items = slices.map((slice, index) => {
const [label, value] = Object.entries(slice)[0];
return { id: label + "-" + index, label, value, backgroundColor: colors && colors[index] };
});
} catch (error) {
console.warn("Wheel of Fortune could not read the slice settings.", error);
return;
}
t({
parent,
items,
playOnce: !!playOnlyOnce,
hasPlayed: !!hasPlayed,
onClick(item, done) {
if (runtime.inStudio) {
done(true);
return;
}
const data = [{ dataField: JSON.stringify({ name: resultField }), value: item.value }];
if (flagField) {
data.push({ dataField: JSON.stringify({ name: flagField }), value: true });
}
runtime.data.save({
data,
success() {
done(true);
followAction(action.trim());
},
error() {
done(false);
console.warn("Wheel of Fortune could not save the spin result.");
}
});
}
}).create();
}
window.ixpPSWidgetDataLayer.forEach(([command, options]) => {
if (command === "init") initialize(options);
});
}();
Step 2: Upload the framework assets
- In Ion, navigate to
Libraries > Frameworks > Ion Framework. - Upload the
ixp-ps-widget-wheel-of-fortune.min.cssandixp-ps-widget-wheel-of-fortune.min.jsfiles you created in Step 1.


- Confirm both files now appear in the framework list before leaving the screen.

Step 3: Register the widget in Ion
- Navigate to
Libraries > Widgets, click Create New Widget, and select an existing widget category (or add a new one for the wheel widget).

- In the widget editor, name the widget and confirm its category. Copy the entire Widget embed code, including the opening and closing
<script>tags, and paste it into Widget code & variables. Keep the##variable tokens and the{{##dataField}}merge field as shown. Set their values when you add the widget to a creative.

Widget embed code
<script>
(function (d, s, id, src, fjs) {
if (d.getElementById(id)) return;
fjs = d.getElementsByTagName(s)[0];
s = d.createElement(s);
s.id = id;
s.rel = "stylesheet";
s.href = src;
fjs.parentNode.insertBefore(s, fjs);
})(
document,
"link",
"ixp-ps-wof-css",
"/Templates/ion/ion_Framework_v4.0/ixp-ps-widget-wheel-of-fortune.min.css"
);
(function (d, s, id, src, fjs) {
if (d.getElementById(id)) return;
fjs = d.getElementsByTagName(s)[0];
s = d.createElement(s);
s.id = id;
s.src = src;
s.async = true;
fjs.parentNode.insertBefore(s, fjs);
})(
document,
"script",
"ixp-ps-wof-js",
"/Templates/ion/ion_Framework_v4.0/ixp-ps-widget-wheel-of-fortune.min.js"
);
window.ixpPSWidgetDataLayer = window.ixpPSWidgetDataLayer || [];
function ixpPSWidget() {
ixpPSWidgetDataLayer.push(arguments);
}
ixpPSWidget("init", {
data: ` ##dataJSON `,
sliceColors: ` ##colorJSON `,
dataField: "##dataField",
spinFlagField: "##spinFlagField",
hasPlayed: `{{##dataField}}`,
scriptElement: document.currentScript,
playOnlyOnce: "##playOnlyOnce",
action: "##action",
});
</script>
- Ion detects the variable names from the embed code. Use the recommended settings below to configure their labels, types, and required settings.


- For each detected variable, select Add Variable. Keep the Variable name as shown in the table so it matches the embed code. Use the listed Label so it matches this guide, then choose the Type and Required setting shown.
- Click OK and repeat for all six variables.
Recommended settings for widget variables in Ion:
| Variable | Label | Type | Required |
| action | Action Trigger | Action | no |
| colorJSON | Background Colors | Text | no |
| dataField | DataField Name | Text | yes |
| dataJSON | Wheel Contents | Text | yes |
| playOnlyOnce | Can only play once | Text | no |
| spinFlagField | Spin Flag Field Name | Text | no |
- Save the widget so it becomes available in creatives.
Usage Configuration
- Drag the widget into your creative (
Elements palette > Basics > Widget), then select the widget name configured above.

- Fill in the widget settings using the values below. Paste each JSON example on one line.
- Wheel Contents needs at least two slices. Copy the one-line example below into the field to try it. Each pair gives Ion the label to display and the value to save on the respondent record.
- Background Colors is optional. To set custom colors, paste a one-line list in slice order, for example
["#FFD166","#90E0EF"]for the two slices below. - DataField Name is the exact name of your existing Text field, for example
WheelResult. - Spin Flag Field Name is optional. Leave it blank for a basic wheel. If you use the lightbox workflow below, enter the name of a separate Text field, for example
justSpun. Ion sets this field totruewhen it saves a spin result. - Can only play once accepts
trueto limit the respondent to one spin. Leave it blank to allow repeat spins. Any text, includingfalse, enables the one-spin limit.
Two-slice example to paste into Wheel Contents
[{"Win":"win"},{"Lose":"lose"}]
Optional 12-slice example
[{"Win":true},{"Win":true},{"Win":true},{"Lose":false},{"Lose":false},{"Lose":false},{"Win":true},{"Win":true},{"Win":true},{"Lose":false},{"Lose":false},{"Lose":false}]
Tip: If the wheel stays blank, paste the two-slice example again. It needs at least two slices and valid JSON. Edit any custom values in a plain-text editor and keep the finished list on one line.
Optional Workflow: Win/Lose Lightboxes
- Create two separate Text fields in Data Collection > Data Fields, for example
justSpunfor the spin flag andShowWinnerfor the result to display once. EnterjustSpunin Spin Flag Field Name and keep DataField Name set to your result field (for exampleWheelResult). Set Action Trigger to return to the current page. The wheel follows the action after Ion saves both fields. - Add two page-load rules in this order. First, clear
ShowWinneron every load. Second, ifjustSpunequalstrue, copy the saved result fromWheelResulttoShowWinner, then clearjustSpun. Keep the saved result inWheelResultso the one-spin setting can still use it.

- Place two lightboxes under the wheel, set them to open on page load, and hide their launch buttons. Show each lightbox only when
ShowWinnermatches its result exactly. The two-slice example useswinandlose. The 12-slice example usestrueandfalse. Neither lightbox should open whenShowWinneris empty.


Testing Checklist
- Open a test creative outside Creative Studio as a fresh respondent. Check that both asset URLs from the embed code load, then spin and confirm the configured data field contains the result.
- With Can only play once set to
true, reload the page with a result already saved and confirm a second spin is blocked. With the setting blank, confirm another spin is possible. - If you configured an Action Trigger, verify that the redirect opens the intended page after the result saves, including on a slow connection. For lightboxes, test a win and a loss with fresh respondents. Refresh after each outcome and confirm the lightbox stays closed.
- Validate any custom slice colors render as expected and contrast with the text labels.