@aistarfish/event-web

0.1.5 • Public • Published

海心全平台埋点SDK-Web

介绍

越来越多的web项目需要加入打点需求,所以对web端的埋点进行抽离,封装成SDK供各项目使用。

安装

npm install @aistarfish/event-web / yarn add @aistarfish/event-web

使用

1.SDK提供了onEventonPageStartonPageEnd三个打点方法,分别用于事件打点、页面统计。

  /**
   * 事件打点
   * @param  eventId 事件id
   * @param  params 携带参数
   */
  onEvent(eventId = "", params = {}) 

  /**
   * 页面创建的时候调用onPageStart
   */
  onPageStart(eventId,params) 
  /**
   * 页面销毁的时候调用onPageEnd
   */
  onPageEnd(eventId)

页面统计是在页面创建销毁时调用,在页面的生命周期方法中直接调用。

扩展

1.事件统计的参数会默认携带eventDateuserAgent,不会携带userId

userId用做统计当前事件的UV。若不需要统计UV则跳过。 需要则将userId放入额外参数中。

2.为了避免线下测试产生脏数据,SDK中提供线下线上两个域名进行打点。

生产:https://gw.aistarfish.com/api/log/upload
测试:https://gateway-d9200.aistarfish.net/api/log/upload

SDK会根据当前访问的域名进行区分。

let api = "/api/log/upload";
  if (window.location.hostname.includes("aistarfish.net")) {
    api = "http://gateway-d9200.aistarfish.net/api/log/upload";
  } else if (window.location.hostname.includes("aistarfish.com")) {
    api = "https://gw.aistarfish.com/api/log/upload";
  }

3.SDK支持海心APP内部打点和外部浏览器打点,海心APP内部打点需要引入HxAppMethod.js

Readme

Keywords

none

Package Sidebar

Install

npm i @aistarfish/event-web

Weekly Downloads

9

Version

0.1.5

License

MIT

Unpacked Size

27.9 kB

Total Files

9

Last publish

Collaborators

  • lw_windy
  • doin0719
  • doin
  • yunque.wly
  • chujiu
  • stuartpounds
  • fantasy123
  • wangqi_sl
  • liuhao1
  • yiyun220