@builtonveya/analytics-web

中文文档
4.0.4发布于 2026/09/30UNLICENSEDTypeScriptESM + CJS零依赖近 30 天下载 3039

Veya Analytics SDK for the web - auto-detecting page, product and cart tracking for restaurant ordering sites

原始使用文档
文档目录10 节
  1. Install
  2. Configure
  3. Track
  4. Automatic events
  5. Changes in 4.0.4
  6. Changes in 4.0.3
  7. Changes in 4.0.2
  8. Changes in 4.0.1
  9. Server-side rendering
  10. Build & publish

@builtonveya/analytics-web

Veya Analytics SDK for the web. Auto-detects page types, product impressions and cart changes on restaurant ordering sites, and ships events to the Veya analytics pipeline in batches.

Shares its core with @builtonveya/analytics-react-native (same event taxonomy, same version line).

Install

npm / yarn / pnpm

npm install @builtonveya/analytics-web
import veya from '@builtonveya/analytics-web';

await veya.init({ tenantSlug: 'your-tenant-slug' });

Script tag (the package ships a self-contained browser bundle that sets window.veya)

<script src="https://cdn.jsdelivr.net/npm/@builtonveya/analytics-web@4/dist/veya-analytics.min.js"></script>
<script>
  veya.init({ tenantSlug: 'your-tenant-slug' });
</script>

Pin the major (@4) for automatic patch updates, or an exact version (@4.0.0) for a frozen build.

Configure

await veya.init({
  tenantSlug: 'your-tenant-slug',      // required
  endpoint: 'https://analytics.builtonveya.com/v1/events',   // the default
  storeId: 'store-81',                 // if known at init; otherwise call veya.setStore(id, name)
  debug: false,
  autoDetect: true,                    // page-type detection on navigation
  autoTrackProducts: true,             // product impressions
  autoTrackCart: true,                 // cart change detection
  interceptOloApi: false,              // opt-in: patches window.fetch to read Olo order responses
  batchSize: 10,
  flushInterval: 5000,
  sessionTimeout: 1800000,             // 30 minutes
});

Track

Everything the core SDK offers is on the default export: track, pageView, productView, productClick, addToCart, removeFromCart, updateCartQuantity, setCart, checkoutStart, checkoutStep, addPaymentInfo, checkoutComplete, loginAttempt, loginSuccess, loginFailure, logout, identify, storeSelect, setStore, search, loyaltyLogin, rewardView, rewardApply, rewardRemove, promoApply, promoRemove, setExperiment, error, flush, getSessionId, getVisitorId, getCustomerId.

veya.setStore('81', 'Earthbar Flagship - West Hollywood');
veya.addToCart({ id: 'olo:item:106702642', name: 'The Workout Smoothie', price: 12.95 }, 1);
veya.checkoutComplete({ order_id: '46749…', total: 12.95, items: [...] });

init() can be called more than once: calls made while one is in flight share it, and later calls resolve straight away, so React StrictMode's double effects are harmless.

Automatic events

EventWhenProperties
session_startOnce per new session — not again when a stored session is resumed (a full page load within the 30-minute timeout)platform
page_viewOn load, on client-side navigation, and when the page comes back from the browser's back/forward cache, only with autoDetect: true (the default). With autoDetect: false, call veya.pageView() yourself (a restore fires pageshow with event.persisted === true)page_url, page_title, page_type, referrer, utm_*
page_hidden / page_visibleThe tab is hidden / shown againpage_hidden: time_on_page (ms since the last page view or back/forward-cache restore); page_visible: none
scroll_depthThe page is scrolled past 25 / 50 / 75 / 100% — each once per page view, reset by every page view and by a back/forward-cache restore; pages that don't scroll report nothingdepth
page_unloadThe page is left (pagehide): full navigation, tab close, or going into the back/forward cachetime_on_page; persisted — true when the page went into the back/forward cache (it may be restored) rather than being unloaded
errorUncaught errors and unhandled promise rejectionserror_type, error_message, …

Properties named exactly email, phone, password, ssn, credit_card, cvv, address or street are dropped from every event (and from identify() traits) as a backstop against sending personal data by mistake. Only those exact top-level keys: don't rely on it to catch delivery_address, streetAddress or nested objects. ZIP / postal codes are allowed: send address_postal_code (5-digit ZIP) for delivery-area analysis, never the street address.

Changes in 4.0.4

  • Calling identify(), loginSuccess(), logout() or setExperiment() before init() no longer stores an empty session id, and a stored session without an id is never resumed. Before, every event in such a session was rejected for a missing session_id. Their effect on login state and experiments survives only when init() starts a new session, so still call them after await veya.init().

Changes in 4.0.3

  • The PII backstop no longer drops postal_code and zip — only the street-level address and street (plus the existing email / phone / password / SSN / card / CVV keys). A ZIP is coarse enough to keep, and it's what delivery-area analysis runs on; 4.0.2 dropped it along with the street address.

Changes in 4.0.2

  • page_unload is sent on pagehide instead of beforeunload. A beforeunload listener keeps Firefox from putting the page in its back/forward cache, so Back reloaded the page instead of restoring it; pagehide doesn't, and mobile browsers fire it more reliably when a tab is closed. New property persisted: true when the page went into the back/forward cache rather than unloading.
  • A page restored from the back/forward cache restarts time_on_page and the scroll_depth thresholds, and sends a page_view when autoDetect is on. Before, time_on_page after Back counted from the original load and scroll depth never fired again.
  • The PII backstop also drops address, street, postal_code and zip (4.0.3 keeps the ZIP keys again). query is deliberately not on the list: search events use it for what was typed.
  • Removed the aiEndpoint and useAiClassification options: nothing read them, and aiEndpoint defaulted to a host that doesn't resolve. TypeScript code that still passes them gets an excess-property error; delete them.

Changes in 4.0.1

  • session_start is sent (it was dropped because init() tracked it before marking itself initialized), once per new session.
  • No automatic page_view with autoDetect: false — 4.0.0 sent one on every load in addition to the app's own.
  • New automatic events: page_hidden / page_visible and scroll_depth (see above).
  • New method: addPaymentInfo(paymentMethod, properties?) → add_payment_info with { payment_method } at funnel step checkout_payment (4).
  • Unloading the page sends page_unload instead of session_end (the session carries on across full navigations).
  • Defaults: endpoint is the live https://analytics.builtonveya.com/v1/events (4.0.0 pointed at a host that doesn't resolve); interceptOloApi is now opt-in.
  • Concurrent init() calls share one run instead of both setting up listeners and sending session_start.

Server-side rendering

Importing the package on the server is safe: module load only registers window.veya when a window exists, and nothing touches the DOM until init() runs. Call init() from a client-side effect.

Build & publish

cd sdk/web
npm ci
npm run build      # dist/esm (ESM + types), dist/cjs, dist/veya-analytics[.min].js
npm run smoke      # loads all three outputs and checks the public surface
npm publish        # prepublishOnly runs build + smoke; scope @builtonveya is public

Bump version in package.json in step with the React Native package when the shared core changes.

版本与发布记录

@builtonveya/analytics-web 共发布 5 个版本,首次发布于 2026/09/26;过去 12 个月发布了 5 个版本。

版本发布日期距今
4.0.4latest2026/09/301 个月前
4.0.32026/09/261 个月前
4.0.22026/09/261 个月前
4.0.12026/09/261 个月前
4.0.02026/09/261 个月前

关于 @builtonveya/analytics-web 的常见问题

@builtonveya/analytics-web 是什么?

Veya Analytics SDK for the web - auto-detecting page, product and cart tracking for restaurant ordering sites

如何安装 @builtonveya/analytics-web?

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

@builtonveya/analytics-web 支持 TypeScript 吗?

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

@builtonveya/analytics-web 支持 ESM 还是 CommonJS?

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

@builtonveya/analytics-web 可以商用吗?

@builtonveya/analytics-web 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@builtonveya/analytics-web 的下载量有多少?

根据 npm 官方下载统计,@builtonveya/analytics-web 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,039 次,日均约 101 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@builtonveya/analytics-web 还在维护吗?

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