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

sd-wxlittle-track-service

v0.7.4

Published

sd 小程序 统计封装

Downloads

4

Readme

sd-track-demo

SD 小程序 统计封装

详见Git
WIKI地址

安装使用

npm i [email protected] --save

集成

初始化

创建servicies/trackService.js文件

import trackService from 'sd-wxlittle-track-service'

const tracker = trackService.wxLittleCreate({
  showLog: false, // 是否打印统计成功 log
  /**
   用于从Storage中获取account Object的对应key
   account Object 应该包含 account = {cryptoUserId, sdToken}
   */
  accountKey: 'account',
  commonParams: () => {
    return {
      biz: 'DEMO_TRACK', // 根据业务自行修改 后面可能会删掉
      appType: -1, // 根据业务自行修改, 后面可能会删掉
      appId: 'sd123456' // 根据业务自行修改
    }
  },
  commonControlArg: {
    host: 'shuidichou.com', // 默认为水滴筹
    onHandleTrack: (trackData, controlArg) => { // 用于打印发出的统计log 可注释掉
      const {
        showInfo = true
      } = controlArg
      if (showInfo) console.info(trackData)
    }
  }
})

export default tracker

集成来源统计 与 位置统计

app.wepy中调用tracker.onLaunch(...args) src/app.wpy

import tracker from './servicies/trackService.js'
export default class extends wepy.app {
  onShow(options) {
    tracker.onAppShow(options) // 满足小程序来源统计需求
  }
  onLaunch(options) {
    tracker.onAppLaunch(options) // 满足小程序来源统计需求
    // tracker.loadLocation() // 满足小程序位置统计需求
  }
  onHide(){
    // 切到后台 视为 跳转到了 名字为 fakePageBackground 的新页面
    // 用于精细化统计
    tracker.onAppHide()
  }
}

集成页面统计 与 分享

1.第一种方式 mixin来实现 mixins/trackMixin.js

import wepy from 'wepy'
import tracker from '../servicies/trackService'

const TAG = 'track'

export default class TrackMixin extends wepy.mixin {
  onShow() {
    tracker.onPageShow()
    log('pageName', tracker.currentPage)
    log('fromPath', tracker.lastPage)
    log('visitDv', tracker.visitDV)
    log('mixin onShow')
  }

  onLoad() {
    log('mixin onLoad')
    wx.showShareMenu({
      withShareTicket: true
    })
  }
}

function log (...args) {
  console.log(TAG, ...args)
}

因为小程序并不支持全局mixin,所以还是需要在所有页面 加一下mixin配置 pages/index.wpy

import wepy from 'wepy'
import trackMixin from '../mixins/trackMixin'
export default class Index extends wepy.page {
  config = {
    navigationBarTitleText: 'index'
  }

  mixins = [trackMixin] // 引入mixin

  onShareAppMessage(options) { // 满足分享统计需求
    return tracker.onShareAppMessage({title: 'specialTitle'}, options, {
      // shareParams: {haha: 'haha'}, // 分享出去的path后面拼上的参数
      // trackParams: {k1: 'k1v'}, // 公共分享统计附加参数
      // extInfo: {k1: 'k1v'} // 公共分享统计附加的扩展参数
    })
  }
}

2.第二种方式 不推荐,有复杂自定义需求可以考虑 在所有页面的onShow方法里调用tracker.onShow() pages/index.wpy

import wepy from 'wepy'
import tracker from '../servicies/trackService.js'
export default class Index extends wepy.page {
  config = {
    navigationBarTitleText: 'index'
  }

  onShow() {
    tracker.onPageShow() // 满足小程序页面统计需求
  }

  onLoad() {
    wx.showShareMenu({
      withShareTicket: true
    })
  }

  onShareAppMessage(options) {
    return tracker.onShareAppMessage({title: 'specialTitle'}, options, {
      // shareParams: {haha: 'haha'}, // 分享出去的path后面拼上的参数
      // trackParams: {k1: 'k1v'}, // 公共分享统计附加参数
      // extInfo: {k1: 'k1v'} // 公共分享统计附加的扩展参数
    })
  }
}

其他业务统计 调用

tracker.track({
  op: 'login',
  mobile: 'xxxxx'
})

更多详细api见demo 和源码


  const targetAction = title => console.warn(`targetAction ${title} run`)

  const action1 = title => {
    targetAction(title)
    tracker.track({op: title})
  }
  const action2 = tracker.wrap(
    targetAction,
    {op: 'action2Title'}
  )
  const action3 = tracker.wrap(
    targetAction,
    title => ({op: title})
  )
  const action4 = tracker.wrap(
    targetAction,
    title => ({op: title}),
    {
      showLog: true,
      showInfo: true,
      onHandleTrack: (trackData, {showInfo = false}) => {
        if (showInfo) console.info(trackData)
      }
    }
  )

// 已过时 请使用wrap方法
  const action5 = tracker.wrapper({op: 'action5Title'})(targetAction)
  const action6 = tracker.wrapper(title => ({op: title}))(targetAction)
  const action7 = tracker.wrapper(title => ({op: title}), {showLog: true})(targetAction)

  const action8 = () => {
    wx.navigateTo({
      url: 'info'
    })
  }

  const itemList = [
    {title: 'test1', action: action1},
    {title: 'test2', action: action2},
    {title: 'test3', action: action3},
    {title: 'test4', action: action4},
    {title: 'test5', action: action5},
    {title: 'test6', action: action6},
    {title: 'test7', action: action7},
    {title: 'testJumpInfoPage', action: action8},
    {title: 'testJumpWepyDemoPage', action: () => wx.navigateTo({url: 'wepydemo'})}
  ]

说明

扩展

微信小程序统计

默认注入公共参数
不需要再传了,其他参数见wiki

| 分类 | 名称 | 类型 | 描述 | 备注 | | --- | --- | --- | --- | --- | | | version | string | 日志版本号 | 1.0 | | | opTime | long | 事件触发时间点(毫秒) | | | | channel | int | scene | onLaunch => option.scene 场景值| | | platform | string | 平台,如ios、android、wx、mp? | 小程序是mp| | | actionType | string | 小程序值固定为: actionType: 'miniapp', | | | | latitude | double | scene | | | | longitude | double | scene | | | | visitId | string | 当前会话唯一随机字符串(session id) | | | | visitDv | string | 当前会话唯一随机字符串(session id) | | | | pageName | string | | | | | fromPath | string | | | | | shareSourceId | string | | | | | userSourceId | string | 点击别人分享进入小程序的那人用户id | | | | shareSourceId | string | 点击别人分享进入小程序的那条分享id | hash.default| | | selfTagSourceId | string | 点击别人分享进入小程序的那人的selfTag | hash.default| | | shareTo | int | | | | | msgChannel | string | | | | | authorizationV2 | string | | | | | selfTag | string | | |

extInfo

| 分类 | 名称 | 类型 | 描述 | 备注 | | --- | --- | --- | --- | --- | | | shareAction | int | [1(页面按钮), 2(右上角菜单)] | | | | id | string | 当前分享id | |

分享url参数注入

| 分类 | 名称 | 类型 | 描述 | 备注 | | --- | --- | --- | --- | --- | | | userSourceId | string | 当前用户id | 默认取 wx.getStorageSync('userId')| | | shareSourceId | string | 当前分享的id | hash.default| | | selfTagSourceId | string | 当前用户selfTag | hash.default|

注意

v0.6.5开始

  1. commonParams 里面不要放selfTag 库本身已经接管selfTag 若想获取可以调用tracker.getSelfTag()
  2. commonParams 里面不要放authorizationV2 库本身从account里面取了 如需自定义可以覆盖或者 config中加入getToken func

更新日志

v0.7.4

新增 tracker.onAppHide() 切到后台 视为 跳转到了 名字为 fakePageBackground 的新页面 用于精细化统计

v0.7.3

fix msgChannel没记上

v0.7.2

fix fromPage 丢失 bug版本[0.6.5 - 0.7.1]
commonControlArg中增加host参数可配 host: 'shuidichou.com'

v0.7.1

修改默认 log api 为 url: 'http://log.shuidichou.com/log'

v0.7.0

增加公共字段actionType: miniapp

v0.6.5

修改使用cryptoUserId 替换userId config 增加 accountKey字段 用于获取 account: {cryptoUserId}

  1. commonParams 里面不要放selfTag 库本身已经接管selfTag 若想获取可以调用tracker.getSelfTag() 或tracker.config.getSelfTag()
  2. commonParams 里面不要放authorizationV2 库本身从account里面取了sdToken 如需自定义可以覆盖或者 config中加入getToken func
  3. config中原有的 getUserId 可以删除 默认取的account 里面的 cryptoUserId

v0.6.4

onPageShow 增加一个参数 onPageShow({op: 'overrideOp', extInfo: {word: 'fakeWord'}}) 用于增加pageEnter统计数据

v0.6.3

分享时自动拼上selfTagSourceId,并统计点击分享进入的selfTagSourceId

v0.6.2

app.wpy => onLaunch 自动调用 tracker.track({op: 'start'})

v0.6.1

onShareAppMessage 增加第三个参数 trackOptions

v0.6.0

增加 api
onShareAppMessage
config 增加 getUserId

v0.5.1

rename tracker.wraper 2 tracker.wrapper

v0.5.0

修正readme

v0.4.3

增加shareSourceId, userSourceId, msgChannel, shareTo 字段 api 增加tracker.onAppLaunch, tracker.onAppShow, tracker.onPageShow, tracker.promoteShare

v0.4.2

修改readme格式

v0.4.1

同步部分readme注释

v0.4.0

增加onShow方法 用来统计页面 附带增加公共 参数 [pageName, fromPath, visitDv] 重写readme

v0.3.1

修复import error

v0.3.0

更新一波功能

v0.2.3

fix bug

Possible Unhandled Promise Rejection: TypeError: Cannot read property 'then' of undefined

v0.2.0

增加 commonControlArg 来自定义url

v0.1.9

更新track-core version 0.0.5

v0.1.8

修改body为数组

v0.1.7

补充opTime

v0.1.5

fix import err

v0.1.4

抽离track-core

v0.1.3

showLog 控制请求返回log是否显示