Commit 7cf9845a by 杨明

属性

1 parent dd741db0
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: yangming yangming@didihu.com.cn * @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-24 17:29:53 * @Date: 2023-11-24 17:29:53
* @LastEditors: yangming yangming@didihu.com.cn * @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-12-14 17:55:38 * @LastEditTime: 2023-12-15 16:51:23
* @FilePath: \rollup_demo\public\index.html * @FilePath: \rollup_demo\public\index.html
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
--> -->
...@@ -91,16 +91,6 @@ router.beforeEach(function (to, from, next) { ...@@ -91,16 +91,6 @@ router.beforeEach(function (to, from, next) {
const app = new Vue({ const app = new Vue({
router, router,
}).$mount("#app"); }).$mount("#app");
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("get", "https://www.czhuihao.cn/ip/", false);
xmlhttp.send();
var item = JSON.parse(xmlhttp.responseText);
console.log(item)
</script> </script>
</body> </body>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: yangming yangming@didihu.com.cn * @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-24 17:28:02 * @Date: 2023-11-24 17:28:02
* @LastEditors: yangming yangming@didihu.com.cn * @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-12-14 10:30:33 * @LastEditTime: 2023-12-15 16:49:04
* @FilePath: \rollup_demo\src\main.ts * @FilePath: \rollup_demo\src\main.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
...@@ -12,6 +12,7 @@ import type { BaseOptions, trackType } from './types/main' ...@@ -12,6 +12,7 @@ import type { BaseOptions, trackType } from './types/main'
import stayEvent from './modules/stayEvent' import stayEvent from './modules/stayEvent'
import clickEvent from './modules/clickEvent' import clickEvent from './modules/clickEvent'
import viewEvent from './modules/viewEvent' import viewEvent from './modules/viewEvent'
import user from './modules/user'
const request = new Request('https://www.xxx.com', 'ajax') const request = new Request('https://www.xxx.com', 'ajax')
class Tracker { class Tracker {
SDK: BaseOptions SDK: BaseOptions
...@@ -72,14 +73,14 @@ class Tracker { ...@@ -72,14 +73,14 @@ class Tracker {
/** /**
* 用户登录绑定唯一标识 * 用户登录绑定唯一标识
*/ */
login() {} login(id: string) {
/** user.setLoginId(id)
* 自定义上报事件 }
*/
setEvent() {}
/** /**
* 直接设置用户的属性,如果存在则覆盖。 * 直接设置用户的属性,如果存在则覆盖。
*/ */
setAttribute() {} setAttribute(obj: object) {
user.setUser(obj)
}
} }
export default Tracker export default Tracker
...@@ -2,40 +2,20 @@ ...@@ -2,40 +2,20 @@
* @Author: yangming yangming@didihu.com.cn * @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-28 17:05:34 * @Date: 2023-11-28 17:05:34
* @LastEditors: yangming yangming@didihu.com.cn * @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-12-15 09:35:50 * @LastEditTime: 2023-12-15 16:36:17
* @FilePath: \glsx-tracker-javascript\src\modules\collect.ts * @FilePath: \glsx-tracker-javascript\src\modules\collect.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
import type { DefaultInfoDescriptor, EventType ,DeviceInfoDescriptor} from '../types/collect' import type { DefaultInfoDescriptor, EventType, ReportInfoDescriptor } from '../types/collect'
import utils from '../utils/helper' import utils from '../utils/helper'
import user from './user'
class Collect { class Collect {
/** /**
*
* 开始收集
* @param target 目标
* @param tagName 标签
* @param customProps 属性
* @param callback 回调函数
*/
start() {}
/**
* 采集用户信息数据 * 采集用户信息数据
* @param info 接收的数据 * @param info 接收的数据
*/ */
getUserData() {} getUserData() {}
/** /**
* 采集设备信息数据
* @param info 接收的数据
*/
getDeviceData():DeviceInfoDescriptor {
return {
$plateform: navigator.platform,
$appName: navigator.appName,
$userAgent: navigator.userAgent,
$appVersion: navigator.appVersion
}
}
/**
* 采集默认信息数据 * 采集默认信息数据
* @param info 接收的数据 * @param info 接收的数据
*/ */
...@@ -65,15 +45,19 @@ class Collect { ...@@ -65,15 +45,19 @@ class Collect {
getStayEvent<T extends object>(para: T) { getStayEvent<T extends object>(para: T) {
this.send(para, 'stayEvent') this.send(para, 'stayEvent')
} }
/** /**
* 发送埋点数据 * 发送埋点数据
*/ */
send<T>(para: T, type: EventType) { send<T>(para: T, type: EventType) {
para = Object.assign(this.getDefaultData(), para) const reportInfo: ReportInfoDescriptor = {
const reportInfo = { properties: Object.assign(this.getDefaultData(), para),
properties: para, eventName: type,
event: type, anonymous_id: '888',
time: utils.dateFormat(Date.now()) send_time: utils.dateFormat(Date.now())
}
if (user.user_login_id) {
reportInfo.user_login_id = user.user_login_id
} }
console.log(reportInfo) console.log(reportInfo)
} }
......
...@@ -2,19 +2,24 @@ ...@@ -2,19 +2,24 @@
* @Author: yangming yangming@didihu.com.cn * @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-30 14:46:13 * @Date: 2023-11-30 14:46:13
* @LastEditors: yangming yangming@didihu.com.cn * @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-12-14 16:04:28 * @LastEditTime: 2023-12-15 16:49:25
* @FilePath: \glsx-tracker-javascript\src\modules\stayEvent.ts * @FilePath: \glsx-tracker-javascript\src\modules\stayEvent.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
console.log(222)
import type { StayDescriptor } from '../types/stay' import type { StayDescriptor } from '../types/stay'
import collect from './collect' import collect from './collect'
import Events from './events' import Events from './events'
class StayEvent { class StayEvent {
static instance: StayEvent | undefined
_options: any _options: any
start_time: number = Date.now() start_time: number = Date.now()
timeout_time: number = 1000 timeout_time: number = 1000
timer: NodeJS.Timeout | undefined timer: NodeJS.Timeout | undefined
interval_time: number = 5000 interval_time: number = 5000
constructor() {
console.log(1111111)
}
/** /**
* 获取视口位置 * 获取视口位置
*/ */
...@@ -48,16 +53,16 @@ class StayEvent { ...@@ -48,16 +53,16 @@ class StayEvent {
* params * params
*/ */
trigger(this: StayEvent) { trigger(this: StayEvent) {
Events.addEvent(window, 'scroll', (e: MouseEvent)=>{ Events.addEvent(window, 'scroll', (e: MouseEvent) => {
if (this._options.collect_url && !this._options.collect_url()) { if (this._options.collect_url && !this._options.collect_url()) {
return false return false
} }
if(Date.now() - this.start_time<this._options.delay_time) { if (Date.now() - this.start_time < this._options.delay_time) {
return false return false
} }
if (!this.timer) { if (!this.timer) {
const para = this.getStayInfo() const para = this.getStayInfo()
this.timer = setTimeout(()=> { this.timer = setTimeout(() => {
this.send(para) this.send(para)
}, this.timeout_time) }, this.timeout_time)
} }
...@@ -66,18 +71,27 @@ class StayEvent { ...@@ -66,18 +71,27 @@ class StayEvent {
/** /**
* 发送数据 * 发送数据
*/ */
send(para:object) { send(para: object) {
this.timer = undefined this.timer = undefined
this.start_time = Date.now() this.start_time = Date.now()
collect.getStayEvent(para) collect.getStayEvent(para)
} }
/** /**
* 初始化 * 初始化
* params * params data初始化数据
*/ */
init<T>(data: T) { init<T>(data: T) {
this._options = data this._options = data
this.trigger() this.trigger()
} }
/**
* 单例模式
*/
static getInstance() {
if (!StayEvent.instance) {
StayEvent.instance = new StayEvent()
}
return StayEvent.instance
}
} }
export default new StayEvent() export default new StayEvent()
/*
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-12-15 15:49:29
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-12-15 16:35:43
* @FilePath: \glsx-tracker-javascript\src\modules\attribute.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { SDK_version } from '../utils/constants'
import { DeviceInfoDescriptor } from '../types/user'
class User {
/**
* 设置用户登录注册id
*/
user_login_id?: string
userInfo?:object
setLoginId(id: string) {
this.user_login_id = id
}
/**
* 设置用户信息
*/
setUser(obj:object) {
this.userInfo = obj
}
/**
* 采集设备信息数据
* @param info 接收的数据
*/
getDeviceData(): DeviceInfoDescriptor {
return {
SDK_version,
$plateform: navigator.platform,
$appName: navigator.appName,
$userAgent: navigator.userAgent,
$appVersion: navigator.appVersion
}
}
}
export default new User()
...@@ -11,10 +11,10 @@ export interface DefaultInfoDescriptor { ...@@ -11,10 +11,10 @@ export interface DefaultInfoDescriptor {
$page_url: string | undefined $page_url: string | undefined
$page_path: string | undefined $page_path: string | undefined
} }
export interface DeviceInfoDescriptor { export interface ReportInfoDescriptor {
$plateform: string properties: any
$appName: string eventName: EventType
$userAgent: string anonymous_id: string
$appVersion: string send_time: string
[prop: string]: string user_login_id?: string
} }
...@@ -4,7 +4,7 @@ import { routerOption } from './view' ...@@ -4,7 +4,7 @@ import { routerOption } from './view'
* @Author: yangming yangming@didihu.com.cn * @Author: yangming yangming@didihu.com.cn
* @Date: 2023-12-12 14:35:34 * @Date: 2023-12-12 14:35:34
* @LastEditors: yangming yangming@didihu.com.cn * @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-12-15 09:21:40 * @LastEditTime: 2023-12-15 14:41:18
* @FilePath: \glsx-tracker-javascript\src\types\main.ts * @FilePath: \glsx-tracker-javascript\src\types\main.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
...@@ -18,8 +18,8 @@ export type ScrollOption = { ...@@ -18,8 +18,8 @@ export type ScrollOption = {
delay_time: number delay_time: number
} }
export type optonsDescriptor = { export type optonsDescriptor = {
SDK_version: string
server_url: string server_url: string
user_login_id: string
router_type: routerOption router_type: routerOption
track_type: trackType track_type: trackType
max_events_length: number max_events_length: number
......
export interface DeviceInfoDescriptor {
$plateform: string
$appName: string
$userAgent: string
$appVersion: string
[prop: string]: string
}
export const TAG_PROP_NAME = 'data-gl-tracker'
\ No newline at end of file \ No newline at end of file
/*
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-12-13 14:03:18
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-12-15 13:37:11
* @FilePath: \glsx-tracker-javascript\src\utils\constants.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
export const TAG_PROP_NAME = 'data-gl-tracker'
export const SDK_version = 'v1.0.0'
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: yangming yangming@didihu.com.cn * @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-28 14:20:48 * @Date: 2023-11-28 14:20:48
* @LastEditors: yangming yangming@didihu.com.cn * @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-12-11 09:55:03 * @LastEditTime: 2023-12-15 13:54:33
* @FilePath: \glsx-tracker-javascript\src\utils\helper.ts * @FilePath: \glsx-tracker-javascript\src\utils\helper.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
...@@ -51,5 +51,12 @@ export default { ...@@ -51,5 +51,12 @@ export default {
to[key] = _from[key] to[key] = _from[key]
} }
return to return to
},
UUID(): string {
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/x/g, function (c) {
var r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8
return v.toString(16)
})
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!