Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
auto_track_plugin
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Dubhe
2024-10-10 10:20:05 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-10-10 10:20:05 +0800
Commit
ab10bf45d71db1600c87ba5892271f78e439ebaa
ab10bf45
1 parent
1dffc278
feat: add event handler config
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
33 deletions
README.md
example/lib/main.dart
lib/auto_track/config/config.dart
lib/auto_track/track/track.dart
pubspec.yaml
README.md
View file @
ab10bf4
# Auto_Track_Plugin
> Flutter
自动
埋点插件,支持 Android 和 iOS
> Flutter
全
埋点插件,支持 Android 和 iOS
低侵入全局自动埋点,自动记录页面进入、退出,点击、滑动等事件,并支持自定义事件。
## Getting Started 使用指南
只需在入口配置
`AutoTrack().config()`
即可启用全局埋点
目前仅在移动端验证通过,其他平台暂无验证。
### Installation 安装
...
...
@@ -39,8 +41,10 @@ class _MyAppState extends State<MyApp> {
AutoTrack
()
.
config
(
AutoTrackConfig
(
// 其余配置可查看AutoTrackConfig类
host:
'http://localhost:3000/api/track'
,
appKey:
'xxxx'
,
appSecret:
'xxxx'
,
eventHandler:
(
model
)
=>
{
// 事件触发会调用此方法,可自行处理
print
(
'event handler
${model.type}
'
)
},
pageConfigs:
[
AutoTrackPageConfig
<
PageA
>(
pageID:
'page_a'
,
// 配置页面ID,统计时可基于此ID进行统计
...
...
@@ -124,9 +128,10 @@ class PageA extends StatelessWidget {
```
### Data upload 数据上报
数据上报需配合服务端使用,参考
[
AutoTrack Server(开发中)
](
https://github.com/epoll-j/auto_track_server
)
,可自行实现服务端。
数据上报的格式
#### 配置host并启用数据上报后会定时上报数据
##### 数据上报的格式
```
{
'app_key':
config.appKey
??
'',
...
...
example/lib/main.dart
View file @
ab10bf4
...
...
@@ -3,7 +3,6 @@ import 'package:auto_track_example/home.dart';
import
'package:auto_track_example/page_a.dart'
;
import
'package:flutter/material.dart'
;
void
main
(
)
{
runApp
(
const
MyApp
());
}
...
...
@@ -20,11 +19,14 @@ class _MyAppState extends State<MyApp> {
void
initState
()
{
AutoTrack
()
.
config
(
AutoTrackConfig
(
pageConfigs:
[
AutoTrackPageConfig
<
PageA
>(
pageID:
'page_a'
,
),
]))
eventHandler:
(
model
)
=>
{
print
(
'event handler
${model.type}
'
)
},
pageConfigs:
[
AutoTrackPageConfig
<
PageA
>(
pageID:
'page_a'
,
),
]))
.
enable
()
.
enablePageLeave
()
.
enablePageView
()
...
...
lib/auto_track/config/config.dart
View file @
ab10bf4
import
'dart:convert'
;
import
'package:auto_track/auto_track/utils/track_model.dart'
;
import
'package:crypto/crypto.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:uuid/uuid.dart'
;
typedef
EventHandlerFunc
=
void
Function
(
TrackModel
);
class
AutoTrackConfig
{
AutoTrackConfig
({
this
.
host
,
this
.
appKey
=
''
,
this
.
host
,
// 数据上报地址
this
.
uploadInterval
,
// 数据上报间隔
this
.
appKey
=
''
,
// 数据上报时根据key和secret生成签名
this
.
appSecret
=
''
,
this
.
trackId
,
this
.
userId
,
this
.
signature
,
this
.
signature
,
// 签名生成方法,默认使用sha256对key、时间戳和secret进行签名
this
.
enableUpload
=
false
,
// 开启数据上报
this
.
trackId
,
// 埋点ID,默认使用UUID,每次启动时会变化
this
.
userId
,
// 用户ID
this
.
uniqueId
,
this
.
eventHandler
,
// 事件处理
this
.
pageConfigs
=
const
[],
this
.
useCustomRoute
=
false
,
this
.
ignoreElementKeys
=
const
[],
this
.
useCustomRoute
=
false
,
// 使用自定义路由
this
.
ignoreElementKeys
=
const
[],
// 忽略key列表
this
.
ignoreElementStringKeys
=
const
[],
this
.
enablePageView
=
true
,
this
.
enablePageLeave
=
false
,
this
.
enableClick
=
true
,
this
.
enableUpload
=
false
,
this
.
enableDrag
=
false
,
this
.
enableIgnoreNullKey
=
false
,
this
.
uploadInterval
this
.
enablePageView
=
true
,
// 监听页面进入事件
this
.
enablePageLeave
=
false
,
// 监听页面离开事件
this
.
enableClick
=
true
,
// 监听点击事件
this
.
enableDrag
=
false
,
// 监听拖拽事件
this
.
enableIgnoreNullKey
=
false
,
// 忽略空key事件
})
{
trackId
??=
const
Uuid
().
v4
().
replaceAll
(
'-'
,
''
);
signature
??=
(
t
)
=>
sha256
.
convert
(
utf8
.
encode
(
'
$appKey$t$appSecret
'
)).
toString
();
...
...
@@ -39,6 +43,7 @@ class AutoTrackConfig {
int
?
uploadInterval
;
Function
?
signature
;
EventHandlerFunc
?
eventHandler
;
List
<
AutoTrackPageConfig
>
pageConfigs
;
...
...
@@ -87,6 +92,4 @@ class AutoTrackPageConfig<T extends Widget> {
bool
ignore
;
String
?
pageTitle
;
PageWidgetFunc
?
isPageWidget
;
// bool isPageWidget(Widget pageWidget) => pageWidget is T;
}
...
...
lib/auto_track/track/track.dart
View file @
ab10bf4
...
...
@@ -111,22 +111,32 @@ class Track {
class
_TrackPlugin
{
static
void
pageView
(
Map
<
String
,
dynamic
>
params
)
{
AutoTrackQueue
.
instance
.
appendQueue
(
TrackModel
(
'page_view'
,
DateTime
.
now
().
millisecondsSinceEpoch
,
params
,
params
[
'page_manual_key'
]));
var
model
=
TrackModel
(
'page_view'
,
DateTime
.
now
().
millisecondsSinceEpoch
,
params
,
params
[
'page_manual_key'
]);
AutoTrackConfigManager
.
instance
.
config
.
eventHandler
?.
call
(
model
);
AutoTrackQueue
.
instance
.
appendQueue
(
model
);
}
static
void
pageLeave
(
Map
<
String
,
dynamic
>
params
)
{
AutoTrackQueue
.
instance
.
appendQueue
(
TrackModel
(
'page_leave'
,
DateTime
.
now
().
millisecondsSinceEpoch
,
params
,
params
[
'page_manual_key'
]));
var
model
=
TrackModel
(
'page_leave'
,
DateTime
.
now
().
millisecondsSinceEpoch
,
params
,
params
[
'page_manual_key'
]);
AutoTrackConfigManager
.
instance
.
config
.
eventHandler
?.
call
(
model
);
AutoTrackQueue
.
instance
.
appendQueue
(
model
);
}
static
void
click
(
Map
<
String
,
dynamic
>
params
)
{
AutoTrackQueue
.
instance
.
appendQueue
(
TrackModel
(
'click'
,
DateTime
.
now
().
millisecondsSinceEpoch
,
params
,
params
[
'element_manual_key'
]));
var
model
=
TrackModel
(
'click'
,
DateTime
.
now
().
millisecondsSinceEpoch
,
params
,
params
[
'element_manual_key'
]);
AutoTrackConfigManager
.
instance
.
config
.
eventHandler
?.
call
(
model
);
AutoTrackQueue
.
instance
.
appendQueue
(
model
);
}
static
void
customEvent
(
String
type
,
Map
<
String
,
dynamic
>
params
)
{
AutoTrackQueue
.
instance
.
appendQueue
(
TrackModel
(
type
,
DateTime
.
now
().
millisecondsSinceEpoch
,
params
,
params
[
'key'
]
??
type
));
var
model
=
TrackModel
(
type
,
DateTime
.
now
().
millisecondsSinceEpoch
,
params
,
params
[
'key'
]
??
type
);
AutoTrackConfigManager
.
instance
.
config
.
eventHandler
?.
call
(
model
);
AutoTrackQueue
.
instance
.
appendQueue
(
model
);
}
static
void
drag
(
Map
<
String
,
dynamic
>
params
)
{
AutoTrackQueue
.
instance
.
appendQueue
(
TrackModel
(
'drag'
,
DateTime
.
now
().
millisecondsSinceEpoch
,
params
,
params
[
'manual_key'
]));
var
model
=
TrackModel
(
'drag'
,
DateTime
.
now
().
millisecondsSinceEpoch
,
params
,
params
[
'manual_key'
]);
AutoTrackConfigManager
.
instance
.
config
.
eventHandler
?.
call
(
model
);
AutoTrackQueue
.
instance
.
appendQueue
(
model
);
}
}
...
...
pubspec.yaml
View file @
ab10bf4
name
:
auto_track
name
:
auto_track
_plugin
description
:
"
Auto
Track
Plugin"
version
:
0.0.4
homepage
:
https://github.com/epoll-j/auto_track_plugin
...
...
Please
register
or
login
to post a comment