Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas
/
uplus-fapai-mp
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 ead69ed1
authored
Apr 25, 2026
by
chenwq
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化埋点功能,新增事件记录接口并调整定时推送逻辑
1 parent
13e502ec
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
72 deletions
pages/Login/Login.js
utils/cache/storageApi.js
utils/constants.js
utils/track/Track.js
pages/Login/Login.js
View file @
ead69ed
...
@@ -150,6 +150,12 @@ Page({
...
@@ -150,6 +150,12 @@ Page({
if
(
code
==
"200"
)
{
if
(
code
==
"200"
)
{
this
.
customerLoginCallBack
(
data
);
this
.
customerLoginCallBack
(
data
);
wx
.
p
.
isLogin
=
true
;
wx
.
p
.
isLogin
=
true
;
// 登录成功埋点
if
(
wx
.
$Track
&&
wx
.
$Track
.
reportEvent
)
{
wx
.
$Track
.
reportEvent
(
"denglu_dianji"
);
}
wx
.
p
.
router
.
goHome
();
wx
.
p
.
router
.
goHome
();
}
else
{
}
else
{
throw
message
;
throw
message
;
...
...
utils/cache/storageApi.js
View file @
ead69ed
...
@@ -16,6 +16,12 @@ export function setUserInfo(data) {
...
@@ -16,6 +16,12 @@ export function setUserInfo(data) {
console
.
log
(
data
)
console
.
log
(
data
)
storage
.
set
(
'userInfo'
,
data
)
storage
.
set
(
'userInfo'
,
data
)
}
}
export
function
getEventRecordList
()
{
return
storage
.
get
(
'eventRecordList'
)
}
export
function
setEventRecordList
(
data
)
{
storage
.
set
(
'eventRecordList'
,
data
)
}
export
function
removeSystemStorage
()
{
export
function
removeSystemStorage
()
{
// storage.rm('srcm_shopmall_user_info')
// storage.rm('srcm_shopmall_user_info')
// storage.rm('scrm_shopmall_token')
// storage.rm('scrm_shopmall_token')
...
@@ -61,6 +67,8 @@ export default{
...
@@ -61,6 +67,8 @@ export default{
setToken
,
setToken
,
getUserInfo
,
getUserInfo
,
setUserInfo
,
setUserInfo
,
getEventRecordList
,
setEventRecordList
,
removeSystemStorage
,
removeSystemStorage
,
setStorageSync
,
setStorageSync
,
getStorageSync
,
getStorageSync
,
...
...
utils/constants.js
View file @
ead69ed
...
@@ -11,7 +11,8 @@ export const STORAGE_OBJECTkEY = {
...
@@ -11,7 +11,8 @@ export const STORAGE_OBJECTkEY = {
token
:
'token'
,
token
:
'token'
,
bindInfo
:
'bindInfo'
,
bindInfo
:
'bindInfo'
,
unauthorized
:
'unauthorized'
,
unauthorized
:
'unauthorized'
,
wx_user_info
:
'wx_user_info'
wx_user_info
:
'wx_user_info'
,
eventRecordList
:
'eventRecordList'
}
}
export
default
{
export
default
{
...
...
utils/track/Track.js
View file @
ead69ed
...
@@ -10,12 +10,29 @@ import { getUserInfo } from "~/utils/cache/userInfo";
...
@@ -10,12 +10,29 @@ import { getUserInfo } from "~/utils/cache/userInfo";
let
TRACK_TIME
=
null
,
let
TRACK_TIME
=
null
,
ADDRESS_INFO
=
null
;
ADDRESS_INFO
=
null
;
const
track_interval_time
=
6
0
*
1
e3
;
const
track_interval_time
=
3
0
*
1
e3
;
class
TRACK
{
class
TRACK
{
constructor
()
{
constructor
()
{
console
.
log
(
"---------------- 埋点初始化 ----------------"
);
console
.
log
(
"---------------- 埋点初始化 ----------------"
);
this
.
initPageProxy
();
this
.
initPageProxy
();
this
.
appShow
();
this
.
appHide
();
this
.
startInterval
();
}
startInterval
()
{
if
(
TRACK_TIME
)
clearInterval
(
TRACK_TIME
);
TRACK_TIME
=
setInterval
(()
=>
{
this
.
sendEventData
();
},
track_interval_time
);
}
stopInterval
()
{
if
(
TRACK_TIME
)
{
clearInterval
(
TRACK_TIME
);
TRACK_TIME
=
null
;
}
}
}
/**监听页面 */
/**监听页面 */
pageLeaveProxy
(
thisPage
)
{
pageLeaveProxy
(
thisPage
)
{
...
@@ -77,86 +94,70 @@ class TRACK {
...
@@ -77,86 +94,70 @@ class TRACK {
}
}
appShow
()
{
appShow
()
{
wx
.
onAppShow
(()
=>
{
wx
.
onAppShow
(()
=>
{
// if (TRACK_TIME) clearInterval(TRACK_TIME)
// this.sendTrack()
this
.
stopInterval
();
// wx.offAppShow()
this
.
startInterval
();
// this.appHide()
console
.
log
(
'---------------- 重新打开埋点定时器 ----------------'
);
// console.log('---------------- 重新打开埋点 ----------------')
});
});
}
}
appHide
()
{
appHide
()
{
wx
.
onAppHide
(()
=>
{
wx
.
onAppHide
(()
=>
{
// if (TRACK_TIME) clearInterval(TRACK_TIME)
this
.
sendEventData
();
// 隐藏时顺便兜底发一次
// wx.offAppHide()
this
.
stopInterval
();
// this.appShow()
console
.
log
(
'---------------- APP隐藏 埋点停止推送定时器 ----------------'
);
// console.log('---------------- APP隐藏 埋点停止推送 ----------------')
});
});
}
}
/**设置埋点数据
* eventType:动作类型枚举 0点击 1滚动 2浏览
/**
*
eventCode:事件别名枚举
*
上报埋点事件
*
businessParam:业务参数
*
@param {String} eventCode 事件代码
*
batchId 浏览批次id,当浏览-进入事件发生时,必填
*
@param {Array} businessKeys 业务对象键值 [{businessType: "xxx", businessKey: "xxx"}]
*/
*/
setTrackData
(
eventType
,
eventCode
=
""
,
businessParam
=
""
,
batchId
,
scene
)
{
reportEvent
(
eventCode
,
businessKeys
=
[])
{
// console.log(eventCode, 'eventCode');
if
(
!
eventCode
)
return
;
let
recordList
=
wx
.
p
.
storage
.
get
(
"recordList"
),
{
route
}
=
this
.
getPageInstance
(),
let
eventTime
=
""
;
prePagePath
=
this
.
getPageInstance
(
2
),
if
(
Date
.
prototype
.
format
)
{
{
userType
}
=
wx
.
$util
.
getUserInfo
(),
eventTime
=
new
Date
().
format
(
"yyyy-MM-dd hh:mm:ss"
);
item
=
{
}
loginAccount
:
accountName
,
uuid
,
const
eventItem
=
{
userType
,
eventCode
,
systemSource
:
0
,
eventTime
,
eventTime
:
new
Date
().
format
(
"yyyy-MM-dd hh:mm:ss"
),
businessKeys
eventType
,
prePagePath
:
prePagePath
?
prePagePath
.
route
:
"/"
,
pagePath
:
route
,
scene
,
};
};
// console.log(new Date().format('yyyy-MM-dd hh:mm:ss'),'当前页:',route,'=========')
if
(
batchId
)
item
.
batchId
=
batchId
;
let
recordList
=
wx
.
p
.
storage
.
get
(
"eventRecordList"
)
||
[];
if
(
eventCode
)
item
.
eventCode
=
eventCode
;
recordList
.
push
(
eventItem
);
if
(
businessParam
)
item
.
businessParam
=
JSON
.
stringify
(
businessParam
);
wx
.
p
.
storage
.
set
(
"eventRecordList"
,
recordList
);
if
(
!
recordList
)
recordList
=
[
item
];
else
recordList
.
push
(
item
);
// 超过指定条数,触发发送
wx
.
p
.
storage
.
set
(
"recordList"
,
recordList
);
if
(
recordList
.
length
>
9
)
{
if
(
recordList
.
length
>
9
)
this
.
sendData
();
//10条
this
.
sendEventData
();
}
}
/**定时发送埋点数据 */
}
sendData
()
{
let
recordList
=
wx
.
p
.
storage
.
get
(
"recordList"
);
/**
if
(
recordList
&&
recordList
.
length
)
* 将缓存中的埋点数据批量发送给服务端
api
*/
.
post
(
sendEventData
()
{
"clue.api.burial.point.record.batch.insert"
,
let
recordList
=
wx
.
p
.
storage
.
get
(
"eventRecordList"
);
{
if
(
!
recordList
||
!
recordList
.
length
)
return
;
recordList
,
},
// 接口:/vr-api/rest/eventTracking/batchSave
[],
api
.
post
({
"/rop-scrm-clue/router"
,
method
:
'/rest/eventTracking/batchSave'
,
"scrm"
,
projectName
:
'vr'
,
false
,
events
:
recordList
)
},
false
).
then
(
res
=>
{
.
then
(({
code
,
data
,
message
})
=>
{
// 发送成功后清空队列
if
(
code
==
0
&&
data
)
{
wx
.
p
.
storage
.
set
(
"eventRecordList"
,
[]);
wx
.
p
.
storage
.
set
(
"recordList"
,
[]);
console
.
log
(
"---------------- 埋点定时推送成功 ----------------"
,
recordList
);
console
.
log
(
}).
catch
(
err
=>
{
"---------------- 埋点定时推送成功 ----------------"
,
console
.
log
(
"---------------- 埋点推定时送失败 ----------------"
,
err
);
new
Date
().
format
(
"yyyy-MM-dd hh:mm:ss"
),
":"
,
recordList
,
);
}
else
console
.
log
(
"---------------- 埋点定时推送失败 ----------------"
,
new
Date
().
format
(
"yyyy-MM-dd hh:mm:ss"
),
":"
,
message
,
);
});
});
}
}
/**获取页面对象实例 */
/**获取页面对象实例 */
getPageInstance
=
(
size
=
1
)
=>
{
getPageInstance
=
(
size
=
1
)
=>
{
const
pages
=
getCurrentPages
();
const
pages
=
getCurrentPages
();
...
...
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