Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
QM_TJ
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李增强
QM_TJ
Commits
1a9323f7
Commit
1a9323f7
authored
Jan 25, 2021
by
李增强
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
m
parent
dd668db1
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
455 additions
and
191 deletions
+455
-191
lib/a.md
lib/a.md
+135
-0
lib/qm_tj.dart
lib/qm_tj.dart
+112
-175
lib/src/db.dart
lib/src/db.dart
+16
-13
lib/src/model/tj_app_model.dart
lib/src/model/tj_app_model.dart
+21
-0
lib/src/sql.dart
lib/src/sql.dart
+5
-2
lib/src/tj/app.dart
lib/src/tj/app.dart
+73
-0
lib/src/utils.dart
lib/src/utils.dart
+84
-0
pubspec.lock
pubspec.lock
+7
-0
pubspec.yaml
pubspec.yaml
+2
-1
No files found.
lib/a.md
0 → 100644
View file @
1a9323f7
# 1.APP启动
```
{
event_name: "app_stage",
device_id:"",
event_data: [{
inter: "4G", // 网络情况
app_channel: "", // APP下载渠道
app_version: "1.0.0", // APP版本号
type: 2, // 1:启动APP, 2:APP从后台回到前台
appear_time: "1611540208", // 启动时间
disappear_time: "1611540208",// 关闭时间
extras: { // 此数据为自定义数据
user_id: "66713", // 用户id
source: 2, // 来源
...
}
}]
}
```
# 2.页面游览
```
{
event_name: "page_scan",
event_data: [{
inter: "4G", // 网络情况
app_channel: "", // APP下载渠道
app_version: "1.0.0", // APP版本号
page_id: "com.qm.app.goods", // 页面ID
last_page_id: "com.qm.app.home", // 上一个页面ID
appear_time: "1611540208", // 启动时间
disappear_time: "1611540208", // 关闭时间
extras: { // 此数据为自定义数据
user_id: "66713", // 用户id
source: 2, // 来源
goods_id: "15112231541", // 商品ID
...
}
}]
}
```
# 3.点击
```
{
event_name: "elem_click",
event_data: [{
inter: "4G", // 网络情况
app_channel: "", // APP下载渠道
app_version: "1.0.0", // APP版本号
page_id: "com.qm.app.goods", // 页面ID
click_id: "button", // 点击ID
click_time: "1611540208", // 点击时间
extras: { // 此数据为自定义数据
user_id: "66713", // 用户id
source: 2, // 来源
goods_id: "15112231541", // 商品ID
...
}
}]
}
```
# 4.曝光
```
{
event_name: "elem_exposure",
event_data: [{
inter: "4G", // 网络情况
app_channel: "", // APP下载渠道
app_version: "1.0.0", // APP版本号
page_id: "com.qm.app.goods", // 页面ID
exposure_id: "order_good_list", // 曝光ID
exposure_time: "1611540208", // 曝光时间
extras: { // 此数据为自定义数据
user_id: "66713", // 用户id
source: 2, // 来源
goods_id: "15112231541", // 商品ID
...
}
}]
}
```
# API数据格式
```
{
device_id:"",
projects:[{
event_name: "app_stage",
...
},{
event_name: "page_scan",
...
},{
event_name: "elem_click",
...
},{
event_name: "elem_exposure",
...
},{
event_name: "app_stage",
...
},{
event_name: "page_scan",
...
},{
event_name: "elem_click",
...
},{
event_name: "elem_exposure",
...
}]
}
```
## 数据上报
1.
APP启动上报(回到前台)
2.
定时上报
## APP启动和页面游览上报
1.
APP启动(进入前台)->APP关闭(进入后台),算一次上报
2.
页面启动(进入前台)->页面关闭(进入后台),算一次上报
## APP被杀死上报
1.
APP被杀死时,APP和游览页面没有关闭关闭时间,正常情况无法算一次上报,在APP启动时直接上报所有
\ No newline at end of file
lib/qm_tj.dart
View file @
1a9323f7
This diff is collapsed.
Click to expand it.
lib/src/db.dart
View file @
1a9323f7
...
...
@@ -5,9 +5,11 @@ import 'sql.dart';
class
DB
{
int
_version
=
1
;
Database
db
;
Future
<
bool
>
ready
;
/// 打开数据库
Future
init
()
async
{
void
init
()
{
ready
=
new
Future
<
bool
>(()
async
{
var
databasesPath
=
await
getDatabasesPath
();
String
path
=
join
(
databasesPath
,
...
...
@@ -20,6 +22,7 @@ class DB {
await
db
.
execute
(
SQL_TAP_TJ_TABLE
);
await
db
.
execute
(
SQL_EXPOSURE_TJ_TABLE
);
});
return
true
;
});
}
}
lib/src/model/tj_app_model.dart
0 → 100644
View file @
1a9323f7
enum
TJAppModelTypes
{
startUp
,
resume
}
class
TJAppModel
{
String
inter
;
String
appChannel
;
String
appVersion
;
TJAppModelTypes
type
;
int
appearTime
;
int
disappearTime
;
Map
<
String
,
dynamic
>
extras
;
TJAppModel
(
{
this
.
inter
,
this
.
appChannel
,
this
.
appVersion
,
this
.
type
,
this
.
appearTime
,
this
.
disappearTime
,
this
.
extras
});
}
lib/src/sql.dart
View file @
1a9323f7
...
...
@@ -3,10 +3,13 @@ String SQL_APP_TJ_TABLE = '''
CREATE TABLE app_tj (
id VARCHAR(32) ,
type TINYINT(4),
source INTEGER(10),
appear_time INTEGER(10),
disappear_time INTEGER(10),
extras VARCHAR(255)
extras VARCHAR(255),
inter VARCHAR(255),
app_channel VARCHAR(255),
app_version VARCHAR(255),
)
'''
;
// 页面可见或者不可见
...
...
lib/src/tj/app.dart
0 → 100644
View file @
1a9323f7
import
'dart:convert'
;
import
'../../src/db.dart'
;
import
'../../src/utils.dart'
;
class
App
{
DB
_db
;
String
_appStartUpId
;
App
(
DB
db
)
{
_db
=
db
;
}
/// APP回到前台
void
onResume
({
Map
<
String
,
dynamic
>
extras
})
async
{
int
type
=
2
;
int
disappearTime
=
0
;
int
appearTime
=
Utils
.
getDateNow
();
Map
<
String
,
dynamic
>
map
=
{
"id"
:
_appStartUpId
,
"type"
:
type
,
"appear_time"
:
appearTime
,
"disappear_time"
:
disappearTime
,
"extras"
:
json
.
encode
(
extras
)
};
Map
<
String
,
dynamic
>
common
=
await
Utils
.
getCommonParams
();
map
.
addAll
(
common
);
// APP 启动生成本次启动ID
if
(
_appStartUpId
==
null
)
{
type
=
1
;
_appStartUpId
=
Utils
.
md5
(
Utils
.
getDateNow
().
toString
());
}
await
_db
.
ready
;
Utils
.
log
(
"app onResume"
,
map
);
await
_db
.
db
.
insert
(
"app_tj"
,
map
);
}
/// APP进入后台
void
onPause
()
async
{
int
disappearTime
=
Utils
.
getDateNow
();
Map
<
String
,
dynamic
>
map
=
{
"id"
:
_appStartUpId
,
"disappear_time"
:
disappearTime
,
};
await
_db
.
ready
;
Utils
.
log
(
"app onPause"
,
map
);
await
_db
.
db
.
insert
(
"app_tj"
,
map
);
}
// 上传数据至接口
void
upload
()
async
{
await
_db
.
ready
;
List
<
Map
>
list
=
await
_db
.
db
.
query
(
"page_tj"
,
limit:
100
,
offset:
0
);
if
(
list
.
length
==
0
)
{
return
;
}
String
deviceId
=
await
Utils
.
getDeviceId
();
bool
result
=
await
Utils
.
uploadData
({
"device_id"
:
deviceId
,
"projects"
:
list
});
if
(
result
)
{
List
<
String
>
ids
=
list
.
map
((
e
)
=>
e
[
'id'
]).
toList
();
await
_db
.
db
.
rawDelete
(
"delete from page_tj where id in('
${ids.join("','")}
')"
);
}
if
(
Utils
.
isDebug
)
{
Utils
.
log
(
"upload_result"
,
{
"ok"
:
result
,
"length"
:
list
.
length
});
}
if
(
list
.
length
==
100
)
{
upload
();
}
}
}
lib/src/utils.dart
0 → 100644
View file @
1a9323f7
import
'dart:convert'
;
import
'http.dart'
;
import
'package:crypto/crypto.dart'
as
crypto
;
import
'package:package_info/package_info.dart'
;
class
Utils
{
static
String
channel
=
''
;
static
bool
isDebug
=
false
;
static
Http
_http
=
Http
(
scheme:
"http"
,
host:
"8.135.58.206"
,
port:
8802
);
/// 设置调试模式
static
void
debug
()
{
isDebug
=
true
;
}
/// 设置渠道
static
void
setChannel
(
String
s
)
{
channel
=
s
;
}
/// 获取当前时间戳,单位:秒
static
int
getDateNow
()
{
int
now
=
(
DateTime
.
now
().
millisecondsSinceEpoch
/
1000
).
floor
();
return
now
;
}
// md5编码
static
String
md5
(
String
data
)
{
var
bytes
=
utf8
.
encode
(
data
);
var
digest
=
crypto
.
md5
.
convert
(
bytes
);
return
digest
.
toString
();
}
// 获取app版本号
static
Future
<
String
>
getAppVersion
()
async
{
PackageInfo
packageInfo
=
await
PackageInfo
.
fromPlatform
();
String
version
=
packageInfo
.
version
;
return
version
;
}
// 获取网络类型
static
Future
<
String
>
getNetworkType
()
async
{
return
"4G"
;
}
// 获取设备ID
static
Future
<
String
>
getDeviceId
()
async
{
return
"3A26610FFE43D5838DDE7A40BA2E3E2C"
;
}
// 获取公共参数
static
Future
<
Map
<
String
,
dynamic
>>
getCommonParams
()
async
{
String
inter
=
await
Utils
.
getNetworkType
();
String
appVersion
=
await
Utils
.
getAppVersion
();
return
{
"inter"
:
inter
,
// 网络情况
"app_channel"
:
channel
,
// APP下载渠道
"app_version"
:
appVersion
,
// APP版本号
};
}
// 上传数据
static
Future
<
bool
>
uploadData
(
Map
<
String
,
dynamic
>
body
)
async
{
var
res
=
await
_http
.
post
(
"/collection"
,
body
);
if
(
isDebug
)
{
log
(
"upload-res"
,
res
);
}
if
(
res
!=
null
&&
res
[
'code'
]
==
200
)
{
return
true
;
}
return
false
;
}
static
void
log
(
String
type
,
Map
<
String
,
dynamic
>
map
)
{
if
(!
isDebug
)
{
return
;
}
print
(
"qm_tj:
$type
=======================s===========================
$type
"
);
print
(
"qm_tj:
$map
"
);
print
(
"qm_tj:
$type
=======================e===========================
$type
"
);
}
}
pubspec.lock
View file @
1a9323f7
...
...
@@ -88,6 +88,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0-nullsafety.3"
package_info:
dependency: "direct main"
description:
name: package_info
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.3+2"
path:
dependency: "direct main"
description:
...
...
pubspec.yaml
View file @
1a9323f7
...
...
@@ -14,6 +14,7 @@ dependencies:
sqflite
:
^1.3.2+2
path
:
^1.6.4
crypto
:
2.1.4
package_info
:
0.4.3+2
dev_dependencies
:
flutter_test
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment