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 🙏

© 2024 – Pkg Stats / Ryan Hefner

px-tracker

v0.1.8

Published

针对螃蟹项目做的定制化埋点SDK

Downloads

25

Readme

螃蟹的埋点SDK

针对螃蟹项目做的定制化埋点SDK

使用

<script src="http://10.176.50.131:5500/dist/index.js"></script>
<script>
  const pxTracker = new window.PxTracker({
    reportUrl: 'xxx',
  });
  pxTracker.reportTracker('测试主动上报');
</script>

● 安装

npm install px-tracker

● 使用

  1. 初始化
import PxTracker from 'px-tracker'
const pxTracker = new PxTracker({
  open: true,
  env: 'dev',
  entryRatio: 1,
  outRatio: 0.2
}:{
  /** 开关,默认true */
  open?: boolean;
  /** 使用哪个环境,默认dev */
  env?: 'dev' | 'prod';
  /** 触发算曝光的比例 0-1,默认1 */
  entryRatio?: number;
  /** 触发不算曝光的比例 0-1,默认0.2 */
  outRatio?: number;
  request?: (data: {
    url: string;
    header: Record<string, string>;
    method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'CONNECT';
    data: string;
  }) => void
})
// 可挂在到vue实例上
app.config.globalProperties.$pxTracker = pxTracker;
  1. 暴露出来的一些方法
// 设置userid
pxTracker.setUserId('test')
// 设置游客Id
pxTracker.setVisitorId('test')
// 设置sessionId(new的时候会默认从cookie中获取sessionId,也可手动用此方法设置)
pxTracker.setSessionId('test')
// 设置token
// pxTracker.setToken('test')
// 设置页面pageCode
pxTracker.setPageCode('test')
// 主动上报PV
pxTracker.reportPV(code: string)
// 用户主动上报
pxTracker.reportTracker(spmCode: string, data: Record<string,any>)
// spmCode 实例 { spmCode: 'a.b.c.d', gameId:'', productId:''}
// 初始化埋点request请求(适合没有navigator?.sendBeacon的环境使用),例:pxTracker.initRequest(uni.request)
pxTracker.initRequest(request: ({
  url: string;
  header: Record<string, string>;
  method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'CONNECT';
  data: string;
}) => void)
  1. pv使用

    pv为自动埋点,无需手动配置

  2. 曝光度使用

// 参数为需观察元素的数组
pxTracker.initExposureTracker(HTMLElement[])
// 例(也可用Ref实例)
pxTracker.initExposureTracker([document.querySelector('.test1'), document.querySelector('.test2'), document.querySelector('.test3'), document.querySelector('.test4'), document.querySelector('.test5'), document.querySelector('.test6'), document.querySelector('.test7')])
// 注:每个元素必须要有独一无二的id,id中需包含index(列表中的角标,v-for的index)等其他信息,如数据那边想知道观察的这个元素的商品id,可写作index-goods-id,这里的数据格式由数据那边定义,这边只保存id
1. 曝光百分比使用
// 第一个参数为需观察元素的数组,第二哥参数为需观察元素所在的滚动区的元素
pxTracker.initExposurePercentTracker(HTMLElement[],HTMLElement)
// 例(也可用Ref实例)
pxTracker.initExposurePercentTracker([document.querySelector('.test7'), document.querySelector('.test5')], document.querySelector('.main'))
// 注:每个元素必须要有独一无二的id,id中需包含index(列表中的角标,v-for的index)等其他信息,如数据那边想知道观察的这个元素的商品id,可写作index-goods-id,这里的数据格式由数据那边定义,这边只保存id id: account-index ,type data-set