Showing
6 changed files
with
76 additions
and
12 deletions
| @@ -35,10 +35,7 @@ class ClickInfo { | @@ -35,10 +35,7 @@ class ClickInfo { | ||
| 35 | } else { | 35 | } else { |
| 36 | clickInfo._elementManualKey = key?.toString() ?? md5.convert(utf8.encode('${clickInfo._elementType}${clickInfo._elementPath}')).toString(); | 36 | clickInfo._elementManualKey = key?.toString() ?? md5.convert(utf8.encode('${clickInfo._elementType}${clickInfo._elementPath}')).toString(); |
| 37 | } | 37 | } |
| 38 | - clickInfo._ignore = AutoTrackConfigManager.instance.isIgnoreElement(key); | ||
| 39 | - if (key is AutoTrackElementKey && !clickInfo._ignore) { | ||
| 40 | - clickInfo._ignore = key.ignore; | ||
| 41 | - } | 38 | + clickInfo._ignore = clickInfo._checkIgnore(key, clickInfo); |
| 42 | 39 | ||
| 43 | return clickInfo; | 40 | return clickInfo; |
| 44 | } | 41 | } |
| @@ -72,6 +69,23 @@ class ClickInfo { | @@ -72,6 +69,23 @@ class ClickInfo { | ||
| 72 | 69 | ||
| 73 | final PageInfo pageInfo; | 70 | final PageInfo pageInfo; |
| 74 | 71 | ||
| 72 | + bool _checkIgnore(Key? key, ClickInfo clickInfo) { | ||
| 73 | + if (AutoTrackConfigManager.instance.isIgnoreElement(key)) { | ||
| 74 | + return true; | ||
| 75 | + } | ||
| 76 | + if (key is AutoTrackElementKey) { | ||
| 77 | + if (key.ignore) { | ||
| 78 | + return true; | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + if (key == null && AutoTrackConfigManager.instance.config.enableIgnoreNullKey) { | ||
| 83 | + return true; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + return false; | ||
| 87 | + } | ||
| 88 | + | ||
| 75 | @override | 89 | @override |
| 76 | String toString() { | 90 | String toString() { |
| 77 | return [ | 91 | return [ |
| @@ -12,6 +12,7 @@ class AutoTrackConfig { | @@ -12,6 +12,7 @@ class AutoTrackConfig { | ||
| 12 | this.trackId, | 12 | this.trackId, |
| 13 | this.userId, | 13 | this.userId, |
| 14 | this.signature, | 14 | this.signature, |
| 15 | + this.uniqueId, | ||
| 15 | this.pageConfigs = const [], | 16 | this.pageConfigs = const [], |
| 16 | this.useCustomRoute = false, | 17 | this.useCustomRoute = false, |
| 17 | this.ignoreElementKeys = const [], | 18 | this.ignoreElementKeys = const [], |
| @@ -20,7 +21,8 @@ class AutoTrackConfig { | @@ -20,7 +21,8 @@ class AutoTrackConfig { | ||
| 20 | this.enablePageLeave = false, | 21 | this.enablePageLeave = false, |
| 21 | this.enableClick = true, | 22 | this.enableClick = true, |
| 22 | this.enableUpload = false, | 23 | this.enableUpload = false, |
| 23 | - this.enableDrag = false | 24 | + this.enableDrag = false, |
| 25 | + this.enableIgnoreNullKey = false | ||
| 24 | }) { | 26 | }) { |
| 25 | trackId ??= const Uuid().v4().replaceAll('-', ''); | 27 | trackId ??= const Uuid().v4().replaceAll('-', ''); |
| 26 | signature ??= (t) => sha256.convert(utf8.encode('$appKey$t$appSecret')).toString(); | 28 | signature ??= (t) => sha256.convert(utf8.encode('$appKey$t$appSecret')).toString(); |
| @@ -31,6 +33,8 @@ class AutoTrackConfig { | @@ -31,6 +33,8 @@ class AutoTrackConfig { | ||
| 31 | String? appSecret; | 33 | String? appSecret; |
| 32 | String? trackId; | 34 | String? trackId; |
| 33 | String? userId; | 35 | String? userId; |
| 36 | + String? uniqueId; | ||
| 37 | + | ||
| 34 | Function? signature; | 38 | Function? signature; |
| 35 | 39 | ||
| 36 | List<AutoTrackPageConfig> pageConfigs; | 40 | List<AutoTrackPageConfig> pageConfigs; |
| @@ -58,6 +62,8 @@ class AutoTrackConfig { | @@ -58,6 +62,8 @@ class AutoTrackConfig { | ||
| 58 | bool enableUpload; | 62 | bool enableUpload; |
| 59 | 63 | ||
| 60 | bool enableDrag; | 64 | bool enableDrag; |
| 65 | + | ||
| 66 | + bool enableIgnoreNullKey; | ||
| 61 | } | 67 | } |
| 62 | 68 | ||
| 63 | typedef PageWidgetFunc = bool Function(Widget); | 69 | typedef PageWidgetFunc = bool Function(Widget); |
| 1 | +import 'dart:convert'; | ||
| 2 | + | ||
| 1 | import 'package:auto_track/auto_track/config/queue.dart'; | 3 | import 'package:auto_track/auto_track/config/queue.dart'; |
| 4 | +import 'package:crypto/crypto.dart'; | ||
| 2 | import 'package:device_info_plus/device_info_plus.dart'; | 5 | import 'package:device_info_plus/device_info_plus.dart'; |
| 3 | import 'package:flutter/widgets.dart'; | 6 | import 'package:flutter/widgets.dart'; |
| 4 | import 'package:package_info_plus/package_info_plus.dart'; | 7 | import 'package:package_info_plus/package_info_plus.dart'; |
| @@ -8,19 +11,24 @@ import 'config.dart'; | @@ -8,19 +11,24 @@ import 'config.dart'; | ||
| 8 | class AutoTrackConfigManager { | 11 | class AutoTrackConfigManager { |
| 9 | static final AutoTrackConfigManager instance = AutoTrackConfigManager._(); | 12 | static final AutoTrackConfigManager instance = AutoTrackConfigManager._(); |
| 10 | 13 | ||
| 11 | - | ||
| 12 | AutoTrackConfigManager._() { | 14 | AutoTrackConfigManager._() { |
| 13 | PackageInfo.fromPlatform().then((value) => _appVersion = value.version); | 15 | PackageInfo.fromPlatform().then((value) => _appVersion = value.version); |
| 14 | - DeviceInfoPlugin().deviceInfo.then((value) => _deviceInfo = value.data); | 16 | + DeviceInfoPlugin().deviceInfo.then((value) { |
| 17 | + _deviceInfo = value.data; | ||
| 18 | + baseDeviceInfo = value; | ||
| 19 | + }); | ||
| 15 | } | 20 | } |
| 16 | 21 | ||
| 17 | String _appVersion = ''; | 22 | String _appVersion = ''; |
| 18 | String get appVersion => _appVersion; | 23 | String get appVersion => _appVersion; |
| 19 | 24 | ||
| 25 | + BaseDeviceInfo? baseDeviceInfo; | ||
| 26 | + String _deviceId = ''; | ||
| 27 | + String get deviceId => _deviceId; | ||
| 28 | + | ||
| 20 | Map<String, dynamic> _deviceInfo = {}; | 29 | Map<String, dynamic> _deviceInfo = {}; |
| 21 | Map<String, dynamic> get deviceInfo => _deviceInfo; | 30 | Map<String, dynamic> get deviceInfo => _deviceInfo; |
| 22 | 31 | ||
| 23 | - | ||
| 24 | AutoTrackConfig _config = AutoTrackConfig(); | 32 | AutoTrackConfig _config = AutoTrackConfig(); |
| 25 | AutoTrackConfig get config => _config; | 33 | AutoTrackConfig get config => _config; |
| 26 | 34 | ||
| @@ -29,6 +37,13 @@ class AutoTrackConfigManager { | @@ -29,6 +37,13 @@ class AutoTrackConfigManager { | ||
| 29 | 37 | ||
| 30 | void updateConfig(AutoTrackConfig config) { | 38 | void updateConfig(AutoTrackConfig config) { |
| 31 | _config = config; | 39 | _config = config; |
| 40 | + if (baseDeviceInfo is IosDeviceInfo) { | ||
| 41 | + _deviceId = md5.convert(utf8.encode('${(baseDeviceInfo as IosDeviceInfo).identifierForVendor}#${config.appKey}')).toString(); | ||
| 42 | + } else if (baseDeviceInfo is AndroidDeviceInfo) { | ||
| 43 | + _deviceId = md5.convert(utf8.encode('${(baseDeviceInfo as AndroidDeviceInfo).serialNumber}#${config.appKey}')).toString(); | ||
| 44 | + } else { | ||
| 45 | + _deviceId = ''; | ||
| 46 | + } | ||
| 32 | if (config.enableUpload) { | 47 | if (config.enableUpload) { |
| 33 | AutoTrackQueue.instance.start(); | 48 | AutoTrackQueue.instance.start(); |
| 34 | } else { | 49 | } else { |
| @@ -81,6 +96,10 @@ class AutoTrackConfigManager { | @@ -81,6 +96,10 @@ class AutoTrackConfigManager { | ||
| 81 | } | 96 | } |
| 82 | } | 97 | } |
| 83 | 98 | ||
| 99 | + void enableIgnoreNullKey(bool enable) { | ||
| 100 | + _config.enableIgnoreNullKey = enable; | ||
| 101 | + } | ||
| 102 | + | ||
| 84 | List<AutoTrackPageConfig> get pageConfigs => _config.pageConfigs; | 103 | List<AutoTrackPageConfig> get pageConfigs => _config.pageConfigs; |
| 85 | 104 | ||
| 86 | bool get useCustomRoute => _config.useCustomRoute; | 105 | bool get useCustomRoute => _config.useCustomRoute; |
| @@ -88,13 +107,13 @@ class AutoTrackConfigManager { | @@ -88,13 +107,13 @@ class AutoTrackConfigManager { | ||
| 88 | AutoTrackPageConfig getPageConfig(Widget pageWidget) { | 107 | AutoTrackPageConfig getPageConfig(Widget pageWidget) { |
| 89 | return _config.pageConfigs.firstWhere( | 108 | return _config.pageConfigs.firstWhere( |
| 90 | (pageConfig) => pageConfig.isPageWidget!(pageWidget), | 109 | (pageConfig) => pageConfig.isPageWidget!(pageWidget), |
| 91 | - orElse: () => AutoTrackPageConfig() | ||
| 92 | - ); | 110 | + orElse: () => AutoTrackPageConfig()); |
| 93 | } | 111 | } |
| 94 | 112 | ||
| 95 | Set<Key> getIgnoreElementKeySet() => _config.getIgnoreElementKeySet(); | 113 | Set<Key> getIgnoreElementKeySet() => _config.getIgnoreElementKeySet(); |
| 96 | 114 | ||
| 97 | - Set<String> getIgnoreElementStringKeySet() => _config.getIgnoreElementStringKeySet(); | 115 | + Set<String> getIgnoreElementStringKeySet() => |
| 116 | + _config.getIgnoreElementStringKeySet(); | ||
| 98 | 117 | ||
| 99 | bool isIgnoreElement(Key? key) { | 118 | bool isIgnoreElement(Key? key) { |
| 100 | if (key == null) { | 119 | if (key == null) { |
| @@ -121,4 +140,6 @@ class AutoTrackConfigManager { | @@ -121,4 +140,6 @@ class AutoTrackConfigManager { | ||
| 121 | bool get clickEnable => _config.enableClick; | 140 | bool get clickEnable => _config.enableClick; |
| 122 | 141 | ||
| 123 | bool get dragEnable => _config.enableDrag; | 142 | bool get dragEnable => _config.enableDrag; |
| 143 | + | ||
| 144 | + bool get ignoreNullKeyEnable => _config.enableIgnoreNullKey; | ||
| 124 | } | 145 | } |
| @@ -47,6 +47,7 @@ class AutoTrackQueue { | @@ -47,6 +47,7 @@ class AutoTrackQueue { | ||
| 47 | 't': t, | 47 | 't': t, |
| 48 | 'user_id': config.userId ?? '', | 48 | 'user_id': config.userId ?? '', |
| 49 | 'track_id': config.trackId ?? '', | 49 | 'track_id': config.trackId ?? '', |
| 50 | + 'unique_id': config.uniqueId ?? AutoTrackConfigManager.instance.deviceId, | ||
| 50 | 'data_list': uploadList.map((e) => e.toMap()).toList(), | 51 | 'data_list': uploadList.map((e) => e.toMap()).toList(), |
| 51 | 'app_version': AutoTrackConfigManager.instance.appVersion, | 52 | 'app_version': AutoTrackConfigManager.instance.appVersion, |
| 52 | 'device_info': AutoTrackConfigManager.instance.deviceInfo | 53 | 'device_info': AutoTrackConfigManager.instance.deviceInfo |
| @@ -67,6 +67,16 @@ class AutoTrack { | @@ -67,6 +67,16 @@ class AutoTrack { | ||
| 67 | return _instance; | 67 | return _instance; |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | + AutoTrack enableIgnoreNullKey() { | ||
| 71 | + AutoTrackConfigManager.instance.enableIgnoreNullKey(true); | ||
| 72 | + return _instance; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + AutoTrack disableIgnoreNullKey() { | ||
| 76 | + AutoTrackConfigManager.instance.enableIgnoreNullKey(false); | ||
| 77 | + return _instance; | ||
| 78 | + } | ||
| 79 | + | ||
| 70 | AutoTrack enableUpload() { | 80 | AutoTrack enableUpload() { |
| 71 | AutoTrackConfigManager.instance.enableUpload(true); | 81 | AutoTrackConfigManager.instance.enableUpload(true); |
| 72 | return _instance; | 82 | return _instance; |
| @@ -17,7 +17,7 @@ class PageInfo { | @@ -17,7 +17,7 @@ class PageInfo { | ||
| 17 | pageInfo._pagePath = pageConfig.pagePath ?? route.settings.name ?? ''; | 17 | pageInfo._pagePath = pageConfig.pagePath ?? route.settings.name ?? ''; |
| 18 | pageInfo._pageTitle = pageConfig.pageTitle ?? pageInfo._findTitle(element) ?? ''; | 18 | pageInfo._pageTitle = pageConfig.pageTitle ?? pageInfo._findTitle(element) ?? ''; |
| 19 | pageInfo._pageManualKey = pageConfig.pageID ?? md5.convert(utf8.encode('${pageInfo._pageKey}${pageInfo._pagePath}${pageInfo._pageTitle}')).toString(); | 19 | pageInfo._pageManualKey = pageConfig.pageID ?? md5.convert(utf8.encode('${pageInfo._pageKey}${pageInfo._pagePath}${pageInfo._pageTitle}')).toString(); |
| 20 | - pageInfo.ignore = pageConfig.ignore; | 20 | + pageInfo.ignore = pageInfo._checkIgnore(pageConfig); |
| 21 | return pageInfo; | 21 | return pageInfo; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| @@ -37,6 +37,18 @@ class PageInfo { | @@ -37,6 +37,18 @@ class PageInfo { | ||
| 37 | String _pagePath = ''; | 37 | String _pagePath = ''; |
| 38 | String get pagePath => _pagePath; | 38 | String get pagePath => _pagePath; |
| 39 | 39 | ||
| 40 | + bool _checkIgnore(AutoTrackPageConfig pageConfig) { | ||
| 41 | + if (pageConfig.ignore) { | ||
| 42 | + return true; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + if (AutoTrackConfigManager.instance.config.enableIgnoreNullKey && pageConfig.pageID == null) { | ||
| 46 | + return true; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + return false; | ||
| 50 | + } | ||
| 51 | + | ||
| 40 | String? _findTitle(Element element) { | 52 | String? _findTitle(Element element) { |
| 41 | String? title; | 53 | String? title; |
| 42 | ElementUtil.walkElement(element, (child, _) { | 54 | ElementUtil.walkElement(element, (child, _) { |
-
Please register or login to post a comment