Commit 1a9323f7 authored by 李增强's avatar 李增强

m

parent dd668db1
# 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
This diff is collapsed.
......@@ -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;
});
}
}
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});
}
......@@ -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),
)
''';
// 页面可见或者不可见
......
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();
}
}
}
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");
}
}
......@@ -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:
......
......@@ -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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment