
Company News
Meet the Socket Team at RSAC and BSidesSF 2026
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.
jstatistics
Advanced tools
安装
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
FAQs
The npm package jstatistics receives a total of 0 weekly downloads. As such, jstatistics popularity was classified as not popular.
We found that jstatistics demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.

Research
/Security News
Malicious Packagist packages disguised as Laravel utilities install an encrypted PHP RAT via Composer dependencies, enabling remote access and C2 callbacks.

Research
/Security News
OpenVSX releases of Aqua Trivy 1.8.12 and 1.8.13 contained injected natural-language prompts that abuse local AI coding agents for system inspection and potential data exfiltration.