@caravela-studio/glancy-web

中文文档
0.4.0发布于 2026/11/05MITTypeScriptES Module近 30 天下载 1942

Glancy for the browser: events, page views, session replay and heatmaps — any framework or none

原始使用文档
文档目录3 节
  1. npm
  2. Server
  3. Script tag (glancy.js)

@caravela-studio/glancy-web

Glancy in the browser, for any framework (or none): events, page views, session replay and heatmaps. On Next.js use @caravela-studio/glancy-next, which wraps this with a provider and a server client. On a site without a build step (or WordPress), use the script tag glancy.js below.

npm

Public on npm, no token needed:

npm install @caravela-studio/glancy-web
import { BrowserClient } from "@caravela-studio/glancy-web";

export const glancy = new BrowserClient({
  writeKey: "glc_prod_…",            // Glancy → Setup
  // host: "https://analytics.example.com", // only when self-hosting (default https://ingest.heyglancy.com)
  heatmaps: true,                     // optional
  sessionReplay: { sampleRate: 0.5 }, // optional; inputs are masked
});

glancy.page();                        // on every route change (your router's hook)
glancy.track("Order Completed", { revenue: 42 });
glancy.identify(user.id, { name: user.name, email: user.email });
glancy.reset();                       // on sign out
OptionDefault
writeKey, host—Required
heatmapsfalseClicks and scroll depth
sessionReplayfalsetrue or { sampleRate, maskAllInputs, maskAllText, maskTextSelector, blockSelector }
redactParamskey, token, code, password…Query parameters replaced by redacted in URLs
flushAt / flushInterval20 / 2000 msBatching
consent—{ ads: boolean }, the visitor's ad consent if already known
debugfalseLog every event

Methods: track, page, identify, group, alias, reset, flush, getAnonymousId, getUserId, getSessionId, startRecording, stopRecording (e.g. when consent is withdrawn), consent({ ads }) (from your consent banner: with ads: false, the visitor's events are never sent on to ad platforms; a browser with Global Privacy Control on counts as ads: false).

Privacy: data-glancy-mask hides an element's text in replays, data-glancy-block leaves it out.

Server

@caravela-studio/glancy-web/server: glancy() / ServerClient for any JavaScript server, plus request tracking with status and duration_ms as API Request events: withGlancyRoute(handler, { waitUntil? }) for fetch-style handlers and trackRequests() for Express / Connect. Events report @glancy/web-server as their library, so ingestion treats them as server events. See /docs/sdks/web.

Script tag (glancy.js)

Every Glancy serves it (~7 KB gzipped). Each feature is its own file, fetched only when it's on: glancy-capture.js (autocapture, heatmaps), glancy-errors.js, glancy-vitals.js (at idle) and glancy-replay.js (only for sampled sessions):

<script defer src="https://ingest.heyglancy.com/glancy.js" data-key="glc_prod_…" data-heatmaps data-replay></script>
Attribute
data-keyThe bucket's write key (required)
data-hostWhere Glancy runs (default: where the script came from)
data-heatmaps, data-replay, data-replay-sample="0.25"Heatmaps / session replay
data-outbound-linksTrack clicks on links to other sites
data-redact-params="order,email"More query parameters to hide
data-manualNo automatic page views
data-debugLog everything

Then glancy.track(…), glancy.identify(…), glancy.reset(). To call it before the script has loaded, add the stub first and use the function form:

<script>window.glancy=window.glancy||function(){(glancy.q=glancy.q||[]).push([].slice.call(arguments))}</script>
<script>glancy("track", "Pricing Viewed")</script>

No code at all: <button data-glancy-event="Demo Requested" data-glancy-prop-plan="pro"> (works on forms too).

版本与发布记录

@caravela-studio/glancy-web 共发布 8 个版本,首次发布于 2026/10/23;过去 12 个月发布了 8 个版本。

版本发布日期距今
0.4.0latest2026/11/055 天前
0.3.12026/11/045 天前
0.2.02026/10/3011 天前
0.1.32026/10/2713 天前
0.1.22026/10/2713 天前
0.1.12026/10/2417 天前

关于 @caravela-studio/glancy-web 的常见问题

@caravela-studio/glancy-web 是什么?

Glancy for the browser: events, page views, session replay and heatmaps — any framework or none

如何安装 @caravela-studio/glancy-web?

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

@caravela-studio/glancy-web 支持 TypeScript 吗?

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

@caravela-studio/glancy-web 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@caravela-studio/glancy-web 可以商用吗?

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

@caravela-studio/glancy-web 的下载量有多少?

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

@caravela-studio/glancy-web 还在维护吗?

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