
This block reads live subscription data, so it only runs inside a real customer portal. The animation shows what subscribers see.
What it does
A “A gift is waiting for you” card in the customer portal. The subscriber reveals the gift options, picks one, and it's added to their next order at $0 as a one-time item. Once they've claimed it, the card says “You claimed the [gift]” and the other options lock across all their subscriptions and past orders. It only shows on active subscriptions during the campaign dates, can be limited to subscriptions created between two dates, and hides itself if anything fails.
Why it exists
For subscription brands running a limited-time thank-you, like a December gift for subscribers who joined over Black Friday. Picking the gift is something subscribers do themselves, so they know it's coming, unlike a surprise item they might never notice. The merchant controls the window and who qualifies, each subscriber gets one gift in total, and claimed gifts still ship if the card is removed.
The code
Paste it as-is, or download gift-picker.html<style>
/* Gift picker: Skio CPv3 custom extension block.
Active subscribers pick ONE free gift for their next order; the others lock.
SETUP: create gift-only products in Shopify priced at $0 (not on the Online
Store), put their Shopify variant IDs in CONFIG.gifts (platformId), set the
dates, and restyle the colours below to the brand.
Style: 3px black frame, hard offset shadow, square corners, mono labels.
Rules: every declaration !important EXCEPT transform/opacity (animation-only),
font-family inherit (mono only for labels, matching the portal CSS). */
.sb-gift{
--g-ink:#200039; --g-pink:#E879A8; --g-paper:#F8F6FC; --g-accent:#6941C6;
--g-muted:#5b4a73; --g-bd:3px; --g-shadow:7px 7px 0 #000;
--g-mono:"JetBrains Mono",ui-monospace,SFMono-Regular,Menlo,monospace;
container-type:inline-size;
}
:where(.sb-gift) div,:where(.sb-gift) span,:where(.sb-gift) button,:where(.sb-gift) img{
font-family:inherit!important;font-size:inherit!important;font-weight:inherit!important;
line-height:inherit!important;letter-spacing:normal!important;text-transform:none!important;
color:inherit!important;background:none!important;border:0!important;border-radius:0!important;
box-shadow:none!important;margin:0!important;padding:0!important;text-decoration:none!important;
min-width:0!important;min-height:0!important;max-width:none!important;
}
:where(.sb-gift) button{appearance:none!important;-webkit-appearance:none!important;cursor:pointer}
.sb-gift,.sb-gift *{box-sizing:border-box}
.sb-gift[hidden],.sb-gift [hidden][hidden]{display:none!important}
.sb-gift{
display:block!important;width:calc(100% - 10px)!important;margin:0 0 22px!important;padding:0!important;
background:#fff!important;border:var(--g-bd) solid #000!important;box-shadow:var(--g-shadow)!important;
border-radius:0!important;color:var(--g-ink)!important;font-family:inherit!important;
}
.sb-gift .sb-gift__in{display:flex!important;flex-direction:column!important;gap:14px!important;padding:20px!important}
.sb-gift .sb-gift__eyebrow{
display:inline-block!important;align-self:flex-start!important;font-family:var(--g-mono)!important;
font-size:11px!important;font-weight:800!important;letter-spacing:.14em!important;text-transform:uppercase!important;
background:var(--g-pink)!important;color:var(--g-ink)!important;border:2px solid #000!important;
box-shadow:3px 3px 0 #000!important;padding:4px 8px!important;
}
.sb-gift .sb-gift__h{display:block!important;font-size:24px!important;font-weight:900!important;letter-spacing:-.02em!important;line-height:1.1!important;color:var(--g-ink)!important}
.sb-gift .sb-gift__p{display:block!important;font-size:14px!important;line-height:1.45!important;color:var(--g-muted)!important}
.sb-gift .sb-gift__p b{font-weight:800!important;color:var(--g-ink)!important}
.sb-gift button.sb-gift__cta{
display:inline-flex!important;align-items:center!important;justify-content:center!important;gap:8px!important;
align-self:flex-start!important;min-height:46px!important;padding:12px 20px!important;width:auto!important;
background:var(--g-pink)!important;color:var(--g-ink)!important;border:var(--g-bd) solid #000!important;
box-shadow:4px 4px 0 #000!important;border-radius:0!important;
font-family:var(--g-mono)!important;font-size:13px!important;font-weight:800!important;
letter-spacing:.06em!important;text-transform:uppercase!important;line-height:1.2!important;white-space:nowrap!important;
}
.sb-gift button.sb-gift__cta:active{box-shadow:2px 2px 0 #000!important}
.sb-gift button.sb-gift__cta[disabled]{background:#fff!important;color:#8a7fa0!important;border-style:dashed!important;box-shadow:none!important;cursor:not-allowed!important}
.sb-gift button.sb-gift__cta:focus-visible,.sb-gift button.sb-gift__opt:focus-visible{outline:3px solid var(--g-accent)!important;outline-offset:3px!important}
.sb-gift .sb-gift__grid{display:grid!important;grid-template-columns:repeat(3,minmax(0,1fr))!important;gap:12px!important}
.sb-gift button.sb-gift__opt{
display:flex!important;flex-direction:column!important;gap:8px!important;width:100%!important;text-align:left!important;
background:var(--g-paper)!important;border:2px solid #000!important;padding:10px!important;color:var(--g-ink)!important;
position:relative!important;
}
.sb-gift button.sb-gift__opt[aria-checked="true"]{background:var(--g-pink)!important;border-width:3px!important;box-shadow:4px 4px 0 #000!important;padding:9px!important}
.sb-gift button.sb-gift__opt[disabled]{cursor:default!important}
.sb-gift .sb-gift__img{display:block!important;width:100%!important;aspect-ratio:1/1!important;background:#fff!important;border:2px solid #000!important;overflow:hidden!important}
.sb-gift .sb-gift__img img{display:block!important;width:100%!important;height:100%!important;object-fit:cover!important}
.sb-gift .sb-gift__img .sb-gift__ph{display:flex!important;width:100%!important;height:100%!important;align-items:center!important;justify-content:center!important;font-size:34px!important}
.sb-gift .sb-gift__t{display:block!important;font-size:14px!important;font-weight:800!important;line-height:1.2!important}
.sb-gift .sb-gift__v{display:block!important;font-family:var(--g-mono)!important;font-size:11px!important;font-weight:700!important;letter-spacing:.06em!important;text-transform:uppercase!important}
.sb-gift .sb-gift__tick{
position:absolute!important;top:-10px!important;right:-10px!important;width:26px!important;height:26px!important;
display:flex!important;align-items:center!important;justify-content:center!important;
background:#000!important;color:#fff!important;font-size:14px!important;font-weight:900!important;
}
.sb-gift .sb-gift__fine{display:block!important;font-family:var(--g-mono)!important;font-size:11px!important;letter-spacing:.04em!important;color:var(--g-muted)!important}
.sb-gift .sb-gift__err{display:block!important;font-size:13px!important;font-weight:700!important;color:#b42318!important;background:#fef3f2!important;border:2px solid #b42318!important;padding:8px 10px!important}
/* Claimed: the picked gift big, the others dimmed. */
.sb-gift .sb-gift__won{display:flex!important;gap:14px!important;align-items:center!important}
.sb-gift .sb-gift__won .sb-gift__img{width:84px!important;flex:0 0 84px!important}
.sb-gift .sb-gift__rest{display:flex!important;gap:8px!important;align-items:center!important}
.sb-gift .sb-gift__rest .sb-gift__img{width:34px!important;flex:0 0 34px!important;filter:grayscale(1)!important}
.sb-gift .sb-gift__rest .sb-gift__dim{opacity:.4}
/* Motion: transform/opacity only, never !important (see motion.md). */
@media (prefers-reduced-motion:no-preference){
/* transform only: if the timeline is frozen (background tab), a fade would hold the block at opacity 0 */
@keyframes sbGiftDrop{from{transform:translateY(10px)}to{transform:none}}
@keyframes sbGiftStamp{0%{transform:scale(1.4) rotate(-6deg)}100%{transform:scale(1) rotate(0)}}
.sb-gift.is-in{animation:sbGiftDrop 220ms cubic-bezier(.2,0,0,1) both}
.sb-gift .sb-gift__grid.is-in .sb-gift__opt{animation:sbGiftDrop 200ms cubic-bezier(.2,0,0,1) both}
.sb-gift .sb-gift__grid.is-in .sb-gift__opt:nth-child(2){animation-delay:60ms}
.sb-gift .sb-gift__grid.is-in .sb-gift__opt:nth-child(3){animation-delay:120ms}
.sb-gift .sb-gift__grid.is-in .sb-gift__opt:nth-child(4){animation-delay:180ms}
.sb-gift button.sb-gift__cta{transition:transform 80ms linear,box-shadow 80ms linear}
.sb-gift button.sb-gift__cta:active{transform:translate(2px,2px)}
.sb-gift .sb-gift__stamp{animation:sbGiftStamp 260ms cubic-bezier(.2,0,0,1) both}
}
@container (min-width:700px){
.sb-gift .sb-gift__grid{grid-template-columns:repeat(3,minmax(0,210px))!important;gap:16px!important}
}
@container (max-width:440px){
.sb-gift .sb-gift__in{padding:14px!important}
.sb-gift .sb-gift__h{font-size:21px!important}
.sb-gift .sb-gift__grid{grid-template-columns:minmax(0,1fr)!important;gap:10px!important}
.sb-gift button.sb-gift__opt{flex-direction:row!important;align-items:center!important;gap:12px!important}
.sb-gift button.sb-gift__opt .sb-gift__img{width:64px!important;flex:0 0 64px!important}
.sb-gift button.sb-gift__cta{align-self:stretch!important;white-space:normal!important}
}
</style>
<div class="sb-gift" data-sb-gift hidden>
<div class="sb-gift__in" data-g-root></div>
</div>
<script>
(function () {
'use strict';
/* ===================== SETTINGS: edit these, then save =====================
Dates: ISO format WITH a time zone offset, e.g. '2026-12-31T23:59:59-08:00'
(-08:00 = Pacific). Without one, '2026-12-31' means midnight UTC, which is
the afternoon of Dec 30 in California. Use '' to switch a check off.
campaignStart / campaignEnd
When customers can claim. Outside it, anyone who hasn't claimed doesn't
see the block. Customers who already claimed keep seeing "You claimed…".
Claimed gifts ship on their next order even after the end date, or if
the block is removed.
eligibleCreatedFrom / eligibleCreatedTo
Which subscriptions qualify, by the date the subscription was created
(e.g. BFCM sign-ups). Migrated subscriptions carry their migration date.
gifts
One entry per gift: platformId = the $0 gift product's Shopify variant
ID, plus title, image URL and value (shown as "worth $X"; remove it for
multi-currency stores).
copy
Every line of text the customer sees.
Dates are checked against the customer's own device clock.
============================================================================ */
var CONFIG = {
"gifts": [
{
"key": "gift1",
"title": "Gift one",
"value": 0,
"skioVariantId": "",
"platformId": "gid://shopify/ProductVariant/REPLACE_ME",
"image": ""
},
{
"key": "gift2",
"title": "Gift two",
"value": 0,
"skioVariantId": "",
"platformId": "gid://shopify/ProductVariant/REPLACE_ME",
"image": ""
},
{
"key": "gift3",
"title": "Gift three",
"value": 0,
"skioVariantId": "",
"platformId": "gid://shopify/ProductVariant/REPLACE_ME",
"image": ""
}
],
"campaignStart": "2026-12-01T00:00:00-08:00",
"campaignEnd": "2026-12-31T23:59:59-08:00",
"campaignTag": "2026",
"eligibleCreatedFrom": "",
"eligibleCreatedTo": "",
"sendAttributes": true,
"lockProperty": "_loyaltyFreeProduct",
"verifyAttempts": 4,
"verifyDelayMs": 400,
"bootMs": 8000,
"reloadAfterMs": 1500,
"debug": false,
"copy": {
"eyebrow": "Subscriber gift",
"teaserTitle": "A gift is waiting for you 🎁",
"teaserBody": "Thanks for sticking with us. Pick one free gift and we’ll pack it in your next order.",
"revealCta": "Reveal your gift",
"pickTitle": "Pick your free gift",
"claimCtaEmpty": "Pick a gift",
"claimCta": "Claim the {gift}",
"claiming": "Adding to your order…",
"shipsWith": "Ships free with your {date} order.",
"onlyOne": "You can pick one.",
"claimedEyebrow": "Gift claimed",
"justClaimed": "{gift} added to your next order",
"refreshing": "Updating your order…",
"claimedOn": "You claimed the {gift} 🎁",
"claimedShipped": "You claimed the {gift} 🎁",
"claimedFine": "One gift per subscriber. Enjoy!",
"error": "Something went wrong. Please try again."
}
};
// Claim our own instance: two copies on one page otherwise both bind to the first.
var block = null, all = document.querySelectorAll('[data-sb-gift]');
for (var n = 0; n < all.length; n++) if (!all[n].hasAttribute('data-sb-claimed')) { block = all[n]; break; }
if (!block) return;
block.setAttribute('data-sb-claimed', '1');
var root = block.querySelector('[data-g-root]');
function log() { if (CONFIG.debug) try { console.warn.apply(console, ['[gift-picker]'].concat([].slice.call(arguments))); } catch (e) {} }
// No error boundary in CPv3: on anything unexpected the block removes itself.
function die(reason, err) {
log('hidden:', reason, err || '');
try { block.setAttribute('data-g-state', 'gone:' + reason); block.parentNode && block.parentNode.removeChild(block); } catch (e) {}
}
function el(tag, cls, text) {
var e = document.createElement(tag);
if (cls) e.className = cls;
if (text != null) e.textContent = text; // never innerHTML with data
return e;
}
function clear() { while (root.firstChild) root.removeChild(root.firstChild); }
function safeImg(url) { return typeof url === 'string' && /^https:\/\//i.test(url) ? url : null; }
function fmtDate(iso) {
try { return new Date(iso).toLocaleDateString(undefined, { month: 'short', day: 'numeric' }); } catch (e) { return ''; }
}
function money(v) {
if (typeof v !== 'number' || !isFinite(v) || v <= 0) return null;
return '$' + (v % 1 ? v.toFixed(2) : String(v));
}
/* ---------------------------------------------------------- identity */
function waitFor(test, ms) {
return new Promise(function (resolve) {
var t0 = Date.now();
(function tick() {
var v; try { v = test(); } catch (e) {}
if (v) return resolve(v);
if (Date.now() - t0 > ms) return resolve(null);
setTimeout(tick, 150);
})();
});
}
function viewedId() {
var m = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i.exec(location.pathname + location.search + location.hash);
return m ? m[0].toLowerCase() : null;
}
/* ---------------------------------------------------------- Skio API
Everything runs as the logged-in customer through the portal's own
fetchSkioAPI, so Skio scopes every read and write to this customer.
No server, no API key.
The gift is $0 because the gift PRODUCTS are $0 in Shopify. The block never
sends a price. A line added without one bills at the variant's own price
(verified live, 2026-11-05), and Skio refuses a
price set from a customer login. */
function api(query, vars) {
return Promise.resolve()
.then(function () { return window.fetchSkioAPI(query, vars || {}); })
.then(function (res) { // resolves with {data, errors}; it does not throw
if (!res || res.errors || !res.data) {
var e = new Error((res && res.errors && res.errors[0] && (res.errors[0].extensions && res.errors[0].extensions.detail || res.errors[0].message)) || 'api');
e.gql = true; throw e;
}
return res.data;
});
}
// uuid!, never String!: a String! variable kills the whole query at validation.
var SUB_Q = 'query($id: uuid!) { Subscriptions(where: {id: {_eq: $id}}) { id status createdAt nextBillingDate } }';
var VARIANTS_Q = 'query($p: [String!]!) { ProductVariants(where: {platformId: {_in: $p}}) { id platformId } }';
// Row scoping limits this to the customer's own subscriptions. No `limit`: limit
// truncates BEFORE where-filters run.
var LINES_Q = 'query { Subscriptions { id SubscriptionLines(where: {removedAt: {_is_null: true}}) { ProductVariant { id } } } }';
// Only gift items come back, so a customer with many orders downloads almost nothing.
// (Filtering order items by productVariantId is allowed for the customer role: checked live 2026-11-05.)
var ORDERS_Q = 'query($since: timestamptz!, $ids: [uuid!]!) { Orders(where: {createdAt: {_gte: $since}}) { OrderLineItems(where: {productVariantId: {_in: $ids}}) { ProductVariant { id } } } }';
var ADD_M = 'mutation($i: AddSubscriptionLineInput!) { addSubscriptionLine(input: $i) { ok } }';
// Gift products exist only to be gifts, so the variant id alone marks a claim.
// No dependence on customAttributes being readable by the customer role.
function giftByVariant(id) {
for (var i = 0; i < S.gifts.length; i++) if (S.gifts[i].skioVariantId === id) return S.gifts[i];
return null;
}
function resolveVariants() {
var missing = S.gifts.filter(function (g) { return !g.skioVariantId; });
if (!missing.length) return Promise.resolve();
return api(VARIANTS_Q, { p: missing.map(function (g) { return g.platformId; }) }).then(function (d) {
(d.ProductVariants || []).forEach(function (v) {
S.gifts.forEach(function (g) { if (g.platformId === v.platformId) g.skioVariantId = v.id; });
});
// A gift we can't map is dropped rather than offered and then failing on claim.
S.gifts = S.gifts.filter(function (g) { return g.skioVariantId; });
});
}
/** The customer's existing claim: a gift already on an ORDER (shipped or about to),
else a gift still waiting on any of their subscriptions.
Orders win. After "Get now" (or any billing) the order holds the gift straight
away, but Skio takes ~25s to clear the one-time line from the subscription.
Seen live 2026-11-05: in that gap the line still looked "coming with your next
order" although it had already been billed. */
function findClaim() {
var since = CONFIG.campaignStart || '2000-01-01T00:00:00Z';
var ids = S.gifts.map(function (g) { return g.skioVariantId; });
var ordersP = api(ORDERS_Q, { since: since, ids: ids }).then(function (od) { return od.Orders || []; }, function (e) {
// Orders not readable by this role: we can only see unbilled gifts.
block.setAttribute('data-g-orders', 'unreadable');
log('orders unreadable', e && e.message);
return [];
});
return Promise.all([ordersP, api(LINES_Q)]).then(function (res) {
var orders = res[0], subs = res[1].Subscriptions || [];
for (var a = 0; a < orders.length; a++) {
var items = orders[a].OrderLineItems || [];
for (var b = 0; b < items.length; b++) {
var g2 = giftByVariant(items[b].ProductVariant && items[b].ProductVariant.id);
if (g2) return { key: g2.key, title: g2.title, where: 'order' };
}
}
for (var i = 0; i < subs.length; i++) {
var lines = subs[i].SubscriptionLines || [];
for (var j = 0; j < lines.length; j++) {
var g = giftByVariant(lines[j].ProductVariant && lines[j].ProductVariant.id);
if (g) return { key: g.key, title: g.title, where: 'subscription', subscriptionId: subs[i].id };
}
}
return null;
});
}
function inWindow() {
var now = Date.now(), s = Date.parse(CONFIG.campaignStart), e = Date.parse(CONFIG.campaignEnd);
return (!s || now >= s) && (!e || now <= e);
}
/* Who qualifies: subscriptions CREATED between these two moments (e.g. the BFCM
cohort). Judged on the subscription being viewed. Leave both blank for everyone.
A customer with an older and a newer subscription sees the block only on the
qualifying one, and still gets one gift in total. Note: migrated subscriptions
carry their migration date as createdAt. */
function createdQualifies(createdAt) {
var from = Date.parse(CONFIG.eligibleCreatedFrom), to = Date.parse(CONFIG.eligibleCreatedTo);
if (!from && !to) return true;
var c = Date.parse(createdAt);
if (!c) return false; // can't tell, so don't offer
return (!from || c >= from) && (!to || c <= to);
}
// Same shape the views expect: {state, gifts, claimed, nextBillingDate, reason}.
// One round of requests: the subscription read runs alongside the claim check
// (orders + lines). With skioVariantIds filled in, resolveVariants() makes no call.
function loadStatus() {
return Promise.all([
api(SUB_Q, { id: S.subId }),
resolveVariants().then(function () { return findClaim(); })
]).then(function (res) {
var sub = (res[0].Subscriptions || [])[0], claim = res[1];
if (!sub) return { state: 'ineligible', reason: 'not-found' };
if (claim) return { state: 'claimed', claimed: claim, gifts: S.gifts, nextBillingDate: sub.nextBillingDate };
if (String(sub.status).toUpperCase() !== 'ACTIVE') return { state: 'ineligible', reason: 'not-active' };
if (!createdQualifies(sub.createdAt)) return { state: 'ineligible', reason: 'created-outside-window' };
if (!inWindow()) return { state: 'ineligible', reason: 'outside-window' };
return { state: 'eligible', gifts: S.gifts, nextBillingDate: sub.nextBillingDate };
});
}
function sleep(ms) { return new Promise(function (r) { setTimeout(r, ms); }); }
function claimGift(giftKey) {
var gift = S.gifts.filter(function (g) { return g.key === giftKey; })[0];
if (!gift) return Promise.reject(new Error('unknown-gift'));
// Read before write: another tab or device may have claimed since the page loaded.
return findClaim().then(function (prior) {
if (prior) return { state: 'claimed', alreadyClaimed: true, claimed: prior };
var input = { subscriptionId: S.subId, variantId: gift.skioVariantId, quantity: 1, upsell: true };
if (CONFIG.sendAttributes) {
input.customAttributes = [{ key: '_holidayGift', value: CONFIG.campaignTag }];
if (CONFIG.lockProperty) input.customAttributes.push({ key: CONFIG.lockProperty, value: 'true' });
}
return api(ADD_M, { i: input }).then(function (d) {
if (!d.addSubscriptionLine || !d.addSubscriptionLine.ok) throw new Error('add-refused');
// `ok` is never believed: the line has to be there on a fresh read.
var tries = 0;
return (function verify() {
return findClaim().then(function (c) {
if (c && c.where === 'subscription') return { state: 'claimed', claimed: c };
if (++tries >= CONFIG.verifyAttempts) throw new Error('not-visible-after-add');
return sleep(CONFIG.verifyDelayMs * tries).then(verify);
});
})();
});
});
}
/* ---------------------------------------------------------- views */
var S = { subId: null, gifts: [], next: null, pick: null, busy: false };
function imgBox(gift, big) {
var box = el('div', 'sb-gift__img');
var src = safeImg(gift && gift.image);
if (src) { var im = el('img'); im.src = src; im.alt = ''; box.appendChild(im); }
else box.appendChild(el('span', 'sb-gift__ph', '🎁')); // has content, so div:empty can't eat it
return box;
}
function viewTeaser() {
clear();
root.appendChild(el('span', 'sb-gift__eyebrow', CONFIG.copy.eyebrow));
root.appendChild(el('div', 'sb-gift__h', CONFIG.copy.teaserTitle));
root.appendChild(el('div', 'sb-gift__p', CONFIG.copy.teaserBody));
var b = el('button', 'sb-gift__cta', CONFIG.copy.revealCta);
b.type = 'button';
b.addEventListener('click', viewPick);
root.appendChild(b);
// Warm the browser cache so the gift images are already there on Reveal.
S.gifts.forEach(function (g) {
var src = safeImg(g.image);
if (src) { try { var im = new Image(); im.src = src; } catch (e) {} }
});
}
function viewPick() {
clear();
root.appendChild(el('span', 'sb-gift__eyebrow', CONFIG.copy.eyebrow));
root.appendChild(el('div', 'sb-gift__h', CONFIG.copy.pickTitle));
var grid = el('div', 'sb-gift__grid');
grid.setAttribute('role', 'radiogroup');
grid.setAttribute('aria-label', CONFIG.copy.pickTitle);
var cta = el('button', 'sb-gift__cta', CONFIG.copy.claimCtaEmpty);
cta.type = 'button'; cta.disabled = true;
S.gifts.forEach(function (g) {
var o = el('button', 'sb-gift__opt');
o.type = 'button';
o.setAttribute('role', 'radio');
o.setAttribute('aria-checked', 'false');
o.setAttribute('data-key', g.key);
o.appendChild(imgBox(g));
var txt = el('div'); txt.style.setProperty('display', 'flex', 'important');
txt.style.setProperty('flex-direction', 'column', 'important'); txt.style.setProperty('gap', '4px', 'important');
txt.appendChild(el('span', 'sb-gift__t', g.title));
var worth = money(g.value);
txt.appendChild(el('span', 'sb-gift__v', worth ? 'Free · worth ' + worth : 'Free'));
o.appendChild(txt);
o.addEventListener('click', function () {
if (S.busy) return;
S.pick = g.key;
[].forEach.call(grid.children, function (c) {
var on = c.getAttribute('data-key') === g.key;
c.setAttribute('aria-checked', on ? 'true' : 'false');
var t = c.querySelector('.sb-gift__tick'); if (t) c.removeChild(t);
if (on) c.appendChild(el('span', 'sb-gift__tick', '✓'));
});
cta.disabled = false;
cta.textContent = CONFIG.copy.claimCta.replace('{gift}', g.title);
});
grid.appendChild(o);
});
root.appendChild(grid);
requestAnimationFrame(function () { grid.classList.add('is-in'); });
var fine = el('div', 'sb-gift__fine',
(S.next ? CONFIG.copy.shipsWith.replace('{date}', fmtDate(S.next)) + ' ' : '') + CONFIG.copy.onlyOne);
root.appendChild(fine);
var err = el('div', 'sb-gift__err'); err.hidden = true; err.setAttribute('role', 'alert');
root.appendChild(err);
cta.addEventListener('click', function () { claim(cta, err, grid); });
root.appendChild(cta);
}
function claim(cta, err, grid) {
if (S.busy || !S.pick) return;
S.busy = true; err.hidden = true;
cta.disabled = true; cta.setAttribute('aria-busy', 'true'); cta.textContent = CONFIG.copy.claiming;
[].forEach.call(grid.children, function (c) { c.disabled = true; });
claimGift(S.pick).then(function (res) {
if (res && res.state === 'claimed' && res.claimed) {
viewJustClaimed(res.claimed, res.nextBillingDate || S.next);
if (CONFIG.reloadAfterMs > 0) setTimeout(function () { try { location.reload(); } catch (e) {} }, CONFIG.reloadAfterMs);
return;
}
throw new Error((res && res.reason) || 'claim-failed');
}).catch(function (e) {
log('claim failed', e && e.message);
S.busy = false;
err.textContent = CONFIG.copy.error; err.hidden = false;
[].forEach.call(grid.children, function (c) { c.disabled = false; });
cta.disabled = false; cta.removeAttribute('aria-busy');
var g = S.gifts.filter(function (x) { return x.key === S.pick; })[0];
cta.textContent = CONFIG.copy.claimCta.replace('{gift}', g ? g.title : 'gift');
});
}
function viewJustClaimed(claimed, next) {
clear();
var gift = S.gifts.filter(function (x) { return x.key === claimed.key; })[0] || claimed;
var stamp = el('span', 'sb-gift__eyebrow sb-gift__stamp', CONFIG.copy.claimedEyebrow);
root.appendChild(stamp);
var won = el('div', 'sb-gift__won');
won.appendChild(imgBox(gift));
var txt = el('div'); txt.style.setProperty('display', 'flex', 'important');
txt.style.setProperty('flex-direction', 'column', 'important'); txt.style.setProperty('gap', '6px', 'important');
txt.appendChild(el('div', 'sb-gift__h', CONFIG.copy.justClaimed.replace('{gift}', gift.title || claimed.title)));
txt.appendChild(el('div', 'sb-gift__fine', CONFIG.copy.refreshing));
won.appendChild(txt);
root.appendChild(won);
}
function viewClaimed(claimed, next) {
clear();
var gift = S.gifts.filter(function (x) { return x.key === claimed.key; })[0] || claimed;
root.appendChild(el('span', 'sb-gift__eyebrow', CONFIG.copy.claimedEyebrow));
var won = el('div', 'sb-gift__won');
won.appendChild(imgBox(gift));
var txt = el('div'); txt.style.setProperty('display', 'flex', 'important');
txt.style.setProperty('flex-direction', 'column', 'important'); txt.style.setProperty('gap', '6px', 'important');
var where = claimed.where === 'order' ? CONFIG.copy.claimedShipped : CONFIG.copy.claimedOn;
txt.appendChild(el('div', 'sb-gift__h', where.replace('{gift}', gift.title || claimed.title).replace('{date}', next ? fmtDate(next) : 'your next')));
txt.appendChild(el('div', 'sb-gift__fine', CONFIG.copy.claimedFine));
won.appendChild(txt);
root.appendChild(won);
var others = S.gifts.filter(function (x) { return x.key !== claimed.key; });
if (others.length) {
var rest = el('div', 'sb-gift__rest');
others.forEach(function (o) {
var w = el('span', 'sb-gift__dim'); w.style.setProperty('display', 'flex', 'important');
w.style.setProperty('gap', '6px', 'important'); w.style.setProperty('align-items', 'center', 'important');
w.appendChild(imgBox(o)); w.appendChild(el('span', 'sb-gift__fine', o.title));
rest.appendChild(w);
});
root.appendChild(rest);
}
}
function show() {
block.hidden = false;
requestAnimationFrame(function () { block.classList.add('is-in'); });
}
/* ---------------------------------------------------------- boot */
waitFor(function () { return typeof window.fetchSkioAPI === 'function'; }, CONFIG.bootMs)
.then(function (ready) {
if (!ready) return die('no-api');
S.subId = viewedId();
if (!S.subId) return die('no-subscription-in-url');
// Copy so resolveVariants() never mutates CONFIG between instances.
S.gifts = CONFIG.gifts.map(function (g) { var o = {}; for (var k in g) o[k] = g[k]; return o; });
return loadStatus().then(function (res) {
S.next = res && res.nextBillingDate;
if (res && res.state === 'eligible' && S.gifts.length) { viewTeaser(); show(); return; }
if (res && res.state === 'claimed' && res.claimed) { viewClaimed(res.claimed, S.next); show(); return; }
die((res && (res.reason || res.state)) || 'no-status');
});
})
.catch(function (e) { die('boot-error', e && e.message); });
})();
</script>
How to install
- Copy the code above, or download the .html file.
- Go to
Storefront→Customization→Blocks, then clickAdd block→Custom block. - Name it and paste the whole file into the code editor.
- Swap anything the file asks you to, like
[BRAND], product names or Quick Action IDs. The AI prompt below can walk you through it. - Save, drag it where you want it in the layout, then
Publish. Check it on a test subscription’s magic link with?forcePreview=true, since some scripts don’t run in Preview.
It ships unconfigured: the three gifts in SETTINGS are placeholders (platformId REPLACE_ME), so the card stays hidden until you add your own. In Shopify, create a gift-only product for each gift, priced at $0 and kept off the Online Store; the block never sends a price, so a gift bills at its variant's own price. For each gift, set its Shopify variant ID (platformId), title, image URL (https only) and an optional value, shown as “worth $X” (leave it at 0 for non-dollar or multi-currency stores). Set campaignStart and campaignEnd (the sample is 1–31 Dec 2026) and, optionally, eligibleCreatedFrom and eligibleCreatedTo to limit it to subscriptions created between two dates. Write dates with a time zone offset, e.g. 2026-12-31T23:59:59-08:00. Dates are checked against the customer's device clock, and migrated subscriptions carry their migration date. The gift line carries two properties: _holidayGift (set by campaignTag, sample “2026”) and _loyaltyFreeProduct: true (lockProperty), which keeps the gift as a reward the subscriber can't change. Rename them if they clash with an app you use, or set sendAttributes to false. Known limits: the one-gift rule runs in the browser, so a customer using developer tools could add a second gift (a Shopify Flow that holds orders with more than one gift item catches it). Right after “Get now”, Skio takes about 25 seconds to clear the one-time line, so ordering again in that gap ships the gift on another order too. Test on a live subscription page; the admin preview doesn't run block code. It uses Skio's portal API (fetchSkioAPI), so it needs a Skio customer portal.
Customize it with AI
Paste this prompt into Claude Code or Codex. It asks for the code and your brand and product details, then writes a version for your store.
I want to add a custom extension from customizeyourportal.xyz to my subscription customer portal. Walk me through customizing it for my brand, then write the finished code. EXTENSION Name: Gift Picker (No. 20) Page: /blocks/gift-picker What it does: A “A gift is waiting for you” card in the customer portal. The subscriber reveals the gift options, picks one, and it's added to their next order at $0 as a one-time item. Once they've claimed it, the card says “You claimed the [gift]” and the other options lock across all their subscriptions and past orders. It only shows on active subscriptions during the campaign dates, can be limited to subscriptions created between two dates, and hides itself if anything fails. My portal app: Skio WHAT THE BUILDER SAYS TO CUSTOMIZE It ships unconfigured: the three gifts in SETTINGS are placeholders (platformId REPLACE_ME), so the card stays hidden until you add your own. In Shopify, create a gift-only product for each gift, priced at $0 and kept off the Online Store; the block never sends a price, so a gift bills at its variant's own price. For each gift, set its Shopify variant ID (platformId), title, image URL (https only) and an optional value, shown as “worth $X” (leave it at 0 for non-dollar or multi-currency stores). Set campaignStart and campaignEnd (the sample is 1–31 Dec 2026) and, optionally, eligibleCreatedFrom and eligibleCreatedTo to limit it to subscriptions created between two dates. Write dates with a time zone offset, e.g. 2026-12-31T23:59:59-08:00. Dates are checked against the customer's device clock, and migrated subscriptions carry their migration date. The gift line carries two properties: _holidayGift (set by campaignTag, sample “2026”) and _loyaltyFreeProduct: true (lockProperty), which keeps the gift as a reward the subscriber can't change. Rename them if they clash with an app you use, or set sendAttributes to false. Known limits: the one-gift rule runs in the browser, so a customer using developer tools could add a second gift (a Shopify Flow that holds orders with more than one gift item catches it). Right after “Get now”, Skio takes about 25 seconds to clear the one-time line, so ordering again in that gap ships the gift on another order too. Test on a live subscription page; the admin preview doesn't run block code. It uses Skio's portal API (fetchSkioAPI), so it needs a Skio customer portal. HOW TO WORK 1. Ask me to paste the full code (the "Copy code" button on the page) or to give you the path to the downloaded gift-picker.html. Wait until you have it. 2. Read the whole file. List every value that is specific to the original brand or needs my input: brand name and [PLACEHOLDERS], product and variant names or IDs, prices, discount codes and reward amounts, Quick Action IDs or tokens, store domains and API endpoints, colors, fonts, logos and images, and any copy that names the original brand, products or offers. Include everything in the builder's notes above. 3. Ask me for those values in one numbered list, with the current value next to each, so I can answer or say "keep". If you can open web pages, offer to pull my brand colors, fonts, logo and product names from my store's URL. 4. Don't invent stats, reviews, IDs, prices or claims. If I don't have a value, leave a clearly marked TODO in the code and tell me. 5. Write the customized version as gift-picker-<my-brand>.html. Change only what my brand needs. Keep the logic, behavior and structure the same, and keep it one self-contained file (HTML, <style> and <script>). 6. Finish with a short list of what you changed, any TODOs left, and these install steps for Skio: 1. Go to `Storefront` → `Customization` → `Blocks`, then click `Add block` → `Custom block`. 2. Name it and paste the whole file into the code editor. 3. Save, drag it where you want it in the layout, then `Publish`. Check it on a test subscription’s magic link with `?forcePreview=true`, since some scripts don’t run in Preview.
Blocks are shared as-is by the people who built them. Read the code before you add it to your portal, and test it with a test subscriber first.
