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

ys-sdk

v0.8.5

Published

- 简要说明

Readme

小程序数据埋点

  • 简要说明

    • 用于页面的数据埋点(UV、PV、停留时长、触达率等
  • 项目构建

    • 打生产包:yarn build:ys
    • 打测试包:yarn build:ys_dev
    • npm 包地址

接口说明

Usage

// 使用生产环境接口
const yssdk = require("ys-sdk")("production");
// 使用测试环境接口
// const yssdk = require("ys-sdk")("test");

// 渠道枚举,目前的可选值
export enum SourceFrom {
  YISEN_AJN = "YISEN_AJN",
  YISEN_CONTENT_H5 = "YISEN_CONTENT_H5",
  HEYSHOP_CONSTELLATION_MINI = "HEYSHOP_CONSTELLATION_MINI"
}

export interface ILogConfig {
  openId: string;
  userId: string;
  unionId: string;
  contentId: number;
  columnId: number;
  clientHeight: number;
  character: string; // 表示用户的角色,是促销员还是客户,"seller" 或者 "customer"
  sessionId?: string;
  title: string; // 内容或素材的名称,如:"内容A"
  columnName: string; // 栏目名称,如果有多级栏目则用逗号分隔,如:"栏目1,栏目2"
  keyWords?: string | null; // 关键词,如果有多个则用逗号分隔,如:"关键词1,关键词2",没有则不传或传 null
  contentCreateTime: string | number; // 内容的创建时间,传字符串或者时间戳,格式保持一致就行
  isShared: boolean; // 页面是分享出去的页面,则传 true,默认是 false
  sellerId?: string | number | null; // 分享者或直销员的ID,从分享出去的页面访问需要传入
  sellerName?: string | null; // 分享者或直销员的姓名,从分享出去的页面访问需要传入
  department?: string; // 直销员所属部门,或是门店名称,如:"上海xxx店"
  sourceFrom: SourceFrom | string; // 渠道来源,必传
}

const log = new yssdk.Log({
  openId: "aaa",
  userId: "bbb",
  unionId: "ccc",
  contentId: 567,
  columnId: 23,
  clientHeight: 666,
  character: "seller",
  title: "内容标题",
  columnName: "栏目1",
  keyWords: "关键词1,关键词2",
  contentCreateTime: 1604460370000,
  isShared: false,
  sellerId: 123,
  sellerName: "直销员1",
  department: "上海xxx门店",
  sourceFrom: yssdk.Log.SourceFrom.YISEN_AJN
});
/**
 * 统计PV,页面加载完后调用
 */
log.event_page_pv();

/**
 * 跳失率,用户有触摸操作后调用
 */
log.event_page_loss_access();

/**
 * 阅读比例,页面加载完和滚动时调用
 */
log.event_page_send_position(scrollHeight: number, scrollTop: number);

/**
 * 页面停留时长,页面加载完后调用
 * @param {number} timeout 埋点请求触发频率,默认值 10000ms
 */
log.event_page_access_time(timeout?: number);

/**
 * 热力图,滚动时调用
 */
log.event_page_hotaccess_time(scrollHeight: number, scrollTop: number);

/**
 * 触发页面隐藏
 */
log.event_page_hide();

/**
 * 触发页面回显
 */
log.event_page_show();

/**
 * 触发页面卸载
 * 提供这个方法是为了在页面卸载时取消定时器
 */
log.event_page_unload();

/**
 ** 内容页点击有用
 */
log.event_page_useful();

/**
 * 点击下载按钮
 */
log.event_page_download();

/**
 * 点击分享按钮
 */
log.event_page_share();

/**
 * 专门用来更新 columnId 这个字段的方法
 * 因为之前有很多埋点数据缺失 columnId
 */
log.upgradeColumnId(columnId: number);