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

node-tongji

v1.0.1

Published

A node module for Baidu Tongji Api

Downloads

9

Readme

node-tongji

This is a module for Baidu Tongji Api of Node.js 7.6+

百度统计Api的Node.js模块,调用它来做其他的定时任务、统计数据同步之类的...

百度官方就特么给了个PHP的例子,所以花了点时间写了个js版本供大家使用和参考

喜欢的话就给个星星吧,蟹蟹各位大佬

注意!这个是统计Api的模块,用于导出百度统计中的数据,不是埋点用的

什么是百度TongjiApi

Installation 安装方式

$ npm install node-tongji --save

Config 配置

百度Tongji Api需要登录后才可以获取统计数据,因此,需要配置config来获取统计模块对象

Basic 基础字段

配置项config中需要包含以下基础字段

| Name       | Description   | Type | | ------------- |:---------------------------------:| ------:| | username     | 登录百度统计使用的用户名     | string | | password     | 登录百度统计使用的密码     | string | | token       | 在百度统计控制台中申请的token     | string | | uuid       | 随便起一个乱七八糟的东西就行     | string |

Optional 可选字段

  • logLevel:

日志输出等级, sting类型, 默认值为 info

可选值为 log, debug, info, warn, errorfatal

  • logProvider

日志的打印方式, function类型, 默认使用console进行输出

使用log4js示例如下

config.logProvider = () => {
  const logger = require('log4js').getLogger('TAM')
  logger.log = logger.trace
  return logger
}

未必好用,我自己没怎么测试这块哈哈哈

Examples 示例

const config = {
  username: 'YOURUSERNAME', //你登录百度统计时候用的账号
  password: 'YOURPASSWORD', //你的密码,放心我不会盗号
  token: 'YOURTOKEN', //你的token,在百度统计你的控制台页面里能找到
  uuid: 'this-is-a-fucking-uuid' //随便起个就行了
}

const tongji = require('node-tongji').getInstance(config)

const test = async () => {
  await tongji.login() //首先要登录

  const siteList = await tongji.getSiteList() //登录完之后可以拿到site list

  const siteid = siteList[0].site_id
  console.log(siteList)

  //这个param就自己随便写吧,看看百度统计F12就知道了。
  const data = await tongji.getData({
    site_id: siteid,
    method: 'custom/event_track/a',
    start_date: '2017-06-01',
    end_date: '2017-06-15',
    metrics: 'event_count,uniq_event_count',
    max_results: 20,
    order: 'event_count,desc'
  })
  console.log(data)

  //记得登出
  tongji.logout()
}

test()

Badges