@zapiack/web

中文文档
0.1.0发布于 2026/11/03MITTypeScriptESM + CJS零依赖

Push notifications for websites with Zapiack: registration, clicks and what happens after a tap.

原始使用文档
文档目录7 节
  1. Set up
  2. Link a browser to your user
  3. Know when a notification was tapped
  4. See what happens after a tap
  5. Other
  6. Good to know
  7. License

@zapiack/web

Push notifications for websites with Zapiack. Registers the browser, shows pushes, reports taps, and follows what the visitor does next, so you can see which pushes bring people back and what they do when they arrive.

npm install @zapiack/web

Or with a script tag:

<script src="https://cdn.jsdelivr.net/npm/@zapiack/web/dist/zapiack.global.js"></script>
<script>Zapiack.Push.init({ appKey: 'pk_...' });</script>

Set up

1. Host the service worker at the root of your site, so it can control every page. Copy node_modules/@zapiack/web/dist/zapiack-sw.js to /zapiack-sw.js, or serve it from there.

2. Set up push for your project in the dashboard (Push, then Set up push) with the web platform turned on, and enter your site's address. You get a public key that starts with pk_. It is safe to put in your page.

3. Start it on every page:

import { ZapiackPush } from '@zapiack/web';

await ZapiackPush.init({ appKey: 'pk_...' });

4. Ask for permission from a click, not on page load:

button.addEventListener('click', async () => {
  const answer = await ZapiackPush.requestPermission(); // 'granted' | 'denied' | 'default'
});

When the visitor agrees, the browser is subscribed and registered. After that it registers itself again on every page load.

await ZapiackPush.login('user_123');   // the id your server uses for them
await ZapiackPush.logout();            // on sign-out

await ZapiackPush.addTags({ plan: 'pro' });
await ZapiackPush.removeTags(['plan']);

Then your server can send to { externalUserIds: ['user_123'] } or { tags: { plan: 'pro' } }.

Know when a notification was tapped

ZapiackPush.onClick((click) => {
  // click.link, click.event, click.actionId (the button, if one was tapped)
});

The link opens by itself. This is for your own routing or for showing something in the page. If the tap opened a new page, the handler still runs once the page has loaded.

See what happens after a tap

A push can ask to follow the visitor for a while after they tap it. While that window is open:

await ZapiackPush.track('purchase_completed', { orderId: 'ord_789' });

reports the event, credited to the push, and when your server named it as the push's goal it counts as a conversion. If the push asked for screens, page changes are reported too, with no code from you. track does nothing, and returns false, when the visitor did not arrive from a push or the window has passed.

Other

ZapiackPush.isSupported();      // false in browsers that cannot receive web push
ZapiackPush.permission();       // 'granted' | 'denied' | 'default'
await ZapiackPush.installationId();
await ZapiackPush.unsubscribe();

init options: serviceWorkerPath (default /zapiack-sw.js), serviceWorkerScope, autoRegister (default true), appVersion.

Good to know

  • Events are kept on the device and sent when the network allows, so a closed tab or a stopped service worker loses nothing.
  • Only web pages open from a notification: anything else in a link is ignored.
  • Pictures set on a push are shown where the browser supports them; buttons only where it shows them (Chrome and Edge do).
  • Web push needs a secure page (https, or localhost while you build).

License

MIT

版本与发布记录

@zapiack/web 共发布 2 个版本,首次发布于 2026/11/03;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.1.0latest2026/11/03今天
0.0.0-stage2026/11/03今天

关于 @zapiack/web 的常见问题

@zapiack/web 是什么?

使用Zapiack的网站推送通知:注册、点击和点击后发生的事情。

如何安装 @zapiack/web?

在项目目录运行 npm install @zapiack/web,或使用 pnpm add / yarn add / bun add。

@zapiack/web 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@zapiack/web 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@zapiack/web 可以商用吗?

@zapiack/web 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@zapiack/web 还在维护吗?

最新版本 0.1.0 发布于 2026/11/03(今天);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/11/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。