main.ts 1.94 KB
/*
 * @Author: yangming yangming@didihu.com.cn
 * @Date: 2023-11-24 17:28:02
 * @LastEditors: yangming yangming@didihu.com.cn
 * @LastEditTime: 2023-12-13 17:37:25
 * @FilePath: \rollup_demo\src\main.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import Request from './modules/request'
import type { BaseOptions, trackType } from './types/main'
import stayEvent from './modules/stayEvent'
import clickEvent from './modules/clickEvent'
import viewEvent from './modules/viewEvent'
const request = new Request('https://www.xxx.com', 'ajax')
class Tracker {
  SDK: BaseOptions
  constructor(options: BaseOptions) {
    this.SDK = Object.assign(this.initOptions(), options)
    this.init()
  }
  /**
   * 默认配置
   */
  initOptions(): BaseOptions {
    return {
      track_type: 'image',
      router_type:'hash',
      clickview: {
        open_all_click: false,
        collect_doms: ['p']
      },
      scrollview: {
        collect_url: function () {
          return true
        },
        scroll_switch: true,
        delay_time: 4000
      }
    }
  }
  /**
   * 初始化数据
   */
  init() {
    stayEvent.init(this.SDK.scrollview)
    clickEvent.init(this.SDK.clickview)
    viewEvent.init(this.SDK.router_type)
  }
  /**
   * 代码埋点触发元素点击事件
   */
  track(target: HTMLElement, prop: any, callback: Function) {
    clickEvent.activeTrigger.call(clickEvent, target, prop, callback)
  }
  /**
   * 设置上报公共属性
   */
  setCommonAttribute() {}
  /**
   *更换上报方式发数据
   */
  setSendType<T extends trackType>(type: T) {
    this.SDK.track_type = type
  }
  /**
   * 用户登录绑定唯一标识
   */
  login() {}
  /**
   * 自定义上报事件
   */
  setEvent() {}
  /**
   * 直接设置用户的属性,如果存在则覆盖。
   */
  setAttribute() {}
}
export default Tracker