npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lydaas/quicktracking-js-analytics

v2.5.8

Published

Web QuickTracking SDK package candidate

Readme

QuickTracking Web SDK

通过 npm 将 QuickTracking 统计 SDK 集成到 Web 或 H5 应用,采集页面浏览、点击、曝光及自定义事件。

官方文档:

本文使用 npm 包说明常用接入方式;完整配置和 API 参数请参阅上述文档。示例统一使用 qt、qt_queue,旧版 aplus、aplus_queue 调用方式已标记为待废弃。

1. 安装与准备

npm install @lydaas/quicktracking-js-analytics

接入前,在 QuickTracking 控制台准备以下信息:

  • Web 应用的 appKey:在应用管理中获取。
  • 收数服务地址 trackDomain:在“管理控制台 → 采集信息”中获取。
  • 埋点方案:确定页面编码、事件编码及需要上报的业务属性。

此包包含 Web SDK 的 ESM、CommonJS 和 UMD 构建,运行依赖已打包。使用 npm 引入后,无需再添加官方文档中的 CDN 加载脚本。SDK 依赖浏览器的 window、document,应在浏览器端运行;服务端渲染项目请使用下文的客户端异步加载方式。

2. 引入与初始化

浏览器应用:静态引入

在应用的浏览器入口文件中引入并配置一次,例如 Vite 或 webpack 项目的入口:

import '@lydaas/quicktracking-js-analytics';

window.qt.initParams({
  appKey: 'YOUR_WEB_APP_KEY',
  trackDomain: 'https://tracking.example.com',
  DEBUG: false,
});

请将示例中的 appKey 和收数服务地址替换为控制台提供的值。trackDomain 填写收数服务的基础地址,不填写 SDK 文件地址或某个具体日志接口。开发联调时可将 DEBUG 设为 true,上线时设为 false。

使用 CommonJS 的浏览器项目,可将上面的 import 替换为:

require('@lydaas/quicktracking-js-analytics');

包加载时会创建 window.qt 和 window.qt_queue;它通过副作用运行,不导出可供 import qt from '...' 使用的 SDK 实例,也不导出 init() 函数。静态引入后立即调用 window.qt.initParams() 设置初始化参数。

异步加载与服务端渲染项目

如果使用动态 import(),在加载包前先创建指令队列并写入配置;在 SSR 项目中,仅从客户端挂载钩子或客户端入口调用下面的函数,不要在服务端静态引入 SDK。

export async function loadQuickTracking() {
  if (typeof window === 'undefined') return;

  window.qt_queue = window.qt_queue || [];
  window.qt_queue.push({
    action: 'qt.setMetaInfo',
    arguments: ['appKey', 'YOUR_WEB_APP_KEY'],
  });
  window.qt_queue.push({
    action: 'qt.setMetaInfo',
    arguments: ['trackDomain', 'https://tracking.example.com'],
  });
  window.qt_queue.push({
    action: 'qt.setMetaInfo',
    arguments: ['DEBUG', false],
  });

  await import('@lydaas/quicktracking-js-analytics');
}

静态与异步加载方式选择一种即可,同一页面只执行一次初始化。SDK 加载后会处理预先写入的队列,后续埋点也可继续使用 window.qt_queue.push()。每次 push 传入一个指令对象,多条指令分别调用。

监听 SDK 就绪

需要直接调用 window.qt.record()、window.qt.sendPV() 或读取配置时,可通过队列订阅就绪状态。静态方式在初始化配置后订阅;异步方式可在加载 SDK 前加入订阅任务。

window.qt_queue.push({
  action: 'qt.qt_pubsub.subscribe',
  arguments: [
    'qtReady',
    (status) => {
      if (status !== 'complete') return;
      console.log('QuickTracking 已就绪', window.qt.getMetaInfo('appKey'));
    },
  ],
});

import() 完成表示模块已加载;qtReady 的状态为 complete 才表示 SDK 功能已就绪。以下业务示例使用指令队列,可在配置完成后调用,无需自行等待就绪回调。

3. 设置账号与全局属性

SDK 默认生成设备标识。用户登录后,或带登录态进入页面时,设置业务账号 ID;退出登录时将其清空:

// 用户登录成功,或从业务登录态中取得账号后。
window.qt_queue.push({
  action: 'qt.setMetaInfo',
  arguments: ['_user_id', 'user_123'],
});

// 用户退出登录时调用。
window.qt_queue.push({
  action: 'qt.setMetaInfo',
  arguments: ['_user_id', ''],
});

两段调用分别放在登录和退出逻辑中。账号设置影响后续日志;如果首条日志也需要携带账号,应在初始化阶段准备账号信息。异步获取账号并需要暂缓日志时,可按埋点 API 文档使用队列的 _hold: BLOCK/START 配对控制。

需要在后续各事件中携带的公共业务属性,可通过 globalproperty 设置:

window.qt_queue.push({
  action: 'qt.appendMetaInfo',
  arguments: [
    'globalproperty',
    {
      app_channel: 'official_site',
      tenant_code: 'tenant_a',
    },
  ],
});

appendMetaInfo 追加属性,同名属性更新为新值;setMetaInfo('globalproperty', ...) 会覆盖整组静态全局属性。希望首条页面日志携带的公共属性,应在初始化参数中配置 globalproperty,或在异步加载 SDK 前写入配置队列。

4. 页面浏览采集

SDK 默认自动采集页面浏览,并监听浏览器 History 和 Hash 的变化。可在初始化参数中增加 pageConfig,将 URL 路径映射为业务页面编码和标题:

window.qt.initParams({
  appKey: 'YOUR_WEB_APP_KEY',
  trackDomain: 'https://tracking.example.com',
  DEBUG: false,
  pageConfig: {
    '/': { pageName: 'home', pageTitle: '首页' },
    '/products': { pageName: 'product_list', pageTitle: '商品列表' },
  },
});

这是对第 2 节初始化示例的替换,不需要再调用一遍。Hash 路由的映射方式及完整配置见埋点 API 文档。

如果由业务路由统一管理页面浏览,可以在初始化参数中增加 'aplus-waiting': 'MAN',关闭自动 PV,再在首屏和每次路由切换完成后手动上报:

window.qt_queue.push({
  action: 'qt.sendPV',
  arguments: [
    { is_auto: false },
    {
      page_name: 'product_detail',
      page_title: '商品详情',
      product_id: 'sku_001',
    },
  ],
});

sendPV 的第一个参数使用 { is_auto: false },第二个参数传本次页面属性。每个页面选择自动或手动采集,避免同一次页面浏览重复上报。

5. 点击、曝光和自定义事件

使用 record 上报事件,参数依次为:事件编码、事件类型、事件属性。事件编码应与平台埋点方案保持一致。

// 在点击处理函数中上报。
window.qt_queue.push({
  action: 'qt.record',
  arguments: [
    'buy_button_click',
    'CLK',
    {
      page_name: 'product_detail',
      product_id: 'sku_001',
      quantity: 1,
    },
  ],
});

| 事件类型 | 含义 | 调用时机 | | -------- | -------------- | ---------------------------- | | CLK | 点击事件 | 用户点击按钮或链接时 | | EXP | 曝光事件 | 业务确认内容曝光时 | | OTHER | 其他自定义事件 | 提交成功、流程完成等业务节点 |

曝光或其他事件沿用上面的结构,替换事件编码、类型和属性即可。record 是一次事件上报,不会自动给业务元素绑定点击或曝光监听。属性使用平铺对象,常用值为字符串、数值或字符串数组;不要传 DOM 元素或多层嵌套业务对象。

6. 集成校验

  1. 开发环境设置 DEBUG: true,确认 qtReady 收到 complete,配置中的 appKey 和收数地址正确。
  2. 打开浏览器 Network,按收数域名筛选请求,访问页面并触发一次业务事件,核对事件编码、账号和属性。
  3. 在 QuickTracking 控制台完成应用的“集成校验”,确认服务端收到对应日志。SDK 就绪本身不代表日志已被服务端接收。
  4. 上线前关闭调试日志,检查同一页面没有重复加载 SDK,也没有同时上报自动和手动 PV。

若没有请求,先检查客户端是否执行了初始化、appKey 和收数地址是否正确、是否仍处于 _hold: BLOCK,以及浏览器是否拦截了请求。更多配置、自动采集规则和完整 API 请查阅本文开头的三篇官方文档。

License

本 SDK 使用 MIT License。

Copyright (c) 2021-2026 Alibaba Group Holding Limited.