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

@qiov/tgp-mp-sdk

v4.0.8

Published

Mini program sdk for TGP(Tencent Growth Platform).

Downloads

16

Readme

1. SDK 初始化

引入 SDk 后,需初始化 SDK

在应用的入口app.js引入SDK,添加代码:


import BeaconAction from '@qiov/tgp-mp-sdk/beacon_mp.min.js'

var success = e => {
  console.log('onReportSuccess : ' + e);
};
var fail = e => {
  console.log('onReportFail : ' + e);
};
var beacon = new BeaconAction({
  appkey: 'appkey', //小程序appKey,从灯塔官网获取,必填
  reportUrl: 'https://xxx', // 上报url, 必填
  versionCode: 'versionCode', //小程序版本号,选填
  channelID: 'channelID', //小程序渠道号,选填
  openid: 'openid', // 用户标示符号,选填
  unionid: 'unionid', // 用户唯一标示符号,选填
  isDebug :false ,//是否测试环境,选填
  strictMode: true,//严苛模式开关, 打开严苛模式会主动抛出异常, 上线请务必关闭!!选填
  delay: 2000, // 普通事件延迟上报时间(单位毫秒), 默认2000(2秒),选填
  onPullDownRefresh: true,//下拉刷新事件统计,默认开启,选填
  onReachBottom: true,//页面下拉触底统计,默认开启,选填
  onReportSuccess: success, // 上报成功回调,选填
  onReportFail: fail, // 上报失败回调,选填
  oneidApi: 'http://yyy', // oneid生成地址,选填
});

2.API

2.1设置appkey

beacon.setAppKey('setAppKey');

2.2普通事件上报接口,小程序环境问题,性能较低,注意!!!! value 类型只能是string 或者 number 类型

beacon.onUserAction('eventCode', {
  'city': 'shenzhen'
});

2.3 实时事件上报接口,注意!!!! value 类型只能是string 或者 number 类型

beacon.onDirectUserAction('eventCode', {
  'city': 'shenzhen'
});

2.4 获取小程序beacon id

beacon.getDeviceId();

2.5 设置公共参数, 注意 !!!! , 相比老接口(setAdditionalParams)新接口是追加,老接口为替换

beacon.addAdditionalParams({
  'additionalParams': 'params'
});

2.6 手动上报PV

beacon.reportPV();

2.7 设置用户id

beacon.setOpenId('openid');

2.8 设置唯一id

beacon.setUnionid('setUnionid');

2.9 设置渠道id

beacon.setChannelId('setChannelId');

2.10 设置用户信息

// 获取用户信息
wx.getSetting({
  success: res => {
    if (res.authSetting['scope.userInfo']) {
      // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
      wx.getUserInfo({
        success: res => {
          beacon.setUserInfo(res);//灯塔会获取用户昵称
        }
      })
    }
  }
})

2.11 设置位置信息

wx.getLocation({
  type: "wgs84",
  success: function (res) {
    beacon.setLocation(res);
  }
})

2.12 用于小程序 与 H5 打通时,返回 H5 事件上报需携带的小程序预置属性,注意 !!!,这里以拼接字符串的方式给出

wx.getWeappInfo() // 返回'beacon_uin=${uin}&beacon_uid=${uid}&beacon_is_first=${isFirst}'

3 小程序 与 H5 打通

3.1 方案概述

小程序与 H5 的数据打通,是小程序将必要预置属性(这里支持用户标识、用户ID和是否为新用户) 通过 URL 方式传递给 H5 端,H5 端解析URL替换对应事件属性,达到统一用户标识和其他必要属性的目的。

3.2 方案实现

1、调用 wx.setWebViewUrl(URL), 拼接好包含 distinctID 的 URL,微信小程序 V1.14.12 及以上版本支持; 2、URL 参数是绑定的 web-view 的 src 属性值

// webview.js
Page({
  data: {
    webUrl: ''
   },
  onLoad: function (options) {
    const URL = 'https://example/demo.html' 必填项
    this.setData({
      webUrl: beacon.setWebViewUrl(URL)
    });
  }
});
// webview.wxml
<web-view src="{{ webUrl }}"></web-view>