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

website-collection

v0.1.3

Published

Site data collection and reporting

Readme

website-collection

npm version License npm downloads

Site data collection and reporting library for browser environments. 自动采集网站访问数据并上报。

Features 特性

  • Device Info - 自动采集设备信息(屏幕尺寸、设备ID、操作系统等)
  • Network Status - 检测网络状态(WiFi/移动网络等)
  • Page Tracking - 自动采集页面信息(URL、标题、来源等)
  • Persistent UUID - 持久化设备ID,支持跨会话识别用户
  • Custom Data - 支持添加自定义采集字段
  • Path Filtering - 支持忽略特定路径不上报
  • Data Encoding - 支持自定义数据编码方式

Install 安装

npm install website-collection

Quick Start 快速开始

Script Tag

<script src="https://unpkg.com/website-collection/lib/website-collection.js"></script>
<script>
  const collector = new EventCollection({
    url: "https://your-api.com/collect"
  });
  collector.send();
</script>

ES Module / TypeScript

import { EventCollection } from 'website-collection';

const collector = new EventCollection({
  url: "https://your-api.com/collect",
  headers: { "Authorization": "Bearer token" }
});

collector.send();

API

Constructor 配置项

| Option | Type | Required | Description | |--------|------|----------|-------------| | url | string | Yes | 数据收集接口地址 | | headers | object | No | 请求头 | | ignorePathName | string[] | No | 忽略上报的路径列表 | | code | ICode | No | 自定义编码器 |

Methods 方法

| Method | Description | |--------|-------------| | send(eventName?) | 发送数据到收集接口 | | addCustomData(data) | 添加自定义字段 | | getData(event?) | 获取采集的数据 | | getDeviceId() | 获取设备ID |

Usage Examples 使用示例

Basic Usage 基础用法

const collector = new EventCollection({
  url: "https://your-api.com/collect"
});

// 页面加载时发送
collector.send('page_view');

With Custom Headers 带请求头

const collector = new EventCollection({
  url: "https://your-api.com/collect",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer your-token"
  }
});

Custom Data 自定义数据

const collector = new EventCollection({
  url: "https://your-api.com/collect"
});

// 添加自定义字段
collector.addCustomData({
  userId: '12345',
  plan: 'premium'
});

collector.send();

Ignore Paths 忽略路径

const collector = new EventCollection({
  url: "https://your-api.com/collect",
  ignorePathName: ['/login', '/register', '/admin']
});

// 访问 /login 时不会发送数据
collector.send();

Periodic Reporting 定时上报

const collector = new EventCollection({
  url: "https://your-api.com/collect"
});

setInterval(() => {
  collector.send('heartbeat');
}, 30000); // 每30秒上报一次

Collected Data 采集数据

| Field | Type | Description | |-------|------|-------------| | device_id | string | 设备唯一标识(UUID) | | event | string | 事件名称 | | device_width | number | 屏幕宽度 | | device_height | number | 屏幕高度 | | is_wifi | boolean | 是否WiFi网络 | | user_agent | string | 用户代理 | | app_code_name | string | 浏览器代码名 | | app_name | string | 浏览器名称 | | language | string | 语言设置 | | platform | string | 平台信息 | | time_zone | string | 时区 | | current_url | string | 当前页面URL | | pathname | string | 页面路径 | | referrer_url | string | 来源页面 | | document_title | string | 页面标题 | | begin_time | number | 事件发生时间戳 |

Browser Support 浏览器支持

  • Chrome 80+
  • Firefox 75+
  • Safari 13+
  • Edge 80+

License

Apache-2.0