Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
npm
/
glsx-tracker-javascript
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit dd741db0
authored
Dec 15, 2023
by
杨明
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
浏览事件
1 parent
a2f1a855
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
191 additions
and
62 deletions
public/index.html
src/main.ts
src/modules/clickEvent.ts
src/modules/collect.ts
src/modules/events.ts
src/modules/stayEvent.ts
src/modules/viewEvent.ts
src/types/collect.d.ts
src/types/main.ts
src/types/view.d.ts
public/index.html
View file @
dd741db
...
@@ -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-1
3 17:53:43
* @LastEditTime: 2023-12-1
4 17:55:38
* @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
-->
-->
...
@@ -25,20 +25,83 @@
...
@@ -25,20 +25,83 @@
<div>
<div>
<button
class=
"class"
name=
"name"
id=
"id"
>
111
</button>
<button
class=
"class"
name=
"name"
id=
"id"
>
111
</button>
</div>
</div>
<script
src=
"../dist/glsx-tracker-javascript.umd.js"
></script>
<div
id=
"app"
>
<script>
<h1>
Hello App!
</h1>
const
tracker
=
new
Tracker
()
<p>
document
.
querySelector
(
'.test'
).
addEventListener
(
'click'
,
function
(
e
)
{
<!-- use router-link component for navigation. -->
tracker
.
track
(
<!-- specify the link by passing the `to` prop. -->
this
,
<!-- `<router-link>` will be rendered as an `<a>` tag by default -->
{
<router-link
to=
"/foo"
>
Go to Foo
</router-link>
aaa
:
999
<router-link
to=
"/bar"
>
Go to Bar
</router-link>
},
<button>
点击
</button>
function
()
{
<div
class=
"aaa"
><div
id=
"testp"
>
44
</div></div>
console
.
log
(
't'
)
</p>
}
<!-- route outlet -->
)
<!-- component matched by the route will render here -->
})
<router-view></router-view>
</script>
</div>
<script
src=
"https://cdn.jsdelivr.net/npm/vue@2.7.14"
></script>
<script
src=
"https://cdn.bootcdn.net/ajax/libs/vue-router/3.1.0/vue-router.min.js"
></script>
<script
src=
"../dist/glsx-tracker-javascript.umd.js"
></script>
<script>
console
.
log
(
8888
)
const
tracker
=
new
Tracker
()
document
.
querySelector
(
'.test'
).
addEventListener
(
'click'
,
function
(
e
)
{
tracker
.
track
(
this
,
{
aaa
:
999
},
function
()
{
console
.
log
(
't'
)
}
)
})
</script>
<script>
const
Foo
=
{
template
:
"<div>foo</div>"
};
const
Bar
=
{
template
:
"<div>bar</div>"
};
// 2. Define some routes
// Each route should map to a component. The "component" can
// either be an actual component constructor created via
// `Vue.extend()`, or just a component options object.
// We'll talk about nested routes later.
const
routes
=
[
{
path
:
"/foo"
,
component
:
Foo
},
{
path
:
"/bar"
,
component
:
Bar
},
];
// 3. Create the router instance and pass the `routes` option
// You can pass in additional options here, but let's
// keep it simple for now.
const
router
=
new
VueRouter
({
routes
,
// short for `routes: routes`
});
router
.
beforeEach
(
function
(
to
,
from
,
next
)
{
//console.log('url1:', document.URL);
setTimeout
(
function
()
{
//console.log('url2:', document.URL);
// tracker.autoTriggerView({
// aa:11
// })
next
();
},
0
);
});
const
app
=
new
Vue
({
router
,
}).
$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>
</body>
</body>
</html>
</html>
src/main.ts
View file @
dd741db
...
@@ -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-1
3 17:37:25
* @LastEditTime: 2023-12-1
4 10:30:33
* @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
*/
*/
...
@@ -15,6 +15,9 @@ import viewEvent from './modules/viewEvent'
...
@@ -15,6 +15,9 @@ import viewEvent from './modules/viewEvent'
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
/**
* SDK配置
*/
constructor
(
options
:
BaseOptions
)
{
constructor
(
options
:
BaseOptions
)
{
this
.
SDK
=
Object
.
assign
(
this
.
initOptions
(),
options
)
this
.
SDK
=
Object
.
assign
(
this
.
initOptions
(),
options
)
this
.
init
()
this
.
init
()
...
@@ -25,7 +28,7 @@ class Tracker {
...
@@ -25,7 +28,7 @@ class Tracker {
initOptions
():
BaseOptions
{
initOptions
():
BaseOptions
{
return
{
return
{
track_type
:
'image'
,
track_type
:
'image'
,
router_type
:
'hash'
,
router_type
:
'hash'
,
clickview
:
{
clickview
:
{
open_all_click
:
false
,
open_all_click
:
false
,
collect_doms
:
[
'p'
]
collect_doms
:
[
'p'
]
...
@@ -53,6 +56,9 @@ class Tracker {
...
@@ -53,6 +56,9 @@ class Tracker {
track
(
target
:
HTMLElement
,
prop
:
any
,
callback
:
Function
)
{
track
(
target
:
HTMLElement
,
prop
:
any
,
callback
:
Function
)
{
clickEvent
.
activeTrigger
.
call
(
clickEvent
,
target
,
prop
,
callback
)
clickEvent
.
activeTrigger
.
call
(
clickEvent
,
target
,
prop
,
callback
)
}
}
autoTriggerView
(
prop
:
any
)
{
viewEvent
.
trigger
.
call
(
viewEvent
,
prop
)
}
/**
/**
* 设置上报公共属性
* 设置上报公共属性
*/
*/
...
...
src/modules/clickEvent.ts
View file @
dd741db
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* @Author: yangming yangming@didihu.com.cn
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-30 14:10:56
* @Date: 2023-11-30 14:10:56
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-12-1
3 15:23:4
2
* @LastEditTime: 2023-12-1
4 17:38:1
2
* @FilePath: \glsx-tracker-javascript\src\modules\clickEvent.ts
* @FilePath: \glsx-tracker-javascript\src\modules\clickEvent.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AEupo
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AEupo
*/
*/
...
@@ -11,6 +11,7 @@ import utils from '../utils/helper'
...
@@ -11,6 +11,7 @@ import utils from '../utils/helper'
const
TAGS
=
[
'a'
,
'input'
,
'textarea'
,
'button'
]
const
TAGS
=
[
'a'
,
'input'
,
'textarea'
,
'button'
]
import
type
{
ClickDescriptor
,
ElDescriptor
,
ClickParmasDescriptor
}
from
'../types/click'
import
type
{
ClickDescriptor
,
ElDescriptor
,
ClickParmasDescriptor
}
from
'../types/click'
import
{
TAG_PROP_NAME
}
from
'../utils/constants'
import
{
TAG_PROP_NAME
}
from
'../utils/constants'
import
collect
from
'./collect'
class
clickEvent
{
class
clickEvent
{
_options
:
any
_options
:
any
/**
/**
...
@@ -131,11 +132,11 @@ class clickEvent {
...
@@ -131,11 +132,11 @@ class clickEvent {
init
<
T
>
(
this
:
clickEvent
,
data
:
T
)
{
init
<
T
>
(
this
:
clickEvent
,
data
:
T
)
{
this
.
_options
=
data
this
.
_options
=
data
if
(
this
.
_options
.
open_all_click
)
{
if
(
this
.
_options
.
open_all_click
)
{
Events
.
addEvent
(
document
.
documentElement
,
'click'
,
(
e
:
MouseEvent
)
=>
{
Events
.
addEvent
(
document
.
documentElement
,
'click'
,
(
e
:
MouseEvent
)
=>
{
console
.
log
(
this
.
getEleDetail
(
e
.
target
as
HTMLElement
))
console
.
log
(
this
.
getEleDetail
(
e
.
target
as
HTMLElement
))
})
})
}
else
{
}
else
{
Events
.
addEvent
(
document
.
documentElement
,
'click'
,
(
e
?:
MouseEvent
)
=>
{
Events
.
addEvent
(
document
.
documentElement
,
'click'
,
(
e
?:
MouseEvent
)
=>
{
console
.
log
(
e
)
console
.
log
(
e
)
if
(
!
e
)
{
if
(
!
e
)
{
return
false
return
false
...
@@ -149,11 +150,11 @@ class clickEvent {
...
@@ -149,11 +150,11 @@ class clickEvent {
}
}
}
}
start
({
event
,
target
,
tagName
,
customProps
,
callback
}:
ClickParmasDescriptor
)
{
start
({
event
,
target
,
tagName
,
customProps
,
callback
}:
ClickParmasDescriptor
)
{
if
(
typeof
callback
==
'function'
)
{
if
(
typeof
callback
==
'function'
)
{
callback
.
call
(
null
)
callback
.
call
(
null
)
}
}
let
para
=
this
.
getBasicEleInfo
({
event
,
target
,
tagName
,
customProps
})
let
para
=
this
.
getBasicEleInfo
({
event
,
target
,
tagName
,
customProps
})
co
nsole
.
log
(
para
)
co
llect
.
getClickEvent
(
para
.
props
)
}
}
}
}
export
default
new
clickEvent
()
export
default
new
clickEvent
()
src/modules/collect.ts
View file @
dd741db
...
@@ -2,11 +2,12 @@
...
@@ -2,11 +2,12 @@
* @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-1
3 10:35:54
* @LastEditTime: 2023-12-1
5 09:35:50
* @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
}
from
'../types/collect'
import
type
{
DefaultInfoDescriptor
,
EventType
,
DeviceInfoDescriptor
}
from
'../types/collect'
import
utils
from
'../utils/helper'
class
Collect
{
class
Collect
{
/**
/**
*
*
...
@@ -23,10 +24,21 @@ class Collect {
...
@@ -23,10 +24,21 @@ class Collect {
*/
*/
getUserData
()
{}
getUserData
()
{}
/**
/**
* 采集公共信息数据
* 采集设备信息数据
* @param info 接收的数据
*/
getDeviceData
():
DeviceInfoDescriptor
{
return
{
$plateform
:
navigator
.
platform
,
$appName
:
navigator
.
appName
,
$userAgent
:
navigator
.
userAgent
,
$appVersion
:
navigator
.
appVersion
}
}
/**
* 采集默认信息数据
* @param info 接收的数据
* @param info 接收的数据
*/
*/
getCommonData
()
{}
getDefaultData
():
DefaultInfoDescriptor
{
getDefaultData
():
DefaultInfoDescriptor
{
return
{
return
{
$page_title
:
document
.
title
,
$page_title
:
document
.
title
,
...
@@ -38,26 +50,32 @@ class Collect {
...
@@ -38,26 +50,32 @@ class Collect {
* 收集点击事件数据
* 收集点击事件数据
* 判断需要监听哪些dom元素
* 判断需要监听哪些dom元素
*/
*/
getClickEvent
()
{}
getClickEvent
<
T
extends
object
>
(
para
:
T
)
{
this
.
send
(
para
,
'clickEvent'
)
}
/**
/**
* 收集浏览事件数据
* 收集浏览事件数据
*/
*/
getViewEvent
()
{}
getViewEvent
<
T
extends
object
>
(
para
:
T
)
{
this
.
send
(
para
,
'viewEvent'
)
}
/**
/**
* 收集停留事件数据
* 收集停留事件数据
*/
*/
getStayEvent
<
T
extends
object
>
(
para
:
T
)
{
getStayEvent
<
T
extends
object
>
(
para
:
T
)
{
this
.
send
(
Object
.
assign
(
this
.
getDefaultData
(),
para
),
'stayEvent'
)
this
.
send
(
para
,
'stayEvent'
)
}
send
<
T
>
(
para
:
T
,
type
:
EventType
)
{
console
.
log
(
para
,
type
)
}
}
/**
/**
* 自定义事件收集数据
* 发送埋点数据
* @param target 目标元素
* @param props 属性
* @param callback 回调函数
*/
*/
trackHeatMap
()
{}
send
<
T
>
(
para
:
T
,
type
:
EventType
)
{
para
=
Object
.
assign
(
this
.
getDefaultData
(),
para
)
const
reportInfo
=
{
properties
:
para
,
event
:
type
,
time
:
utils
.
dateFormat
(
Date
.
now
())
}
console
.
log
(
reportInfo
)
}
}
}
export
default
new
Collect
()
export
default
new
Collect
()
src/modules/events.ts
View file @
dd741db
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* @Author: yangming yangming@didihu.com.cn
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-28 17:15:38
* @Date: 2023-11-28 17:15:38
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-12-1
2 15:47:28
* @LastEditTime: 2023-12-1
4 14:58:34
* @FilePath: \glsx-tracker-javascript\src\modules\clickEvent.ts
* @FilePath: \glsx-tracker-javascript\src\modules\clickEvent.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
*/
*/
...
@@ -28,7 +28,6 @@ class Events {
...
@@ -28,7 +28,6 @@ class Events {
element
.
addEventListener
(
element
.
addEventListener
(
type
,
type
,
e
=>
{
e
=>
{
console
.
log
(
8888
)
handler
.
call
(
this
,
e
)
handler
.
call
(
this
,
e
)
},
},
useCapture
useCapture
...
...
src/modules/stayEvent.ts
View file @
dd741db
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* @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-1
3 15:37:25
* @LastEditTime: 2023-12-1
4 16:04:28
* @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
*/
*/
...
@@ -11,7 +11,7 @@ import collect from './collect'
...
@@ -11,7 +11,7 @@ import collect from './collect'
import
Events
from
'./events'
import
Events
from
'./events'
class
StayEvent
{
class
StayEvent
{
_options
:
any
_options
:
any
start_time
:
number
=
0
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
...
@@ -52,9 +52,13 @@ class StayEvent {
...
@@ -52,9 +52,13 @@ class StayEvent {
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
)
{
return
false
}
if
(
!
this
.
timer
)
{
if
(
!
this
.
timer
)
{
const
para
=
this
.
getStayInfo
()
this
.
timer
=
setTimeout
(()
=>
{
this
.
timer
=
setTimeout
(()
=>
{
this
.
send
()
this
.
send
(
para
)
},
this
.
timeout_time
)
},
this
.
timeout_time
)
}
}
})
})
...
@@ -62,9 +66,9 @@ class StayEvent {
...
@@ -62,9 +66,9 @@ class StayEvent {
/**
/**
* 发送数据
* 发送数据
*/
*/
send
()
{
send
(
para
:
object
)
{
this
.
timer
=
undefined
this
.
timer
=
undefined
const
para
=
this
.
getStayInfo
()
this
.
start_time
=
Date
.
now
()
collect
.
getStayEvent
(
para
)
collect
.
getStayEvent
(
para
)
}
}
/**
/**
...
...
src/modules/viewEvent.ts
View file @
dd741db
...
@@ -2,26 +2,36 @@
...
@@ -2,26 +2,36 @@
* @Author: yangming yangming@didihu.com.cn
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-30 14:45:53
* @Date: 2023-11-30 14:45:53
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-12-1
3 17:57:01
* @LastEditTime: 2023-12-1
4 17:36:55
* @FilePath: \glsx-tracker-javascript\src\modules\viewEvent.ts
* @FilePath: \glsx-tracker-javascript\src\modules\viewEvent.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
{
viewBase
,
routerOption
}
from
'../types/view'
import
type
{
viewBase
,
routerOption
}
from
'../types/view'
import
Events
from
'./events'
import
Events
from
'./events'
import
utils
from
'../utils/helper'
import
collect
from
'./collect'
class
ViewEvent
{
class
ViewEvent
{
baseParams
:
viewBase
last_time
:
string
routerModel
:
routerOption
|
undefined
=
'hash'
routerModel
:
routerOption
|
undefined
=
'hash'
/**
/**
* 初始化页面信息
* 初始化页面信息
*$page_title: 页面标题
*$page_title: 页面标题
$page_url: 页面地址
$page_url: 页面地址
$page_path: 页面地址
$page_path: 页面地址
$path_href: 页面完整地址
$enter_time: 进入页面的时间
$leave_time:离开页面的时间
$page_referrer: 页面来源
$page_referrer: 页面来源
*/
*/
initPage
():
viewBase
{
constructor
()
{
return
{
this
.
last_time
=
utils
.
dateFormat
(
new
Date
())
this
.
baseParams
=
{
$page_title
:
document
.
title
,
$page_title
:
document
.
title
,
$page_url
:
location
.
href
,
$page_url
:
location
.
href
,
$page_path
:
location
.
pathname
,
$page_path
:
location
.
pathname
,
$enter_time
:
this
.
last_time
,
$leave_time
:
''
,
$page_referrer
:
''
$page_referrer
:
''
}
}
}
}
...
@@ -30,15 +40,14 @@ class ViewEvent {
...
@@ -30,15 +40,14 @@ class ViewEvent {
*/
*/
init
(
routerModel
?:
routerOption
)
{
init
(
routerModel
?:
routerOption
)
{
this
.
routerModel
=
routerModel
this
.
routerModel
=
routerModel
this
.
initPage
()
this
.
initEvent
()
this
.
initEvent
()
}
}
/**
/**
* 重写pushState/replaceState事件
* 重写pushState/replaceState事件
*/
*/
initEvent
()
{
initEvent
()
{
window
.
history
[
'pushState'
]
=
this
.
createHistoryEv
n
ent
(
'pushState'
)
window
.
history
[
'pushState'
]
=
this
.
createHistoryEvent
(
'pushState'
)
window
.
history
[
'replaceState'
]
=
this
.
createHistoryEv
n
ent
(
'replaceState'
)
window
.
history
[
'replaceState'
]
=
this
.
createHistoryEvent
(
'replaceState'
)
if
(
this
.
routerModel
==
'history'
)
{
if
(
this
.
routerModel
==
'history'
)
{
this
.
captureEvents
([
'pushState'
,
'replaceState'
,
'popstate'
])
this
.
captureEvents
([
'pushState'
,
'replaceState'
,
'popstate'
])
}
}
...
@@ -46,31 +55,50 @@ class ViewEvent {
...
@@ -46,31 +55,50 @@ class ViewEvent {
this
.
captureEvents
([
'hashchange'
])
this
.
captureEvents
([
'hashchange'
])
}
}
}
}
/**
* 绑定hashchange、popstate事件
*/
captureEvents
<
T
>
(
MouseEventList
:
string
[])
{
captureEvents
<
T
>
(
MouseEventList
:
string
[])
{
MouseEventList
.
forEach
(
event
=>
{
MouseEventList
.
forEach
(
event
=>
{
Events
.
addEvent
(
window
,
event
,
(
e
:
MouseEvent
)
=>
{
Events
.
addEvent
(
window
,
event
,
(
e
:
MouseEvent
)
=>
{
console
.
log
(
555
)
this
.
trigger
(
)
})
})
})
})
}
}
/**
createHistoryEvnent
=
<
T
extends
keyof
History
>
(
type
:
T
):
(()
=>
any
)
=>
{
* 创建事件
* params history事件名
*/
createHistoryEvent
=
<
T
extends
keyof
History
>
(
type
:
T
):
(()
=>
any
)
=>
{
const
origin
=
history
[
type
]
const
origin
=
history
[
type
]
const
self
=
this
return
function
(
this
:
any
)
{
return
function
(
this
:
any
)
{
const
res
=
origin
.
apply
(
this
,
arguments
)
const
res
=
origin
.
apply
(
this
,
arguments
)
var
e
=
new
Event
(
type
)
self
.
trigger
()
window
.
dispatchEvent
(
e
)
return
res
return
res
}
}
}
}
/**
/**
*
获取页面信息
*
修改页面信息、并合并自定义属性
* @param
target 接收的数据
* @param
customProps 自定义属性
*/
*/
getPresetProperties
()
{}
getPresetProperties
(
customProps
:
any
)
{
const
current_url
=
location
.
href
this
.
baseParams
.
$page_referrer
=
this
.
baseParams
.
$page_url
this
.
baseParams
.
$page_url
=
current_url
const
current_time
=
utils
.
dateFormat
(
new
Date
())
this
.
baseParams
.
$leave_time
=
current_time
this
.
baseParams
.
$enter_time
=
this
.
last_time
;
this
.
last_time
=
current_time
let
_customProps
=
typeof
customProps
===
'object'
&&
customProps
!==
null
?
customProps
:
{}
return
Object
.
assign
(
this
.
baseParams
,
_customProps
)
}
/**
/**
* 绑定浏览事件
* 绑定浏览事件
*/
*/
trigger
()
{}
trigger
(
prop
?:
any
)
{
const
para
=
this
.
getPresetProperties
(
prop
)
collect
.
getViewEvent
(
para
)
}
}
}
export
default
new
ViewEvent
()
export
default
new
ViewEvent
()
src/types/collect.d.ts
View file @
dd741db
...
@@ -11,3 +11,10 @@ export interface DefaultInfoDescriptor {
...
@@ -11,3 +11,10 @@ export interface DefaultInfoDescriptor {
$page_url
:
string
|
undefined
$page_url
:
string
|
undefined
$page_path
:
string
|
undefined
$page_path
:
string
|
undefined
}
}
export
interface
DeviceInfoDescriptor
{
$plateform
:
string
$appName
:
string
$userAgent
:
string
$appVersion
:
string
[
prop
:
string
]:
string
}
src/types/main.ts
View file @
dd741db
...
@@ -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-1
3 17:36:03
* @LastEditTime: 2023-12-1
5 09:21:40
* @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,6 +18,7 @@ export type ScrollOption = {
...
@@ -18,6 +18,7 @@ export type ScrollOption = {
delay_time
:
number
delay_time
:
number
}
}
export
type
optonsDescriptor
=
{
export
type
optonsDescriptor
=
{
SDK_version
:
string
server_url
:
string
server_url
:
string
router_type
:
routerOption
router_type
:
routerOption
track_type
:
trackType
track_type
:
trackType
...
...
src/types/view.d.ts
View file @
dd741db
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* @Author: yangming yangming@didihu.com.cn
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-12-11 16:15:11
* @Date: 2023-12-11 16:15:11
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-12-1
1 16:18:57
* @LastEditTime: 2023-12-1
4 14:33:28
* @FilePath: \glsx-tracker-javascript\src\types\view.d.ts
* @FilePath: \glsx-tracker-javascript\src\types\view.d.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
*/
*/
...
@@ -10,6 +10,8 @@ export interface viewBase {
...
@@ -10,6 +10,8 @@ export interface viewBase {
$page_title
:
string
$page_title
:
string
$page_url
:
string
$page_url
:
string
$page_path
:
string
$page_path
:
string
$enter_time
:
string
$leave_time
:
string
$page_referrer
:
string
|
undefined
$page_referrer
:
string
|
undefined
}
}
export
type
routerOption
=
'history'
|
'hash'
export
type
routerOption
=
'history'
|
'hash'
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment