Integrations

Web push for any HTML site, React, Next.js or static host

If you control your files, setup is one script tag and one file in the folder your host serves as the site root.

If you deploy your own files, setup is two things: put superwicket-sw.js where your host serves the site root, and load the script on every page.

Setup

  1. Add the service worker file to the folder that maps to your domain root:
    StackFolder
    Plain HTML, PHP, JekyllThe site root, next to index.html
    Next.js, Vite, React (CRA), Vue, Nuxt 3, Astro, Remixpublic/
    SvelteKit, Gatsby, Hugostatic/
    Angularpublic/ (v17+) or listed in assets in angular.json
    Railspublic/
    Laravelpublic/
    DjangoServe it from a view or web server rule at /superwicket-sw.js
    The file is one line: importScripts('https://superwicket.com/p/sw/YOUR_PIXEL_KEY.js');
  2. Load the script on every page, in your base template or layout:
    <script async src="https://superwicket.com/p/YOUR_PIXEL_KEY.js"></script>
    In Next.js (App Router), put it in app/layout.tsx:
    import Script from 'next/script';
    
    export default function RootLayout({ children }) {
      return (
        <html lang="en">
          <body>
            {children}
            <Script src="https://superwicket.com/p/YOUR_PIXEL_KEY.js" strategy="afterInteractive" />
          </body>
        </html>
      );
    }
  3. Deploy and check that https://your-site.com/superwicket-sw.js returns the JavaScript line with a JavaScript content type. Netlify, Vercel, Cloudflare Pages and GitHub Pages do this by default for .js files.
  4. Send events from your app to trigger flows or segment subscribers:
    // after the script has loaded
    window.superwicket.track('report_exported', { rows: 1200 });
    window.superwicket.setParams({ plan: 'trial', account_id: 'acct_42' });
    If you need to call it before the script loads, push calls onto a queue: (window.superwicket = window.superwicket || []).push(['track', 'signup']);

Single-page apps

Load the script once in the app shell. It records page views on client-side route changes too (it listens to history.pushState and popstate), so page-view triggers and segments work in React, Vue and Svelte apps without extra code.

If you already have a service worker

A page can have only one service worker per scope. If you use Workbox, next-pwa or your own worker for offline caching, don’t add a second file. Add the importScripts line to your existing worker and set SuperWicket’s service worker path to that file in the website settings.

Your own subscribe button

Instead of a widget, give any element the data-superwicket-subscribe attribute, or call window.superwicket.subscribe() from your own click handler. The browser permission prompt must follow a click, so don’t call it on page load.

From your backend

On Pro and above, the REST API sends a notification to one subscriber (looked up by a custom field such as your user ID), records server-side events, and manages campaigns and segments. See web push for SaaS.

Frequently asked questions

Where does the service worker go in Next.js?

In the public/ folder. Next.js serves public/superwicket-sw.js at /superwicket-sw.js.

Will it clash with my existing service worker?

A page can have only one service worker per scope. If you already have one (for a PWA or offline caching), add the importScripts line to it and set SuperWicket to use that path.

Try it on your own site

The Free plan has no time limit and needs no card. Add one script tag, or share a hosted subscribe page if you can’t upload files.