1.0.7 • Published 3 years ago

site-gather v1.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

site-gather

站点数据采集

Install

$ yarn add site-gather

$ npm install site-gather

引入 SDK

const gather = require('site-gather');
import gather from 'site-gather';

配置初始化参数

gather.setOption(Option);

Option setOption方法参数

字段类型是否比填默认值说明
appnameStringNull项目名称
appidStringNull项目 ID
appkeyStringNull项目密钥
server_urlString-数据上报地址
trackString"/app/event"事件上报路径
appopenString"/app/open"app 响应上报路径
appcloseString"/app/close"app 关闭上报路径
pageopenString"/app/page/open"页面响应上报路径
pagecloseString"/app/page/close"页面关闭上报路径

配置用户信息

/*
  * @param {String} UserId 用户ID
  */
gather.setUserId(UserId);

未设置 UserId 时,监测程序则不会执行

配置全局事件公共参数 非必须

/*
  * @param {Object} Option 公共参数
  */
gather.setProfile(Option);

track 执行埋点

gather.track(EventName, EventData);
// todo
gather.track(EventName, EventData, function() {
  // todo
});
async function() {
  await gather.track(EventName, EventData);
  // todo
}

如需同步执行(事件埋点执行完后在执行其它逻辑)可使用 CallBack 或者 async/await 两种方式

字段类型是否比填默认值说明
EventNameString-事件名称
EventDataObjectNull事件参数

小程序配置

在 app.json 配置全局组件

{
  ...
  usingComponents: {
    "gather": "site-gather/gather"
  }
}

数据采集

在需要数据采集的页面中配置

html 标签模式

<view>
  <gather/>
</view>

javascript 自行配置 (推荐 html 模式)

const gather = require('site-gather');

Page({
  onLoad() {
    gather.pageOpen(); // 页面打开
  },
  // 可通过停留监测来计算页面销毁时间
  onUnload () {
    gather.pageClose(); // 页面销毁
  }
})

监听 App 打开

gather.appOpen()

监听 App 退出

gather.appClose();
1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago