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

@medlinker/data-tracker

v0.2.9

Published

医联数据埋点工具

Downloads

5

Readme

@medlinker/data-tracker

多端埋点工具 文档

安装

NPM 安装(推荐)

npm i @medlinker/data-tracker
import MedDT from '@medlinker/data-tracker/browser';

MedDT.init(...);

全局安装

下载文件,并通过 script 标签引用。

<script src="/js/med-tracker/browser.js"></script>
/// <reference types="@medlinker/dt/browser" />

MedDT.init(...);

使用

初始化

模块需要通过调用 init 方法完成初始化。只有在初始化后,才能正常上报埋点信息,初始化前的埋点会被忽略。

MedDT.init(config);

config.hash

类型:boolean,默认为 false。

当前项目使用使用了 hash 路由

config.enable

类型:boolean,默认为 true。

是否启用,开发模式下一般设置成 false。

config.env

类型:dev | qa | prod,默认为 dev

项目当前运行的环境,决定了上传的接口。

埋点方式

手动上报

通过调用方法来进行上报。

方法:MedDT.collect(data:UserDataEntity)

interface UserDataEntity {
  /**
   * log_type
   */
  lt?: number;
  /**
   * event_id
   */
  ei?: number;
  /**
   * event_param
   */
  ep?: string;
  /**
   * business
   */
  b?: string;
}
function Login() {
  return (
    <button
      onClick={() => {
        MedDT.report({
          b: 'someActivity',
          ei: '0',
        });
        // 业务代码逻辑
      }}
    >
      提交
    </button>
  );
}

隐式上报

点击事件埋点更建议使用隐式上报。这种方式对业务代码的侵入性会小一些。

function Login() {
  return (
    <button
      data-medtrack="b:patient;ei:0;s:web"
      onClick={() => {
          // 业务代码逻辑
        };
      }
    >
      提交
    </button>
  );
}

这样每次点击 button 都会将data-medtrack携带的信息进行上报。

API

MedDT.init(config)

初始化配置

MedDT.ready()

调用此方法前的埋点会加入队列直到已经准备完成。一般在获取用户 id 后再调用此方法。

MedDT.setUserId(id:string)

设置当前登录的用户 id

MedDT.collect(data: UserDataEntity)

埋点方法

export interface UserDataEntity {
  /**
   * log_type,默认为1
   */
  lt?: number;
  /**
   * event_id 默认为 -1
   */
  ei?: number;
  /**
   * event_param 默认为 ''
   */
  ep?: string;
  /**
   * business 默认为 ''
   */
  b?: string;
}

MedDT.reset()

重置 tracker。

SPA 应用

  1. 在路由变化时调用一次 MedDT.collect()
  2. 用户退出登录后,如果没有刷新页面,可以调用MedDT.reset() 重置模块。