#跟着坚果学鸿蒙#应用埋点开发实践<六>
·
埋点数据上传
// entry\src\main\ets\entryability\EntryAbility.ets
const onTrigger = CallbackManager.getInstance().getOnTrigger();
hiAppEvent.addWatcher({
name: 'watcher1',
appEventFilters: [
{
domain: 'test_domain',
eventTypes: [hiAppEvent.EventType.FAULT, hiAppEvent.EventType.BEHAVIOR]
}
],
triggerCondition: {
row: 10,
size: 1000,
timeOut: 1
},
onTrigger: onTrigger
})
hilog.info(0x0000, 'ApplicationTrack', '%{public}s', 'Succeeded in loading the content.');
总结
本文从绑定埋点数据入手,介绍三种埋点的开发实现:点击、曝光和页面埋点。最后调用hiAppEvent的addWatcher方法添加订阅对象和onTrigger回调,在回调中实现数据上报逻辑。
- 点击埋点:使用UIObserver的on("willClick")跟hiAppEvent的write方法共同实现埋点操作,将埋点数据写入本地设备文件。
- 曝光埋点:使用setOnVisibleAreaApproximateChange跟hiAppEvent的write方法共同实现埋点操作,将埋点数据写入本地设备文件。
- 页面埋点:使用UIObserver的on("navDestinationSwitch")跟hiAppEvent的write方法共同实现埋点操作,将埋点数据写入本地设备文件。
更多推荐
所有评论(0)