@aranova/tracking-browser

中文文档
1.21.1发布于 2026/11/07近 30 天下载 2070

Aranova tracking global browser script (CDN /

原始使用文档
文档目录10 节
  1. Install
  2. Legacy static gtag IDs
  3. Manual Events
  4. Phone clicks ( tel: taps) — manual or auto-capture
  5. CTA clicks — manual or auto-capture
  6. Automatic dwell + exit ( page_exit )
  7. Global API
  8. Consent (v2 — opt-out model)
  9. On-site conversion firing
  10. Automatic Events

@aranova/tracking-browser

Global browser script for Aranova tracking on sites that cannot use the React or Next.js packages.

This package is intended for CDN/script-tag installs, not application imports.

Install

Place the script in the document <head> before the rest of the page can run.

<script src="https://cdn.jsdelivr.net/npm/@aranova/tracking-browser@0/dist/browser/aranova-tracking.global.js"></script>
<script>
  const ARANOVA_TRACKING_CONFIG = {
    businessId: "<business_id>",
    environment: "production",
    // Optional. Omit for the production CDN; set it to point at another origin
    // (e.g. a local object store). There is no bundler here to inline an env var.
    // cdnBaseUrl: "http://localhost:9100/aranova-demos",
  };

  window.AranovaTracking.init({
    apiKey: "aranv_pk_...",
    endpoint: "https://aranovainternal-production.up.railway.app/tracking",
    trackingConfig: ARANOVA_TRACKING_CONFIG,
    triggers: {
      automatic: {
        page_view: {},
        time_on_site: { thresholdSeconds: 60 },
        specific_page_visit: {
          pages: [{ name: "contact_page", pathPattern: /^\/(contact|book|get-started)/ }],
        },
      },
      manual: {
        form_submit: {},
        phone_click: {},
        cta_click: {},
      },
    },
  });
</script>

Pin an exact version for production when possible, for example @aranova/[email protected].

Tracking is on by default (consent v2, opt-out model) — the script ships no consent banner and the old renderConsentBanner option is a deprecated no-op. Wire a footer "cookie preferences" control to the consent API (see Consent below) and disclose the tracking + opt-out in the site's privacy policy.

Legacy static gtag IDs

gtagId and gtagIds remain compatibility APIs. Do not use them for new installs: static IDs cannot consume dashboard tag changes or tombstones without a site edit. If maintaining a legacy install, gtagIds loads every entry and takes precedence over gtagId.

<script>
  window.AranovaTracking.init({
    apiKey: "aranv_pk_...",
    endpoint: "https://aranovainternal-production.up.railway.app/tracking",
    environment: "production",
    gtagIds: { production: "AW-111111111", test: "AW-222222222" },
    triggers: { automatic: { page_view: {} } },
  });
</script>

Manual Events

The browser package validates manual events at runtime. If an event is not registered under triggers.manual, or the metadata shape is invalid, the SDK warns and drops the event.

<form id="lead-form" action="/api/lead">
  <select name="service_interest" aria-label="Service interest">
    <option value="cleaning">Cleaning</option>
    <option value="teeth_whitening">Teeth whitening</option>
  </select>
  <label>
    <input name="is_existing_patient" type="checkbox" />
    Existing patient
  </label>
  <button type="submit">Submit</button>
</form>

<script>
  document.getElementById("lead-form").addEventListener("submit", function (event) {
    var form = event.currentTarget;
    var data = new FormData(form);

    window.AranovaTracking.trackEvent("form_submit", {
      form: {
        id: form.id,
        action: form.getAttribute("action"),
        fields: [
          {
            name: "service_interest",
            type: "select",
            label: "Service interest",
            value: String(data.get("service_interest") || ""),
          },
          {
            name: "is_existing_patient",
            type: "checkbox",
            label: "Existing patient",
            value: data.get("is_existing_patient") === "on",
          },
        ],
      },
      page: { path: window.location.pathname },
    });
  });
</script>

fields[].value can be any JSON value: string, number, boolean, null, array, or object and is stored as first-party JSONB. Intentionally submitted lead fields may include raw names, emails, phone numbers, addresses, selections, free-text messages, and submitted file data for first-party analytics and lead operations. Build the array explicitly from the submitted form; the SDK never scrapes arbitrary DOM fields. File/Blob objects must be converted to a JSON representation; upload larger files separately and send their storage reference. No byte limit is enforced on event metadata — but a submit fired just before navigation flushes over keepalive, which browsers cap near 64 KB and drop silently, so keep inlined payloads small. Never send passwords, authentication tokens, payment-card/bank credentials, or private keys. Apply the client's privacy notice, consent, retention, and regulated-data requirements. Google offline matching uses normalized, server-side SHA-256-hashed identifiers — not raw free-text/file metadata.

Phone clicks (tel: taps) — manual or auto-capture

Opt into auto-capture and every tel: link is tracked with no per-link code — add autoCapture to the phone_click registration in init():

manual: {
  phone_click: { autoCapture: {} }, // default selector: a[href^="tel:"]
  // or narrow it: { autoCapture: { selector: "a.call" } }
},

Then use ordinary phone links — a single delegated listener does the rest:

<a href="tel:+14165550199" data-aranova-section="header">(416) 555-0199</a>

The number is read from the href (normalized to E.164); section comes from an optional data-aranova-section. Unlike cta_click, a phone_click also fires the Google Ads conversion for a linked phone-call goal (a CLICK_TO_CALL action) — auto-fired the moment the tap is captured, so you never call trackConversion. (Firing needs trackingConfig wired; see below.)

Prefer to instrument links yourself? Fire it per element instead — this fires the conversion the same way:

<a
  href="tel:+14165550199"
  onclick="window.AranovaTracking.trackEvent('phone_click', {
  phone_number: '+14165550199',
  page: { path: window.location.pathname },
  section: 'header'
})"
  >(416) 555-0199</a
>

CTA clicks — manual or auto-capture

Fire cta_click per element with an inline handler, or opt into auto-capture and skip the handlers entirely. Add autoCapture to the cta_click registration in init():

manual: {
  cta_click: { autoCapture: {} }, // default selector: [data-aranova-cta]
  // or target existing classes: { autoCapture: { selector: "a.cta, .btn-primary" } }
},

Then tag your CTAs with data attributes — a single delegated listener does the rest:

<a href="/booking" data-aranova-cta="Book now" data-aranova-section="hero">Book now</a>
<button data-aranova-cta="Get a quote">Get a quote</button>

cta_name resolves to the data-aranova-cta value, else the element's trimmed text (capped 120 chars), else tag#id. section comes from an optional data-aranova-section; href/destination_url and a short element descriptor are captured automatically. Point the selector at real CTAs (an explicit attribute is the safe default) — every matching click is counted, including ones that later stopPropagation.

Automatic dwell + exit (page_exit)

page_exit is captured automatically — no registration. On navigation, tab hide, and page unload it records the active (visible) time spent on the page plus the max scroll depth reached, delivered via a keepalive beacon so the final page still counts. This powers per-page dwell and drop-off in the dashboard Analytics tab; there is nothing to configure.

Global API

window.AranovaTracking.init(config);
window.AranovaTracking.trackEvent(eventType, metadata);
window.AranovaTracking.captureTrackingParams();
window.AranovaTracking.getTrackingParams();
window.AranovaTracking.sales().record({ ... }); // record a sale / conversion

Tracking is on by default; only a stored, unexpired explicit decline blocks gtag, the Meta Pixel, and conversion firing. A decline is honored for 90 days; a grant never expires. Wire a footer control to:

window.AranovaTracking.optOut(); // explicit decline (90 days)
window.AranovaTracking.optIn(); // explicit grant (never expires)
window.AranovaTracking.resetConsent(); // clear the choice → back to default-granted
window.AranovaTracking.getConsentChoice(); // { state, source, updatedAt, expiresAt }
window.AranovaTracking.getConsentState(); // effective "granted" | "denied"
<button onclick="window.AranovaTracking.optOut()">Opt out of ad measurement</button>

setConsentState('granted' | 'denied') remains for compatibility.

sales() returns a client bound to the public key and endpoint you passed to init(), so it can only write conversions (record). All reads — list, summary (tz-aware aggregations), the phone-keyed customers.* roster, business.config(), update, delete — require a secret key (aranv_sk_…) and must run server-side via the React/Next packages. See the sales-tracking guide.

On-site conversion firing

Pass the generated ARANOVA_TRACKING_CONFIG reference to init(). The browser SDK shares one R2 runtime for Google tag loading, page views, automatic goals, and AranovaTracking.sales() firing. It confirms the current object before any Google command; dashboard tag changes, goal remaps, and higher-version disabled tombstones propagate under public, max-age=60, must-revalidate with no CLI run or site redeploy.

<script>
  const ARANOVA_TRACKING_CONFIG = {
    businessId: "<business_id>",
    environment: "production",
    // Optional. Omit for the production CDN; set it to point at another origin
    // (e.g. a local object store). There is no bundler here to inline an env var.
    // cdnBaseUrl: "http://localhost:9100/aranova-demos",
  };

  window.AranovaTracking.init({
    apiKey: "aranv_pk_...",
    endpoint: "https://api.example.com/tracking",
    triggers: {
      automatic: { page_view: {}, scroll_depth: { thresholds: [50] } },
      manual: { phone_click: {} },
    },
    trackingConfig: ARANOVA_TRACKING_CONFIG,
  });

  // Automatic event-goals (scroll/time/page-view/…) fire THEMSELVES — no code.
  // init() also binds the sales client to the config, so these fire too:
  window.AranovaTracking.sales().recordSale({
    currency: "CAD",
    amount_total_cents: 25000,
    service: "tires",
  }); // records + fires
  window.AranovaTracking.sales().trackConversion("phone_click"); // fires a manual event-goal only
</script>

Firing is consent-gated and de-duped by transaction_id. Remapping an existing key needs no codegen. A new manual goal key still requires tracking-cli gen to refresh the generated key list and site code that calls trackConversion(key). conversionConfig: { cdnUrl } and generated ARANOVA_CONFIG_URL remain legacy compatibility APIs; do not use them for new installs. See conversion-config-schema.md.

Automatic Events

Configured automatic events are fired by the SDK:

  • page_view
  • time_on_site
  • specific_page_visit
  • scroll_depth
  • multi_page_session
  • form_start

版本与发布记录

@aranova/tracking-browser 共发布 85 个版本,首次发布于 2026/04/10;过去 12 个月发布了 85 个版本。

版本发布日期距今
1.21.1latest2026/11/07今天
1.21.02026/11/07今天
1.20.02026/11/07今天
1.19.02026/10/308 天前
1.18.02026/10/2117 天前
1.17.02026/10/2018 天前

关于 @aranova/tracking-browser 的常见问题

@aranova/tracking-browser 是什么?

Aranova tracking global browser script (CDN /

如何安装 @aranova/tracking-browser?

在项目目录运行 npm install @aranova/tracking-browser,或使用 pnpm add / yarn add / bun add。

@aranova/tracking-browser 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/aranova__tracking-browser 是否存在。

@aranova/tracking-browser 可以商用吗?

@aranova/tracking-browser 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@aranova/tracking-browser 的下载量有多少?

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

@aranova/tracking-browser 还在维护吗?

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