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

shen-tool-frontend-track

v1.0.6

Published

前端埋点SDK - 支持页面曝光、元素曝光、元素点击

Readme

shen-tool-frontend-track

前端埋点SDK - 支持页面曝光、元素曝光、元素点击

安装

npm install shen-tool-frontend-track

使用

初始化

import { Analytics } from 'shen-tool-frontend-track';

// 创建实例
const analytics = new Analytics({
  endpoint: '/api/analytics',
  appId: 'shen-tool'
});

页面曝光

自动追踪,无需手动调用。页面加载或路由变化时会自动上报。

元素曝光

在需要追踪的元素上添加 data-track 属性:

<div data-track="Banner图">
  ...
</div>

当元素进入视口时自动上报。

元素点击

手动调用 trackClick 方法:

<Button onClick={() => analytics.trackClick('登录按钮')}>
  登录
</Button>

配置选项

interface AnalyticsOptions {
  /** 上报地址 (必填) */
  endpoint: string;
  /** 应用ID (必填) */
  appId: string;
  /** 队列阈值,默认20 */
  maxQueueSize?: number;
  /** 上报间隔,默认5000ms */
  flushInterval?: number;
  /** 是否自动追踪页面曝光,默认true */
  autoTrackPageView?: boolean;
  /** 是否自动追踪元素曝光,默认true */
  autoTrackElementView?: boolean;
  /** 是否自动追踪元素点击,默认true */
  autoTrackElementClick?: boolean;
  /** 获取用户ID的函数 */
  getUserId?: () => string;
}

数据结构

页面曝光

{
  "eventType": "page_view",
  "pageName": "工具页面",
  "pageUrl": "/tools",
  "referrer": "/home",
  "stayDuration": 30000,
  "userId": "user_xxx",
  "appId": "shen-tool",
  "timestamp": 1700000000000
}

元素曝光

{
  "eventType": "element_view",
  "pageName": "首页",
  "pageUrl": "/home",
  "elementName": "Banner图",
  "userId": "user_xxx",
  "appId": "shen-tool",
  "timestamp": 1700000000000
}

元素点击

{
  "eventType": "element_click",
  "pageName": "首页",
  "pageUrl": "/home",
  "elementName": "登录按钮",
  "userId": "user_xxx",
  "appId": "shen-tool",
  "timestamp": 1700000000000
}

上报机制

  • 批量上报:达到20条立即上报
  • 定时上报:每5秒上报一次
  • 页面隐藏时立即上报
  • 使用 sendBeacon 确保页面卸载时也能上报