DocsStorefront integrationConnect a countdown timer

Coming soon Kwik's public API and MCP server are coming soon. These docs are an early preview, in the beginning stages: endpoints, fields and examples are samples and will change before launch. Brands on Kwik today can ask their account manager about integrations.

Read every docs page as one Markdown file, ready to paste into ChatGPT, Claude or any AI assistant.

Storefront integration · Guide 3 of 4

Connect A Countdown Timer To Kwik.

Power your own announcement bar, product page timer or cart countdown with the giveaway schedule Kwik syncs to the store.

Before you start

  • The Kwik 2.0 Shopify app installed. It writes the giveaway schedule to shop metafields (Kwik 1 stores don't have this data).
  • A giveaway with its weeks (earning periods) set up in Kwik: dates, timer text, and banner images if you use them.
  • Read the giveaway data reference for the full field list.

Try the native blocks first

On Liquid themes, the Kwik 2.0 app has two app blocks that already do this. Add them from the App blocks page in the Kwik 2.0 app, then style them in the theme editor. Both switch weeks on their own at the exact boundary.

BlockWhat it does
Giveaway CountdownTimer text plus days, hours, minutes and seconds to the end of the week, with an optional progress bar. Colors, sizes, labels and layout are adjustable.
Giveaway BannerThe running week's desktop and mobile image, with an optional link, alt text and a fallback image for days between weeks.

Build your own only when the design needs it: a timer inside an existing announcement bar, in the cart, or combined with entry badges. The rest of this page shows how.

The data source

Kwik syncs the schedule to the shop metafield giveaway_weeks, in the namespace app--330349150209. When week settings are saved in Kwik, the store gets them in about a minute. It holds the running week and the upcoming weeks. Ended weeks drop off.

In the example, a shopper is browsing on Thursday afternoon. The 50× offer ends tonight at midnight, Mountain time. The giveaway keeps going at 25× through Sunday.

JSON · giveaway_weeks
{
  "version": 1,
  "weeks": [
    {
      "geId": 11,
      "geName": "Truck Giveaway",
      "weekId": 204,
      "startsAt": "2026-11-30T07:00:00Z",
      "endsAt": "2026-12-04T07:00:00Z",
      "startTs": 1796022000,
      "endTs": 1796367600,
      "timeZone": "America/Denver",
      "timerText": "50X Ends Tonight",
      "desktopImage": { "url": "https://cdn.example.com/50x-desktop.jpg", "width": 2400, "height": 800 },
      "mobileImage": { "url": "https://cdn.example.com/50x-mobile.jpg", "width": 1080, "height": 1350 }
    },
    {
      "geId": 11,
      "geName": "Truck Giveaway",
      "weekId": 205,
      "startsAt": "2026-12-04T07:00:00Z",
      "endsAt": "2026-12-07T07:00:00Z",
      "startTs": 1796367600,
      "endTs": 1796626800,
      "timeZone": "America/Denver",
      "timerText": "25X Through Sunday",
      "desktopImage": null,
      "mobileImage": null
    }
  ]
}

Two questions, two timers

Shopper asksPickCount down toIn the example
"When does the current 50× offer end?"The running week: startTs <= now < endTs, for your giveaway's geIdThat week's endTsTonight, 12:00 AM Friday
"When does the giveaway end?"Every week for your geIdThe latest endTs among themEnd of Sunday

Label the offer timer with the week's timerText. Pick the giveaway with its geId when more than one runs at once. If you don't pick one, use the first running giveaway.

Needs confirmationA rate change that ends partway through a week only gets its own timer when it is set up as its own week in Kwik, as in the example. The storefront data has no separate end time for a single multiplier yet, and the API preview's dated multipliers are not live. Until Kwik confirms one, count down to the week's endTs. The giveaway's end is only as complete as the weeks Kwik has scheduled so far.

Time zones

  • Count down with startTs and endTs. They are Unix seconds, the same moment everywhere, so a countdown needs no time zone math. startsAt and endsAt are the same moments as ISO dates in UTC.
  • Show dates in the week's timeZone (for example America/Denver) with Intl.DateTimeFormat, not the shopper's time zone. Liquid's date filter uses the store's time zone, which may be different.
  • Weeks end at midnight. A week that ends Monday 12:00 AM should read "through Sunday", so format endTs - 1 when you show the last day.

1. Get the data onto the page

On a Liquid theme, print the metafields as JSON from a small section, and paint the bar in Liquid so it never flashes empty. Custom code must use the full namespace. $app only works inside Kwik's own app blocks.

Liquid · sections/kwik-data.liquid
{%- comment -%} sections/kwik-data.liquid: prints Kwik's giveaway data as JSON for your scripts.
Render it once in layout/theme.liquid with {% section 'kwik-data' %}. The same file also answers
/?sections=kwik-data, which is how the page gets fresh data after a timer hits zero. {%- endcomment -%}
{%- assign kwik = shop.metafields['app--330349150209'] -%}
<script type="application/json" id="kwik-data">
  {
    "weeks": {{ kwik.giveaway_weeks.value | json }},
    "entries": {{ kwik.giveaway_entries.value | json }},
    "wavelinkRequired": {{ kwik.wavelink_required.value | json }},
    "serverTs": {{ 'now' | date: '%s' }}
  }
</script>
Liquid · announcement bar
{%- comment -%} Announcement bar first paint, so there is no empty flash before JavaScript runs.
The page may be cached, so the script below re-checks the running week on load. {%- endcomment -%}
{%- assign weeks = shop.metafields['app--330349150209'].giveaway_weeks.value.weeks -%}
{%- assign now_ts = 'now' | date: '%s' | plus: 0 -%}
{%- assign running = nil -%}
{%- for week in weeks -%}
  {%- if week.startTs <= now_ts and week.endTs > now_ts -%}{%- assign running = week -%}{%- break -%}{%- endif -%}
{%- endfor -%}
<div class="kwik-bar" data-kwik-bar {% unless running %}hidden{% endunless %}>
  <strong data-kwik-label>{{ running.timerText }}</strong>
  <span data-kwik-offer-timer></span>
  <span data-kwik-giveaway-end></span>
</div>

On Hydrogen, app blocks and app embeds don't run, so read the same metafields through the Storefront API in your own route:

TypeScript · app/routes/api.kwik-promo.tsx
// app/routes/api.kwik-promo.tsx: Kwik's giveaway data for a Hydrogen storefront.
// Needs confirmation: these metafields come back as null unless Kwik's metafield
// definitions allow Storefront API access on your store. Check with Kwik first.
import {data, type LoaderFunctionArgs} from 'react-router';

const QUERY = `#graphql
  query KwikPromo {
    shop {
      weeks: metafield(namespace: "app--330349150209", key: "giveaway_weeks") { value }
      entries: metafield(namespace: "app--330349150209", key: "giveaway_entries") { value }
      wavelinkRequired: metafield(namespace: "app--330349150209", key: "wavelink_required") { value }
    }
  }`;

export async function loader({context}: LoaderFunctionArgs) {
  const {shop} = await context.storefront.query(QUERY, {cache: context.storefront.CacheShort()});
  const parse = (m: {value: string} | null, fallback: unknown) => (m?.value ? JSON.parse(m.value) : fallback);
  return data({
    weeks: parse(shop.weeks, {weeks: []}),
    entries: parse(shop.entries, []),
    wavelinkRequired: parse(shop.wavelinkRequired, false),
  });
}

// In the browser:
// const promo = createPromo({ read: () => window.__KWIK__, reload: () => fetch('/api/kwik-promo').then((r) => r.json()) });

Not on Shopify? The schedule isn't synced to your site for you. Load the same fields from your own server (from the API preview's GET /giveaways/{giveaway_id}/weeks once it is live, or from data your Kwik contact sets up) and pass them to the shared clock below. The clock only needs read and reload functions, so the rest of this page works on any site.

2. One shared clock

Use one clock for the whole page. The announcement bar, product badges and cart estimate all read the same state, so they always agree. Each second it re-checks the running week. When a week starts or ends, it reloads the data and tells every display.

JavaScript · kwik-promo.js
// kwik-promo.js: one shared clock for the announcement bar, product badges and cart estimate.
// Works on Liquid themes and Hydrogen. You pass in how to read and re-load the data.
export function createPromo({read, reload, geId = null}) {
  let data = read();                     // {weeks: {...} | [...], entries: [...], wavelinkRequired}
  let state = compute();
  let updating = false;
  const listeners = new Set();

  function now() { return Math.floor(Date.now() / 1000); }
  function weeksOf(d) {
    const list = Array.isArray(d?.weeks) ? d.weeks : d?.weeks?.weeks ?? [];
    return list.filter((w) => geId == null || String(w.geId) === String(geId));
  }

  function compute() {
    const t = now();
    const weeks = weeksOf(data);
    const week = weeks.filter((w) => w.startTs <= t && t < w.endTs).sort((a, b) => a.endTs - b.endTs)[0] ?? null;
    const next = weeks.filter((w) => w.startTs > t).sort((a, b) => a.startTs - b.startTs)[0] ?? null;
    const giveawayEndTs = weeks.length ? Math.max(...weeks.map((w) => w.endTs)) : null;
    const id = week?.geId ?? geId;
    // No running week means no earning rate. Kwik awards nothing between weeks, so neither do we.
    const rate = week ? (data?.entries ?? []).find((e) => id == null || String(e.geId) === String(id)) ?? null : null;
    return {week, next, giveawayEndTs, rate, updating};
  }

  function emit() { state = compute(); listeners.forEach((fn) => fn(state)); }

  async function refresh() {
    updating = true; emit();                       // badges and cart hide numbers while this is true
    try { data = await reload(); } catch {}
    updating = false; emit();
  }

  setInterval(() => {
    const before = state.week?.weekId ?? null;
    const after = compute().week?.weekId ?? null;
    if (before !== after) {
      refresh();                                    // a week ended or started: get the new rate
      setTimeout(refresh, 60_000);                  // and once more, in case the store data lagged
    } else {
      emit();                                       // just tick the countdowns
    }
  }, 1000);

  return {
    get state() { return state; },
    subscribe(fn) { listeners.add(fn); fn(state); return () => listeners.delete(fn); },
    refresh,
  };
}

// Helpers for labels
export function countdown(endTs) {
  const s = Math.max(0, endTs - Math.floor(Date.now() / 1000));
  return {d: Math.floor(s / 86400), h: Math.floor((s % 86400) / 3600), m: Math.floor((s % 3600) / 60), s: s % 60};
}
export function dayName(ts, timeZone) {
  // Show dates in the giveaway's own time zone, not the shopper's.
  return new Intl.DateTimeFormat('en-US', {weekday: 'long', timeZone}).format(new Date(ts * 1000));
}
export function lastDay(endTs, timeZone) {
  // Weeks end at midnight. Subtract a second so "ends Monday 12:00 AM" reads "through Sunday".
  return dayName(endTs - 1, timeZone);
}
Liquid theme · wire up the bar
<script type="module">
  import {createPromo, countdown, dayName, lastDay} from '{{ "kwik-promo.js" | asset_url }}';

  const parse = (html) => {
    const el = new DOMParser().parseFromString(html, 'text/html').getElementById('kwik-data');
    return JSON.parse(el.textContent);
  };
  const promo = createPromo({
    read: () => JSON.parse(document.getElementById('kwik-data').textContent),
    // Section Rendering API: fresh metafields without reloading the page.
    reload: () => fetch(`/?sections=kwik-data&t=${Date.now()}`).then((r) => r.json()).then((j) => parse(j['kwik-data'])),
  });
  window.kwikPromo = promo;            // product badges and the cart estimate subscribe to the same clock

  const bar = document.querySelector('[data-kwik-bar]');
  promo.subscribe(({week, next, giveawayEndTs}) => {
    if (!week) {                        // a gap between offers
      bar.hidden = !next;
      if (next) bar.querySelector('[data-kwik-label]').textContent = `${next.timerText} starts ${dayName(next.startTs, next.timeZone)}`;
      bar.querySelector('[data-kwik-offer-timer]').textContent = '';
      return;
    }
    const t = countdown(week.endTs);
    bar.hidden = false;
    bar.querySelector('[data-kwik-label]').textContent = week.timerText;
    bar.querySelector('[data-kwik-offer-timer]').textContent = `Offer ends in ${t.d ? t.d + 'd ' : ''}${t.h}h ${t.m}m ${t.s}s`;
    bar.querySelector('[data-kwik-giveaway-end]').textContent =
      giveawayEndTs > week.endTs ? `Giveaway runs through ${lastDay(giveawayEndTs, week.timeZone)}` : '';
  });
</script>

When the timer hits zero

  1. Re-pick the running week. In the example, the 50× week ends and the 25× week starts at the same moment. The label changes to "25X Through Sunday" and the timer counts to the new endTs. Never sit at 00:00:00.
  2. Reload the rate. The rate and multipliers in giveaway_entries belong to the week that was running when the page loaded. Fetch fresh data (the Section Rendering API on Liquid, your own route on Hydrogen) and hide entry numbers until it arrives.
  3. Check again a minute later, in case the store data lagged behind the switch.

A gap between promotions: if no week is running, Kwik awards no entries. Hide entry badges and estimates. Show "25X starts Friday" from the next week's startTs instead, or hide the bar.

A page left open across the switch: the shared clock handles it. The page doesn't need a reload, and every display updates in the same second.

Needs confirmationHow soon giveaway_entries shows the new week's rate after a week boundary. The sample reloads at the switch and again 60 seconds later. If your store lags longer, ask Kwik.

End-to-end test

  1. On a test store, set up two back-to-back weeks in Kwik. The first ends in 3 minutes, with different timer text and rates.
  2. Wait a minute, then load the page. The bar shows the first week's text, the offer timer counts to its end, and the giveaway line shows the second week's last day.
  3. Leave the page open. At zero, the label and timer switch to the second week without a reload, and entry numbers hide briefly, then return at the new rate.
  4. Set up a gap (the second week starts an hour later). At zero, badges hide and the bar shows when the next offer starts.
  5. Compare a displayed date with the Kwik admin, in the giveaway's time zone.