Showing
9 changed files
with
141 additions
and
93 deletions
@@ -29,9 +29,12 @@ class AutoTrackConfig { | @@ -29,9 +29,12 @@ class AutoTrackConfig { | ||
29 | this.enableClick = true, // 监听点击事件 | 29 | this.enableClick = true, // 监听点击事件 |
30 | this.enableDrag = false, // 监听拖拽事件 | 30 | this.enableDrag = false, // 监听拖拽事件 |
31 | this.enableIgnoreNullKey = false, // 忽略空key事件 | 31 | this.enableIgnoreNullKey = false, // 忽略空key事件 |
32 | + this.httpRequestConfig, | ||
32 | }) { | 33 | }) { |
33 | trackId ??= const Uuid().v4().replaceAll('-', ''); | 34 | trackId ??= const Uuid().v4().replaceAll('-', ''); |
34 | - signature ??= (t) => sha256.convert(utf8.encode('$appKey$t$appSecret')).toString(); | 35 | + signature ??= |
36 | + (t) => sha256.convert(utf8.encode('$appKey$t$appSecret')).toString(); | ||
37 | + httpRequestConfig ??= HttpRequestConfig(); | ||
35 | } | 38 | } |
36 | 39 | ||
37 | String? host; | 40 | String? host; |
@@ -77,6 +80,8 @@ class AutoTrackConfig { | @@ -77,6 +80,8 @@ class AutoTrackConfig { | ||
77 | 80 | ||
78 | bool enableIgnoreNullKey; | 81 | bool enableIgnoreNullKey; |
79 | 82 | ||
83 | + HttpRequestConfig? httpRequestConfig; | ||
84 | + | ||
80 | copyWith({ | 85 | copyWith({ |
81 | String? host, | 86 | String? host, |
82 | String? appKey, | 87 | String? appKey, |
@@ -98,6 +103,7 @@ class AutoTrackConfig { | @@ -98,6 +103,7 @@ class AutoTrackConfig { | ||
98 | bool? enableUpload, | 103 | bool? enableUpload, |
99 | bool? enableDrag, | 104 | bool? enableDrag, |
100 | bool? enableIgnoreNullKey, | 105 | bool? enableIgnoreNullKey, |
106 | + HttpRequestConfig? httpRequestConfig | ||
101 | }) { | 107 | }) { |
102 | return AutoTrackConfig( | 108 | return AutoTrackConfig( |
103 | host: host ?? this.host, | 109 | host: host ?? this.host, |
@@ -114,38 +120,14 @@ class AutoTrackConfig { | @@ -114,38 +120,14 @@ class AutoTrackConfig { | ||
114 | useCustomRoute: useCustomRoute ?? this.useCustomRoute, | 120 | useCustomRoute: useCustomRoute ?? this.useCustomRoute, |
115 | ignoreElementKeys: ignoreElementKeys ?? this.ignoreElementKeys, | 121 | ignoreElementKeys: ignoreElementKeys ?? this.ignoreElementKeys, |
116 | ignoreElementStringKeys: | 122 | ignoreElementStringKeys: |
117 | - ignoreElementStringKeys ?? this.ignoreElementStringKeys, | 123 | + ignoreElementStringKeys ?? this.ignoreElementStringKeys, |
118 | enablePageView: enablePageView ?? this.enablePageView, | 124 | enablePageView: enablePageView ?? this.enablePageView, |
119 | enablePageLeave: enablePageLeave ?? this.enablePageLeave, | 125 | enablePageLeave: enablePageLeave ?? this.enablePageLeave, |
120 | enableClick: enableClick ?? this.enableClick, | 126 | enableClick: enableClick ?? this.enableClick, |
121 | enableUpload: enableUpload ?? this.enableUpload, | 127 | enableUpload: enableUpload ?? this.enableUpload, |
122 | enableDrag: enableDrag ?? this.enableDrag, | 128 | enableDrag: enableDrag ?? this.enableDrag, |
123 | enableIgnoreNullKey: enableIgnoreNullKey ?? this.enableIgnoreNullKey, | 129 | enableIgnoreNullKey: enableIgnoreNullKey ?? this.enableIgnoreNullKey, |
124 | - ); | ||
125 | - } | ||
126 | - | ||
127 | - merge(AutoTrackConfig config) { | ||
128 | - return copyWith( | ||
129 | - host: config.host, | ||
130 | - appKey: config.appKey, | ||
131 | - appSecret: config.appSecret, | ||
132 | - trackId: config.trackId, | ||
133 | - userId: config.userId, | ||
134 | - uniqueId: config.uniqueId, | ||
135 | - samplingRate: config.samplingRate, | ||
136 | - uploadInterval: config.uploadInterval, | ||
137 | - signature: config.signature, | ||
138 | - eventHandler: config.eventHandler, | ||
139 | - pageConfigs: config.pageConfigs, | ||
140 | - useCustomRoute: config.useCustomRoute, | ||
141 | - ignoreElementKeys: config.ignoreElementKeys, | ||
142 | - ignoreElementStringKeys: config.ignoreElementStringKeys, | ||
143 | - enablePageView: config.enablePageView, | ||
144 | - enablePageLeave: config.enablePageLeave, | ||
145 | - enableClick: config.enableClick, | ||
146 | - enableUpload: config.enableUpload, | ||
147 | - enableDrag: config.enableDrag, | ||
148 | - enableIgnoreNullKey: config.enableIgnoreNullKey, | 130 | + httpRequestConfig: httpRequestConfig ?? this.httpRequestConfig |
149 | ); | 131 | ); |
150 | } | 132 | } |
151 | } | 133 | } |
@@ -153,13 +135,12 @@ class AutoTrackConfig { | @@ -153,13 +135,12 @@ class AutoTrackConfig { | ||
153 | typedef PageWidgetFunc = bool Function(Widget); | 135 | typedef PageWidgetFunc = bool Function(Widget); |
154 | 136 | ||
155 | class AutoTrackPageConfig<T extends Widget> { | 137 | class AutoTrackPageConfig<T extends Widget> { |
156 | - AutoTrackPageConfig({ | ||
157 | - this.pageID, | ||
158 | - this.pagePath, | ||
159 | - this.ignore = false, | ||
160 | - this.pageTitle, | ||
161 | - this.isPageWidget | ||
162 | - }) { | 138 | + AutoTrackPageConfig( |
139 | + {this.pageID, | ||
140 | + this.pagePath, | ||
141 | + this.ignore = false, | ||
142 | + this.pageTitle, | ||
143 | + this.isPageWidget}) { | ||
163 | isPageWidget ??= (pageWidget) => pageWidget is T; | 144 | isPageWidget ??= (pageWidget) => pageWidget is T; |
164 | } | 145 | } |
165 | 146 | ||
@@ -169,3 +150,13 @@ class AutoTrackPageConfig<T extends Widget> { | @@ -169,3 +150,13 @@ class AutoTrackPageConfig<T extends Widget> { | ||
169 | String? pageTitle; | 150 | String? pageTitle; |
170 | PageWidgetFunc? isPageWidget; | 151 | PageWidgetFunc? isPageWidget; |
171 | } | 152 | } |
153 | + | ||
154 | +class HttpRequestConfig { | ||
155 | + bool ignoreRequestHeader; | ||
156 | + bool ignoreResponseHeader; | ||
157 | + | ||
158 | + HttpRequestConfig({ | ||
159 | + this.ignoreRequestHeader = false, | ||
160 | + this.ignoreResponseHeader = false, | ||
161 | + }); | ||
162 | +} |
@@ -8,6 +8,8 @@ import 'package:package_info_plus/package_info_plus.dart'; | @@ -8,6 +8,8 @@ import 'package:package_info_plus/package_info_plus.dart'; | ||
8 | 8 | ||
9 | import 'config.dart'; | 9 | import 'config.dart'; |
10 | 10 | ||
11 | +typedef UpdateConfigFunc = AutoTrackConfig Function(AutoTrackConfig); | ||
12 | + | ||
11 | class AutoTrackConfigManager { | 13 | class AutoTrackConfigManager { |
12 | static final AutoTrackConfigManager instance = AutoTrackConfigManager._(); | 14 | static final AutoTrackConfigManager instance = AutoTrackConfigManager._(); |
13 | 15 | ||
@@ -37,13 +39,15 @@ class AutoTrackConfigManager { | @@ -37,13 +39,15 @@ class AutoTrackConfigManager { | ||
37 | bool get autoTrackEnable => _autoTrackEnable; | 39 | bool get autoTrackEnable => _autoTrackEnable; |
38 | 40 | ||
39 | void setConfig(AutoTrackConfig config) { | 41 | void setConfig(AutoTrackConfig config) { |
40 | - updateConfig(config); | 42 | + updateConfig((old) { |
43 | + return config; | ||
44 | + }); | ||
41 | _updateDeviceId(); | 45 | _updateDeviceId(); |
42 | } | 46 | } |
43 | 47 | ||
44 | - void updateConfig(AutoTrackConfig config) { | ||
45 | - _config = _config.merge(config); | ||
46 | - if (config.enableUpload) { | 48 | + void updateConfig(UpdateConfigFunc func) { |
49 | + _config = func(_config); | ||
50 | + if (_config.enableUpload) { | ||
47 | AutoTrackQueue.instance.start(); | 51 | AutoTrackQueue.instance.start(); |
48 | } else { | 52 | } else { |
49 | AutoTrackQueue.instance.stop(); | 53 | AutoTrackQueue.instance.stop(); |
@@ -8,10 +8,12 @@ import 'package:auto_track/auto_track/utils/track_model.dart'; | @@ -8,10 +8,12 @@ import 'package:auto_track/auto_track/utils/track_model.dart'; | ||
8 | 8 | ||
9 | import '../log/logger.dart'; | 9 | import '../log/logger.dart'; |
10 | 10 | ||
11 | - | ||
12 | class AutoTrackQueue { | 11 | class AutoTrackQueue { |
13 | static final AutoTrackQueue instance = AutoTrackQueue._(); | 12 | static final AutoTrackQueue instance = AutoTrackQueue._(); |
14 | - AutoTrackQueue._(); | 13 | + AutoTrackQueue._() { |
14 | + httpClient.badCertificateCallback = | ||
15 | + (X509Certificate cert, String host, int port) => true; | ||
16 | + } | ||
15 | 17 | ||
16 | Timer? _timer; | 18 | Timer? _timer; |
17 | final List<TrackModel> _queue = []; | 19 | final List<TrackModel> _queue = []; |
@@ -24,7 +26,10 @@ class AutoTrackQueue { | @@ -24,7 +26,10 @@ class AutoTrackQueue { | ||
24 | 26 | ||
25 | void start() { | 27 | void start() { |
26 | if (_timer != null) return; | 28 | if (_timer != null) return; |
27 | - _timer = Timer.periodic(Duration(seconds: AutoTrackConfigManager.instance.config.uploadInterval ?? 10), (timer) { | 29 | + _timer = Timer.periodic( |
30 | + Duration( | ||
31 | + seconds: AutoTrackConfigManager.instance.config.uploadInterval ?? | ||
32 | + 10), (timer) { | ||
28 | flush(); | 33 | flush(); |
29 | }); | 34 | }); |
30 | } | 35 | } |
@@ -48,15 +53,17 @@ class AutoTrackQueue { | @@ -48,15 +53,17 @@ class AutoTrackQueue { | ||
48 | } | 53 | } |
49 | if (host != null) { | 54 | if (host != null) { |
50 | final t = DateTime.now().millisecondsSinceEpoch; | 55 | final t = DateTime.now().millisecondsSinceEpoch; |
56 | + | ||
51 | httpClient.postUrl(Uri.parse(host)).then((request) { | 57 | httpClient.postUrl(Uri.parse(host)).then((request) { |
52 | - request.headers.set(HttpHeaders.contentTypeHeader, 'application/json'); | 58 | + request.headers.contentType = ContentType.json; |
53 | request.write(json.encode({ | 59 | request.write(json.encode({ |
54 | 'app_key': config.appKey ?? '', | 60 | 'app_key': config.appKey ?? '', |
55 | 'signature': config.signature!(t), | 61 | 'signature': config.signature!(t), |
56 | 't': t, | 62 | 't': t, |
57 | 'user_id': config.userId ?? '', | 63 | 'user_id': config.userId ?? '', |
58 | 'track_id': config.trackId ?? '', | 64 | 'track_id': config.trackId ?? '', |
59 | - 'unique_id': config.uniqueId ?? AutoTrackConfigManager.instance.deviceId, | 65 | + 'unique_id': |
66 | + config.uniqueId ?? AutoTrackConfigManager.instance.deviceId, | ||
60 | 'device_id': AutoTrackConfigManager.instance.deviceId, | 67 | 'device_id': AutoTrackConfigManager.instance.deviceId, |
61 | 'data_list': uploadList.map((e) => e.toMap()).toList(), | 68 | 'data_list': uploadList.map((e) => e.toMap()).toList(), |
62 | 'app_version': AutoTrackConfigManager.instance.appVersion, | 69 | 'app_version': AutoTrackConfigManager.instance.appVersion, |
@@ -64,10 +71,11 @@ class AutoTrackQueue { | @@ -64,10 +71,11 @@ class AutoTrackQueue { | ||
64 | })); | 71 | })); |
65 | return request.close(); | 72 | return request.close(); |
66 | }).then((response) { | 73 | }).then((response) { |
67 | - AutoTrackLogger.getInstance().debug('upload status => ${response.statusCode}'); | 74 | + AutoTrackLogger.getInstance() |
75 | + .debug('upload status => ${response.statusCode}'); | ||
68 | }).catchError((error) { | 76 | }).catchError((error) { |
69 | AutoTrackLogger.getInstance().error(error); | 77 | AutoTrackLogger.getInstance().error(error); |
70 | }); | 78 | }); |
71 | } | 79 | } |
72 | } | 80 | } |
73 | -} | ||
81 | +} |
@@ -19,11 +19,15 @@ class AutoTrack { | @@ -19,11 +19,15 @@ class AutoTrack { | ||
19 | } | 19 | } |
20 | 20 | ||
21 | void updateUserId(String id) { | 21 | void updateUserId(String id) { |
22 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(userId: id)); | 22 | + AutoTrackConfigManager.instance.updateConfig((config) { |
23 | + return config.copyWith(userId: id); | ||
24 | + }); | ||
23 | } | 25 | } |
24 | 26 | ||
25 | void updateSampleRate(double rate) { | 27 | void updateSampleRate(double rate) { |
26 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(samplingRate: rate)); | 28 | + AutoTrackConfigManager.instance.updateConfig((config) { |
29 | + return config.copyWith(samplingRate: rate); | ||
30 | + }); | ||
27 | } | 31 | } |
28 | 32 | ||
29 | AutoTrack config(AutoTrackConfig? config) { | 33 | AutoTrack config(AutoTrackConfig? config) { |
@@ -35,82 +39,112 @@ class AutoTrack { | @@ -35,82 +39,112 @@ class AutoTrack { | ||
35 | 39 | ||
36 | AutoTrack pageConfigs(List<AutoTrackPageConfig>? pageConfigs) { | 40 | AutoTrack pageConfigs(List<AutoTrackPageConfig>? pageConfigs) { |
37 | if (pageConfigs != null) { | 41 | if (pageConfigs != null) { |
38 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(pageConfigs: pageConfigs)); | 42 | + AutoTrackConfigManager.instance.updateConfig((config) { |
43 | + return config.copyWith(pageConfigs: pageConfigs); | ||
44 | + }); | ||
39 | } | 45 | } |
40 | return _instance; | 46 | return _instance; |
41 | } | 47 | } |
42 | 48 | ||
43 | AutoTrack ignoreElementKeys(List<Key>? ignoreElementKeys) { | 49 | AutoTrack ignoreElementKeys(List<Key>? ignoreElementKeys) { |
44 | if (ignoreElementKeys != null) { | 50 | if (ignoreElementKeys != null) { |
45 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(ignoreElementKeys: ignoreElementKeys)); | 51 | + AutoTrackConfigManager.instance.updateConfig((config) { |
52 | + return config.copyWith(ignoreElementKeys: ignoreElementKeys); | ||
53 | + }); | ||
46 | } | 54 | } |
47 | return _instance; | 55 | return _instance; |
48 | } | 56 | } |
49 | 57 | ||
50 | AutoTrack ignoreElementStringKeys(List<String>? ignoreElementStringKeys) { | 58 | AutoTrack ignoreElementStringKeys(List<String>? ignoreElementStringKeys) { |
51 | if (ignoreElementStringKeys != null) { | 59 | if (ignoreElementStringKeys != null) { |
52 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(ignoreElementStringKeys: ignoreElementStringKeys)); | 60 | + AutoTrackConfigManager.instance.updateConfig((config) { |
61 | + return config.copyWith(ignoreElementStringKeys: ignoreElementStringKeys); | ||
62 | + }); | ||
53 | } | 63 | } |
54 | return _instance; | 64 | return _instance; |
55 | } | 65 | } |
56 | 66 | ||
57 | AutoTrack enablePageView() { | 67 | AutoTrack enablePageView() { |
58 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(enablePageView: true)); | 68 | + AutoTrackConfigManager.instance.updateConfig((config) { |
69 | + return config.copyWith(enablePageView: true); | ||
70 | + }); | ||
59 | return _instance; | 71 | return _instance; |
60 | } | 72 | } |
61 | 73 | ||
62 | AutoTrack disablePageView() { | 74 | AutoTrack disablePageView() { |
63 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(enablePageView: false)); | 75 | + AutoTrackConfigManager.instance.updateConfig((config) { |
76 | + return config.copyWith(enablePageView: false); | ||
77 | + }); | ||
64 | return _instance; | 78 | return _instance; |
65 | } | 79 | } |
66 | 80 | ||
67 | AutoTrack enablePageLeave() { | 81 | AutoTrack enablePageLeave() { |
68 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(enablePageLeave: true)); | 82 | + AutoTrackConfigManager.instance.updateConfig((config) { |
83 | + return config.copyWith(enablePageLeave: true); | ||
84 | + }); | ||
69 | return _instance; | 85 | return _instance; |
70 | } | 86 | } |
71 | 87 | ||
72 | AutoTrack disablePageLeave() { | 88 | AutoTrack disablePageLeave() { |
73 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(enablePageLeave: false)); | 89 | + AutoTrackConfigManager.instance.updateConfig((config) { |
90 | + return config.copyWith(enablePageLeave: false); | ||
91 | + }); | ||
74 | return _instance; | 92 | return _instance; |
75 | } | 93 | } |
76 | 94 | ||
77 | AutoTrack enableIgnoreNullKey() { | 95 | AutoTrack enableIgnoreNullKey() { |
78 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(enableIgnoreNullKey: true)); | 96 | + AutoTrackConfigManager.instance.updateConfig((config) { |
97 | + return config.copyWith(enableIgnoreNullKey: true); | ||
98 | + }); | ||
79 | return _instance; | 99 | return _instance; |
80 | } | 100 | } |
81 | 101 | ||
82 | AutoTrack disableIgnoreNullKey() { | 102 | AutoTrack disableIgnoreNullKey() { |
83 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(enableIgnoreNullKey: false)); | 103 | + AutoTrackConfigManager.instance.updateConfig((config) { |
104 | + return config.copyWith(enableIgnoreNullKey: false); | ||
105 | + }); | ||
84 | return _instance; | 106 | return _instance; |
85 | } | 107 | } |
86 | 108 | ||
87 | AutoTrack enableUpload() { | 109 | AutoTrack enableUpload() { |
88 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(enableUpload: true)); | 110 | + AutoTrackConfigManager.instance.updateConfig((config) { |
111 | + return config.copyWith(enableUpload: true); | ||
112 | + }); | ||
89 | return _instance; | 113 | return _instance; |
90 | } | 114 | } |
91 | 115 | ||
92 | AutoTrack disableUpload() { | 116 | AutoTrack disableUpload() { |
93 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(enableUpload: false)); | 117 | + AutoTrackConfigManager.instance.updateConfig((config) { |
118 | + return config.copyWith(enableUpload: false); | ||
119 | + }); | ||
94 | return _instance; | 120 | return _instance; |
95 | } | 121 | } |
96 | 122 | ||
97 | AutoTrack enableClick() { | 123 | AutoTrack enableClick() { |
98 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(enableClick: true)); | 124 | + AutoTrackConfigManager.instance.updateConfig((config) { |
125 | + return config.copyWith(enableClick: true); | ||
126 | + }); | ||
99 | return _instance; | 127 | return _instance; |
100 | } | 128 | } |
101 | 129 | ||
102 | AutoTrack disableClick() { | 130 | AutoTrack disableClick() { |
103 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(enableClick: false)); | 131 | + AutoTrackConfigManager.instance.updateConfig((config) { |
132 | + return config.copyWith(enableClick: false); | ||
133 | + }); | ||
104 | return _instance; | 134 | return _instance; |
105 | } | 135 | } |
106 | 136 | ||
107 | AutoTrack enableDrag() { | 137 | AutoTrack enableDrag() { |
108 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(enableDrag: true)); | 138 | + AutoTrackConfigManager.instance.updateConfig((config) { |
139 | + return config.copyWith(enableDrag: true); | ||
140 | + }); | ||
109 | return _instance; | 141 | return _instance; |
110 | } | 142 | } |
111 | 143 | ||
112 | AutoTrack disableDrag() { | 144 | AutoTrack disableDrag() { |
113 | - AutoTrackConfigManager.instance.updateConfig(AutoTrackConfig(enableDrag: false)); | 145 | + AutoTrackConfigManager.instance.updateConfig((config) { |
146 | + return config.copyWith(enableDrag: false); | ||
147 | + }); | ||
114 | return _instance; | 148 | return _instance; |
115 | } | 149 | } |
116 | 150 | ||
@@ -125,6 +159,7 @@ class AutoTrack { | @@ -125,6 +159,7 @@ class AutoTrack { | ||
125 | AutoTrackConfigManager.instance.enableAutoTrack(false); | 159 | AutoTrackConfigManager.instance.enableAutoTrack(false); |
126 | PointerEventListener.instance.stop(); | 160 | PointerEventListener.instance.stop(); |
127 | DragPointerEventListener.instance.stop(); | 161 | DragPointerEventListener.instance.stop(); |
162 | + disableHttpRequest(); | ||
128 | return _instance; | 163 | return _instance; |
129 | } | 164 | } |
130 | 165 |
@@ -4,6 +4,7 @@ import 'dart:io'; | @@ -4,6 +4,7 @@ import 'dart:io'; | ||
4 | 4 | ||
5 | import 'package:auto_track/auto_track/track/track.dart'; | 5 | import 'package:auto_track/auto_track/track/track.dart'; |
6 | 6 | ||
7 | +import '../../config/manager.dart'; | ||
7 | import '../../utils/request_model.dart'; | 8 | import '../../utils/request_model.dart'; |
8 | import '../page_view/page_stack.dart'; | 9 | import '../page_view/page_stack.dart'; |
9 | 10 | ||
@@ -65,7 +66,10 @@ class HttpClientRequestWithChecker implements HttpClientRequest { | @@ -65,7 +66,10 @@ class HttpClientRequestWithChecker implements HttpClientRequest { | ||
65 | uri: _realRequest.uri, | 66 | uri: _realRequest.uri, |
66 | method: method, | 67 | method: method, |
67 | pageId: pageInfoData?.pageInfo?.pageKey ?? "", | 68 | pageId: pageInfoData?.pageInfo?.pageKey ?? "", |
68 | - requestHeaders: _realRequest.headers, | 69 | + requestHeaders: AutoTrackConfigManager |
70 | + .instance.config.httpRequestConfig!.ignoreRequestHeader | ||
71 | + ? null | ||
72 | + : _realRequest.headers, | ||
69 | message: message, | 73 | message: message, |
70 | status: -1, | 74 | status: -1, |
71 | spent: _stopwatch.elapsedMilliseconds)); | 75 | spent: _stopwatch.elapsedMilliseconds)); |
@@ -123,13 +127,13 @@ class HttpClientRequestWithChecker implements HttpClientRequest { | @@ -123,13 +127,13 @@ class HttpClientRequestWithChecker implements HttpClientRequest { | ||
123 | message = '$message: ${response.reasonPhrase}'; | 127 | message = '$message: ${response.reasonPhrase}'; |
124 | 128 | ||
125 | _stopwatch.stop(); | 129 | _stopwatch.stop(); |
126 | - | 130 | + final config = AutoTrackConfigManager.instance.config.httpRequestConfig!; |
127 | Track.instance.reportHttpRequest(RequestModel( | 131 | Track.instance.reportHttpRequest(RequestModel( |
128 | uri: _realRequest.uri, | 132 | uri: _realRequest.uri, |
129 | method: method, | 133 | method: method, |
130 | pageId: pageInfoData?.pageInfo?.pageKey ?? "", | 134 | pageId: pageInfoData?.pageInfo?.pageKey ?? "", |
131 | - requestHeaders: request.headers, | ||
132 | - responseHeaders: response.headers, | 135 | + requestHeaders: config.ignoreRequestHeader ? null : request.headers, |
136 | + responseHeaders: config.ignoreResponseHeader ? null : response.headers, | ||
133 | message: message, | 137 | message: message, |
134 | status: response.statusCode, | 138 | status: response.statusCode, |
135 | spent: _stopwatch.elapsedMilliseconds)); | 139 | spent: _stopwatch.elapsedMilliseconds)); |
@@ -182,8 +186,8 @@ class HttpClientWithChecker implements HttpClient { | @@ -182,8 +186,8 @@ class HttpClientWithChecker implements HttpClient { | ||
182 | @override | 186 | @override |
183 | set connectionFactory( | 187 | set connectionFactory( |
184 | Future<ConnectionTask<Socket>> Function( | 188 | Future<ConnectionTask<Socket>> Function( |
185 | - Uri url, String? proxyHost, int? proxyPort)? | ||
186 | - f) { | 189 | + Uri url, String? proxyHost, int? proxyPort)? |
190 | + f) { | ||
187 | // TODO: add impl here | 191 | // TODO: add impl here |
188 | assert(false); | 192 | assert(false); |
189 | } | 193 | } |
@@ -228,30 +232,30 @@ class HttpClientWithChecker implements HttpClient { | @@ -228,30 +232,30 @@ class HttpClientWithChecker implements HttpClient { | ||
228 | 232 | ||
229 | @override | 233 | @override |
230 | void addCredentials( | 234 | void addCredentials( |
231 | - Uri url, String realm, HttpClientCredentials credentials) => | 235 | + Uri url, String realm, HttpClientCredentials credentials) => |
232 | _realClient.addCredentials(url, realm, credentials); | 236 | _realClient.addCredentials(url, realm, credentials); |
233 | 237 | ||
234 | @override | 238 | @override |
235 | void addProxyCredentials(String host, int port, String realm, | 239 | void addProxyCredentials(String host, int port, String realm, |
236 | - HttpClientCredentials credentials) => | 240 | + HttpClientCredentials credentials) => |
237 | _realClient.addProxyCredentials(host, port, realm, credentials); | 241 | _realClient.addProxyCredentials(host, port, realm, credentials); |
238 | 242 | ||
239 | @override | 243 | @override |
240 | set authenticate( | 244 | set authenticate( |
241 | - Future<bool> Function(Uri url, String scheme, String? realm)? f) => | 245 | + Future<bool> Function(Uri url, String scheme, String? realm)? f) => |
242 | _realClient.authenticate = f; | 246 | _realClient.authenticate = f; |
243 | 247 | ||
244 | @override | 248 | @override |
245 | set authenticateProxy( | 249 | set authenticateProxy( |
246 | - Future<bool> Function( | ||
247 | - String host, int port, String scheme, String? realm)? | ||
248 | - f) => | 250 | + Future<bool> Function( |
251 | + String host, int port, String scheme, String? realm)? | ||
252 | + f) => | ||
249 | _realClient.authenticateProxy = f; | 253 | _realClient.authenticateProxy = f; |
250 | 254 | ||
251 | @override | 255 | @override |
252 | set badCertificateCallback( | 256 | set badCertificateCallback( |
253 | - bool Function(X509Certificate cert, String host, int port)? | ||
254 | - callback) => | 257 | + bool Function(X509Certificate cert, String host, int port)? |
258 | + callback) => | ||
255 | _realClient.badCertificateCallback = callback; | 259 | _realClient.badCertificateCallback = callback; |
256 | 260 | ||
257 | @override | 261 | @override |
@@ -329,7 +333,7 @@ class HttpClientWithChecker implements HttpClient { | @@ -329,7 +333,7 @@ class HttpClientWithChecker implements HttpClient { | ||
329 | path = path.substring(0, queryStart); | 333 | path = path.substring(0, queryStart); |
330 | } | 334 | } |
331 | final Uri uri = | 335 | final Uri uri = |
332 | - Uri(scheme: 'http', host: host, port: port, path: path, query: query); | 336 | + Uri(scheme: 'http', host: host, port: port, path: path, query: query); |
333 | return _addCheck(_realClient.open(method, host, port, path), method, uri); | 337 | return _addCheck(_realClient.open(method, host, port, path), method, uri); |
334 | } | 338 | } |
335 | 339 | ||
@@ -339,11 +343,19 @@ class HttpClientWithChecker implements HttpClient { | @@ -339,11 +343,19 @@ class HttpClientWithChecker implements HttpClient { | ||
339 | 343 | ||
340 | Future<HttpClientRequest> _addCheck( | 344 | Future<HttpClientRequest> _addCheck( |
341 | Future<HttpClientRequest> request, String method, Uri url) { | 345 | Future<HttpClientRequest> request, String method, Uri url) { |
346 | + final host = AutoTrackConfigManager.instance.config.host; | ||
347 | + if (host != null) { | ||
348 | + final uploadUrl = Uri.parse(host); | ||
349 | + if (uploadUrl.host == url.host && uploadUrl.path == url.path) { | ||
350 | + return request; | ||
351 | + } | ||
352 | + } | ||
353 | + | ||
342 | final Stopwatch stopwatch = Stopwatch()..start(); | 354 | final Stopwatch stopwatch = Stopwatch()..start(); |
343 | final Page? pageInfoData = PageStack.instance.getCurrentPage(); | 355 | final Page? pageInfoData = PageStack.instance.getCurrentPage(); |
344 | return request | 356 | return request |
345 | .then((HttpClientRequest request) => | 357 | .then((HttpClientRequest request) => |
346 | - HttpClientRequestWithChecker(request, stopwatch, pageInfoData)) | 358 | + HttpClientRequestWithChecker(request, stopwatch, pageInfoData)) |
347 | .catchError((dynamic error, dynamic stackTrace) {}, test: (error) { | 359 | .catchError((dynamic error, dynamic stackTrace) {}, test: (error) { |
348 | String message = error.toString(); | 360 | String message = error.toString(); |
349 | if (error is SocketException) { | 361 | if (error is SocketException) { |
@@ -381,4 +393,3 @@ class AutoTrackHttpOverrides extends HttpOverrides { | @@ -381,4 +393,3 @@ class AutoTrackHttpOverrides extends HttpOverrides { | ||
381 | return _currentOverrides!.findProxyFromEnvironment(url, environment); | 393 | return _currentOverrides!.findProxyFromEnvironment(url, environment); |
382 | } | 394 | } |
383 | } | 395 | } |
384 | - |
@@ -3,11 +3,11 @@ import 'package:auto_track/auto_track/utils/error_model.dart'; | @@ -3,11 +3,11 @@ import 'package:auto_track/auto_track/utils/error_model.dart'; | ||
3 | import 'package:auto_track/auto_track/utils/request_model.dart'; | 3 | import 'package:auto_track/auto_track/utils/request_model.dart'; |
4 | import 'package:auto_track/auto_track/utils/track_model.dart'; | 4 | import 'package:auto_track/auto_track/utils/track_model.dart'; |
5 | 5 | ||
6 | -import '../listener/click/click_info.dart'; | ||
7 | import '../config/manager.dart'; | 6 | import '../config/manager.dart'; |
7 | +import '../listener/click/click_info.dart'; | ||
8 | import '../listener/drag/drag_info.dart'; | 8 | import '../listener/drag/drag_info.dart'; |
9 | -import '../log/logger.dart'; | ||
10 | import '../listener/page_view/page_info.dart'; | 9 | import '../listener/page_view/page_info.dart'; |
10 | +import '../log/logger.dart'; | ||
11 | 11 | ||
12 | class Track { | 12 | class Track { |
13 | static final Track instance = Track._(); | 13 | static final Track instance = Track._(); |
@@ -111,6 +111,7 @@ class Track { | @@ -111,6 +111,7 @@ class Track { | ||
111 | } | 111 | } |
112 | 112 | ||
113 | void reportHttpRequest(RequestModel requestModel) { | 113 | void reportHttpRequest(RequestModel requestModel) { |
114 | + _TrackPlugin.customEvent('http', requestModel.toMap(), key: requestModel.uri.path); | ||
114 | AutoTrackLogger.getInstance().debug('track request => ${requestModel.toMap()}'); | 115 | AutoTrackLogger.getInstance().debug('track request => ${requestModel.toMap()}'); |
115 | } | 116 | } |
116 | } | 117 | } |
@@ -135,8 +136,8 @@ class _TrackPlugin { | @@ -135,8 +136,8 @@ class _TrackPlugin { | ||
135 | AutoTrackQueue.instance.appendQueue(model); | 136 | AutoTrackQueue.instance.appendQueue(model); |
136 | } | 137 | } |
137 | 138 | ||
138 | - static void customEvent(String type, Map<String, dynamic> params) { | ||
139 | - var model = TrackModel(type, DateTime.now().millisecondsSinceEpoch, params, params['key'] ?? type); | 139 | + static void customEvent(String type, Map<String, dynamic> params, { String? key }) { |
140 | + var model = TrackModel(type, DateTime.now().millisecondsSinceEpoch, params, params['key'] ?? key ?? type); | ||
140 | AutoTrackConfigManager.instance.config.eventHandler?.call(model); | 141 | AutoTrackConfigManager.instance.config.eventHandler?.call(model); |
141 | AutoTrackQueue.instance.appendQueue(model); | 142 | AutoTrackQueue.instance.appendQueue(model); |
142 | } | 143 | } |
@@ -6,7 +6,6 @@ class RequestModel { | @@ -6,7 +6,6 @@ class RequestModel { | ||
6 | required this.status, | 6 | required this.status, |
7 | required this.spent, | 7 | required this.spent, |
8 | required this.pageId, | 8 | required this.pageId, |
9 | - this.requestBody, | ||
10 | this.requestHeaders, | 9 | this.requestHeaders, |
11 | this.responseHeaders, | 10 | this.responseHeaders, |
12 | }); | 11 | }); |
@@ -17,21 +16,19 @@ class RequestModel { | @@ -17,21 +16,19 @@ class RequestModel { | ||
17 | String pageId; | 16 | String pageId; |
18 | int status; | 17 | int status; |
19 | int spent; | 18 | int spent; |
20 | - dynamic requestBody; | ||
21 | dynamic requestHeaders; | 19 | dynamic requestHeaders; |
22 | dynamic responseHeaders; | 20 | dynamic responseHeaders; |
23 | 21 | ||
24 | Map<String, dynamic> toMap() { | 22 | Map<String, dynamic> toMap() { |
25 | return { | 23 | return { |
26 | - 'uri': uri, | 24 | + 'uri': uri.toString(), |
27 | 'method': method, | 25 | 'method': method, |
28 | 'message': message, | 26 | 'message': message, |
29 | 'pageId': pageId, | 27 | 'pageId': pageId, |
30 | 'status': status, | 28 | 'status': status, |
31 | 'spent': spent, | 29 | 'spent': spent, |
32 | - 'requestBody': requestBody, | ||
33 | - 'requestHeaders': requestHeaders, | ||
34 | - 'responseHeaders': responseHeaders, | 30 | + 'requestHeaders': requestHeaders.toString(), |
31 | + 'responseHeaders': responseHeaders.toString(), | ||
35 | }; | 32 | }; |
36 | } | 33 | } |
37 | } | 34 | } |
1 | name: auto_track | 1 | name: auto_track |
2 | -description: "Auto Track Plugin" | ||
3 | -version: 0.0.6 | 2 | +description: "Low-intrusion global automatic embedding, automatically recording events such as page entry, exit, clicks, scrolling, and HTTP requests, and supporting custom events." |
3 | +version: 0.0.7 | ||
4 | homepage: https://github.com/epoll-j/auto_track_plugin | 4 | homepage: https://github.com/epoll-j/auto_track_plugin |
5 | 5 | ||
6 | environment: | 6 | environment: |
-
Please register or login to post a comment