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

dndc-ttmp-analytics

v1.0.4

Published

微信小程序用户数据统计工具

Downloads

7

Readme

[TOC]

安装

$ npm install [email protected] -D

配置文件

# 域名配置
development_host:
  trackENV: dev
production_host:
  trackENV: prod

初始化

dndc-wxmp-analytics 需在 App 的 onLaunch 生命周期执行前配置初始化参数:

/** app.js */
import Statistics from 'dndc-wxmp-analytics';

const dndcAnalytics = new Statistics({
  site_code: '', // 咨询数据组
  app_id: '',
  app_name: '小程序',
  track_ali_env: mc.$hosts.trackENV,
  event_code_url: '', //page平台生成-直接使用page生产地址
  show_log: false,
  black_pv_list: [],
})

App({
  /** 为了方便后续页面的行为采集,请将 Statistics 的实例赋值给 App 的属性 */
  sa: dndcAnalytics,
});

参数列表

| 参数 | 类型 | 必填 | 默认值 | 说明 | | -------------- | ------- | ---- | ------ | ------------------------------------------------------- | | site_code | string | 是 | - | 站点编码(咨询数据组获取) | app_id | string | 是 | - | appid | | app_name | string | 是 | - | 小程序名称 | | event_code_url | string | 是 | - | 事件码JSON | | black_pv_list | Array | 否 | - | 收集页面浏览事件的路径黑名单 | | show_log | boolean | 否 | False | 设置为 true 时,会在控制台打印 log 信息(用于开发模式) | | send_timeout | number | 否 | 60000 | 数据上报接口超时时间,单位为毫秒 | | source_channel | Array | 否 w | [] | 需要解析的渠道参数名称 | | track_ali_env | dev | prod | 否 | prod | 日志接口环境 |

点击事件采集

静态事件码

/** page.js */
const app = getApp();

Page({
  onClick() {
    app.sa.track({ hit_type: 'click', event_id: 'chebaba-app-20210105164547-1di0' });
  },
});

动态事件码

/** page.js */
const app = getApp();

Page({
  onClick() {
    app.sa.track({
      hit_type: 'click',
      event_id: 'chebaba-web-20210308084439-l9so-{carseries_id}-{cartype_id}',
      event_info: {
        dynamic: {
          carseries_id: 17,
          cartype_id: 279244,
        },
      },
    });
  },
});

target字段

特殊情况只能使用id并需要知道具体的名称可以使用target字段 用target字段必须要有动态参数id

id可以传具体有意义的值、如商品ID、活动ID、广告ID,没有实际ID情况可以用序号

/** page.js */
const app = getApp();

Page({
  onClick() {
    app.sa.track({
      hit_type: 'click',
      event_id: 'chebaba-web-20210308084439-l9so-{id}',
      event_info: {
        dynamic: {
          id: 11,
          target: '海蓝色'
        },
      },
    });
  },
});

如下图,如果数据组要求只有{序号}不需要具体名称,target可以不传。 非序号情况,都需要传target字段 image.png

令牌获取(特征编码)

根据数据组要求特殊场景需要获取令牌后传给接口存储到业务表

const app = getApp();

Page({
  onClick() {
    const resFeatureID = app.sa.track({
      hit_type: 'feature'
    });
    console.log('resFeatureID', resFeatureID)
  },
});

特殊业务场景追加参数使用feature_extra

Page({
  onClick() {
    const resFeatureID = app.sa.track({
      hit_type: 'feature',
      feature_extra: {
        custom: 'test',
      }
    });
    console.log('resFeatureID', resFeatureID)
  },
});

页面标题

在Page中配置saTitle

Page({
  saTitle: '页面标题',
  onShow() {
  // 页面代码
  }
})

在Component中配置saTitle(没有Page的情况)

Component({
  data: {
    saTitle: '页面标题',
  },
  methods: {},
});

设置用户openid

const app = getApp();
app.sa.setOpenId('');

设置用户unionid

const app = getApp();
app.sa.setUnionId('');

设置用户信息

const app = getApp();
tt.getUserInfo({
  success: res => {
    app.sa.setUser(res.userInfo)
  }
})

设置is_oneid (pz1a联友ID)

const app = getApp();
app.sa.setIsOneId('');

手动发送pageView事件

当同一个Page通过URL参数或者状态控制不同模块的展示,需要关闭当前页面pavaView自动触发,调整为手动触发

// app.js文件 埋点初始化配置关闭自动触发pageView
black_pv_list: ['pages/index/index']

// 手动触发pageView
app.sa.pageView({
  title: '首页-车系',
  pageid: 'pages/index/index'
})

查看black_pv_list是否有效

配置pages/index/index,搜索ali刷新页面没有pageview事件触发即可 image.png

查看手动发送pageView事件是否有效

调用app.sa.pageView方法,搜索ali参数pagetitlepageid与发送的参数一致即可 image.png

初始化样例

/** app.js */
import Statistics from 'dndc-wxmp-analytics';

const dndcAnalytics = new Statistics({
  track_ali_env: mc.$hosts.track,
  event_code_url: '', //page平台生成-直接使用page生产地址
  show_log: false,
  site_code: '', // 咨询数据组
  app_id: '',
  app_name: '小程序',
  black_pv_list: [], // 收集页面浏览事件的路径黑名单
})

// 初始化神策通码
dndcAnalytics.loadSensorsData({
  server_url: '', // 数据接收地址 - 咨询数据组获取,
});

App({
  sa: dndcAnalytics,
  onLaunch(options) {},
});

采集字段

| 字段 | 字段说明 |来源方式| | ---------- | ----------------------- |-----| | site_code | 主站编码 |事件公共属性| | site_channel | 渠道 |事件公共属性| | openid | 微信小程序用户 openid |事件公共属性| | unionid | 微信小程序用户 unionid |事件公共属性| | unionid | 微信小程序用户 unionid |事件公共属性| | is_oneid | 联友oneid |事件公共属性| | app_id | 微信小程序 app_id |事件公共属性| | app_name | 微信小程序名称 |事件公共属性| | scene | 场景值 |自动读取| | path | 页面路径 |自动获取| | pagetitle | 页面标题 |-| | referrer | 来源页面 |自动读取| | pageid | 页面源信息 |-| | event_id | 事件编码 |-| | event_info | 事件扩展信息 |-| | event_name | 事件名称 |自动读取| | hit_type | 类型(pageview|event) |-| | smartcode | 推广入口 |自动读取|事件公共属性| | sourcecode | 内部入口 |自动读取|事件公共属性| | brand | 设备品牌 |tt.getSystemInfoSync()自动获取| | model | 设备型号 |tt.getSystemInfoSync()自动获取| | platform | 客户端平台 |tt.getSystemInfoSync()自动获取| | sr | 屏幕宽高 |tt.getSystemInfoSync()自动获取| | system | 操作系统及版本 |tt.getSystemInfoSync()自动获取| | version | 微信版本号 |tt.getSystemInfoSync()自动获取| | client_id | 客户端ID |自动读取|