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

jstatistics

v4.4.4

Published

一个统计系统

Downloads

19

Readme

安装

npm install --save jstatistics 

使用

到这个网站http://test-iappweb.jpushoa.com/front-stat/建个统计项目,然后把下面例子的ID "12" 改成你的。

import { StatisticsModule } from 'jstatistics';

const d=new Date();
d.setHours(d.getHours() + 24);

export interface Option {
    useHash?: boolean;
    captureHttp?: boolean;
    captureError?: boolean;
    captureRouteChange?: boolean;
    user_id?: string;
    log?: boolean;
    host: string; 
    data?: Date;
}

const defaultOption = {
    useHash: false, // 默认前端路由是h5 history
    captureError: false, // 自动监听window.onerror,并发送统计
    captureHttp: true, // 拦截http请求
    captureRouteChange: true, // 拦截路由跳转
    log: true, // 是否输出日志
    user_id: 'xxxxx',
    host: 'xxxx' ,// 后台服务器地址
    date: d // 默认1天后cookie过期
};


@NgModule({
    ...
    imports: [
        ...
        StatisticsModule.forRoot('12', { host: '123' })
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule  {

}



import { StatisticsService } from 'jstatistics';
@Component({
    ...
})
export class AppComponent {
  title = 'app';
  constructor(private stat: StatisticsService) {
    console.log(stat);
  }
}

方法

    setUserId(id: string): this; // 设置用户ID
    clearUserId(): this; // 清除用户ID
    error(e: Error): Promise<{}>; // 发送报错信息
    addNetworkListener(cb: Function): void; // 添加网络请求的监听
    events(events: string[], extras?: {
        [propName: string]: string;
    }): Promise<{}>; // 发送事件
    uteReport(data: any): Promise<{}>; // 上报ute报告
    setChangeURL(url: any): Promise<{}>; //再配置中关闭自动url切换上报,手动上报方法
    setCookie(key: string, value: any, expires?: Date): boolean; //expires默认和其他cookie保持一致,通过client_id_expires的cookie拿到
    
    static getCookie(key: string): string;
    static setCookie(key: string, value: any, expires?: Date): boolean;
    static base64:{
        decode(str) // 解码base64
        encode(str) // 编码base64
    }

更新

2.1.0
Statustics 这个单词写错了,改成了 StatisticsService。在2.1.0中修复了

2.8.0
referrer信息放在cookie,默认一天过期

script引入

    从node_modules/jstatistics/build/output/statistics.js 拷出来
    <script src="/assets/js/statistics.js"></script>
    <script>
        window['stat'] = new Statistics('12', { log: false, host: 'http://183.232.42.221:8091/v1' }); // 测试环境sdk后台

        window['stat'] = new Statistics('12', { log: false, host: 'https://stat-srv.jiguang.cn/v1/sdk' });  // 生产环境sdk后台
    </script>

    declare const stat;
    stat.xx //使用

CDN

https://o8ci6tgz8.qnssl.com/jstatistics/{ 版本号 }/statistics.js