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

barrett-decorator

v1.2.3

Published

### 初始化 ``` BarrettInit([{ name: 'sensors', uid: cookie.get('uid'), config: { send_type: 'ajax', server_url: process.env.VUE_APP_SENSORS_API, heatmap_url: 'https://static.sensorsdata.cn/sdk/1.14.2/sensorsdata.min.js',

Downloads

8

Readme

埋点组件

初始化

  BarrettInit([{
    name: 'sensors',
    uid: cookie.get('uid'),
    config: {
      send_type: 'ajax',
      server_url: process.env.VUE_APP_SENSORS_API,
      heatmap_url: 'https://static.sensorsdata.cn/sdk/1.14.2/sensorsdata.min.js',
      use_client_time: true,
    }
  }]);

  // vue
  // meta 支持 字符串 or object,第三个参数对应 object 的 key
  router.afterEach((to, from) => {
    BarrettPageView(to.fullPath, to.meta, null, {
      $url_path: to.path,
    });
  });

BarrettMaterialAutoReport

  <element>
    :bt-data="JSON.stringify({
      card_type: 'set_flow_banner',
      material_order: index,
      material_id: image.id,
      link: image.link,
      material_position: plate.id,
      ...,
    })"
  </element>

使用方式一,用于某些回调执行的上报,例如 swipe

  @BarrettMaterialAutoReport([
    {
      targetSelector: '.home-xxxx',
      offset: {
        top: 46,
        bottom: 50,
      },
      params: {
        xxxx: 1
      }
    },
  ])
  private sendBarrettSwipe(data: any) {
    return data;
  }

使用方式二,用于产品列表图之类的滚动到可视区域的上报功能,scrollSelector 必填

  @BarrettMaterialAutoReport([
    {
      scrollSelector: '.page-content_main',
      targetSelector: '.home-goods-item',
      offset: {
        top: 46,
        bottom: 50,
      }
    },
  ])
  private async mounted() {
    await this.onRefresh();
  }
  1. 注:params 的附加数据,会被合并到 上报数据中,用于一些固定参数,避免在 element 上写过多
  2. 方法一,仅仅进行简单的判定触发的时候是否在视区来判定上报
  3. 方法二,会判定视区的数据是否需要上报,上报规则见 util.ts -> isReportAndSetART
  4. 注意 当使用该方法在 mounted 的时候,请确保元素加载完毕,可以使用 async await

BarrettPageView,通过路由进入的 pageview 埋点

  router.afterEach((to, from) => {
    ...
    BarrettPageView(to);
  });

BarrettMaterialReport,主动上报

  @BarrettMaterialReport({ event: 'btn_download_safari' }, event, filterFunction)
  private onClick() {
    console.log('clicked');
  }

  // 仅在 xxx 情况下才进行上报
  @BarrettMaterialReport({ event: 'btn_download_safari' }, 'event_xxx', function() {
    return this.$route.query.from === 'xxx';
  })
  private onClick() {
    console.log('clicked');
  }

  // fn 返回不为 false 的时候进行上报
  @BarrettMaterialReport((event: any) => {
    // this, ...args
    try {
      return JSON.parse(event.target.getAttribute('bt-data'));
    } catch (ex) {
      return {};
    }
  })
  private fn() {
    return true;
  }

  // 同上,如果存在异步,使用 async / await
  @BarrettMaterialReport((event: any) => {
    return {};
  })
  private async fn() {
    const res = await xxx();
    return res.status === 1;
  }

重写 report 实例方法, middleware/BarrettSensors.ts, ...

  import BarrettSensors from 'barrett-decorator/lib/middleware/BarrettSensors';

  BarrettSensors.prototype.sendPageview = (data: any) => {
    console.log('sendPageview', data);
  };
  BarrettSensors.prototype.sendMaterial = (event: string, data: any) => {
    console.log('sendMaterial', event, data);
  };