| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library usage_impl; | 5 library usage_impl; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
| 9 | 9 |
| 10 import 'uuid.dart'; | 10 import 'uuid.dart'; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 bool get optIn => properties['optIn'] == true; | 85 bool get optIn => properties['optIn'] == true; |
| 86 | 86 |
| 87 set optIn(bool value) { | 87 set optIn(bool value) { |
| 88 properties['optIn'] = value; | 88 properties['optIn'] = value; |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool get hasSetOptIn => properties['optIn'] != null; | 91 bool get hasSetOptIn => properties['optIn'] != null; |
| 92 | 92 |
| 93 Future sendScreenView(String viewName) { | 93 Future sendScreenView(String viewName) { |
| 94 Map args = {'cd': viewName}; | 94 Map<String, dynamic> args = {'cd': viewName}; |
| 95 return _sendPayload('screenview', args); | 95 return _sendPayload('screenview', args); |
| 96 } | 96 } |
| 97 | 97 |
| 98 Future sendEvent(String category, String action, {String label, int value}) { | 98 Future sendEvent(String category, String action, {String label, int value}) { |
| 99 if (!optIn) return new Future.value(); | 99 if (!optIn) return new Future.value(); |
| 100 | 100 |
| 101 Map args = {'ec': category, 'ea': action}; | 101 Map<String, dynamic> args = {'ec': category, 'ea': action}; |
| 102 if (label != null) args['el'] = label; | 102 if (label != null) args['el'] = label; |
| 103 if (value != null) args['ev'] = value; | 103 if (value != null) args['ev'] = value; |
| 104 return _sendPayload('event', args); | 104 return _sendPayload('event', args); |
| 105 } | 105 } |
| 106 | 106 |
| 107 Future sendSocial(String network, String action, String target) { | 107 Future sendSocial(String network, String action, String target) { |
| 108 if (!optIn) return new Future.value(); | 108 if (!optIn) return new Future.value(); |
| 109 | 109 |
| 110 Map args = {'sn': network, 'sa': action, 'st': target}; | 110 Map<String, dynamic> args = {'sn': network, 'sa': action, 'st': target}; |
| 111 return _sendPayload('social', args); | 111 return _sendPayload('social', args); |
| 112 } | 112 } |
| 113 | 113 |
| 114 Future sendTiming(String variableName, int time, {String category, | 114 Future sendTiming(String variableName, int time, {String category, |
| 115 String label}) { | 115 String label}) { |
| 116 if (!optIn) return new Future.value(); | 116 if (!optIn) return new Future.value(); |
| 117 | 117 |
| 118 Map args = {'utv': variableName, 'utt': time}; | 118 Map<String, dynamic> args = {'utv': variableName, 'utt': time}; |
| 119 if (label != null) args['utl'] = label; | 119 if (label != null) args['utl'] = label; |
| 120 if (category != null) args['utc'] = category; | 120 if (category != null) args['utc'] = category; |
| 121 return _sendPayload('timing', args); | 121 return _sendPayload('timing', args); |
| 122 } | 122 } |
| 123 | 123 |
| 124 AnalyticsTimer startTimer(String variableName, {String category, String label}
) { | 124 AnalyticsTimer startTimer(String variableName, {String category, String label}
) { |
| 125 return new AnalyticsTimer(this, | 125 return new AnalyticsTimer(this, |
| 126 variableName, category: category, label: label); | 126 variableName, category: category, label: label); |
| 127 } | 127 } |
| 128 | 128 |
| 129 Future sendException(String description, {bool fatal}) { | 129 Future sendException(String description, {bool fatal}) { |
| 130 if (!optIn) return new Future.value(); | 130 if (!optIn) return new Future.value(); |
| 131 | 131 |
| 132 // In order to ensure that the client of this API is not sending any PII | 132 // In order to ensure that the client of this API is not sending any PII |
| 133 // data, we strip out any stack trace that may reference a path on the | 133 // data, we strip out any stack trace that may reference a path on the |
| 134 // user's drive (file:/...). | 134 // user's drive (file:/...). |
| 135 if (description.contains('file:/')) { | 135 if (description.contains('file:/')) { |
| 136 description = description.substring(0, description.indexOf('file:/')); | 136 description = description.substring(0, description.indexOf('file:/')); |
| 137 } | 137 } |
| 138 | 138 |
| 139 if (description != null && description.length > _MAX_EXCEPTION_LENGTH) { | 139 if (description != null && description.length > _MAX_EXCEPTION_LENGTH) { |
| 140 description = description.substring(0, _MAX_EXCEPTION_LENGTH); | 140 description = description.substring(0, _MAX_EXCEPTION_LENGTH); |
| 141 } | 141 } |
| 142 | 142 |
| 143 Map args = {'exd': description}; | 143 Map<String, dynamic> args = {'exd': description}; |
| 144 if (fatal != null && fatal) args['exf'] = '1'; | 144 if (fatal != null && fatal) args['exf'] = '1'; |
| 145 return _sendPayload('exception', args); | 145 return _sendPayload('exception', args); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void setSessionValue(String param, dynamic value) { | 148 void setSessionValue(String param, dynamic value) { |
| 149 if (value == null) { | 149 if (value == null) { |
| 150 _variableMap.remove(param); | 150 _variableMap.remove(param); |
| 151 } else { | 151 } else { |
| 152 _variableMap[param] = value; | 152 _variableMap[param] = value; |
| 153 } | 153 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 169 String get _clientId => properties['clientId']; | 169 String get _clientId => properties['clientId']; |
| 170 | 170 |
| 171 void _initClientId() { | 171 void _initClientId() { |
| 172 if (_clientId == null) { | 172 if (_clientId == null) { |
| 173 properties['clientId'] = new Uuid().generateV4(); | 173 properties['clientId'] = new Uuid().generateV4(); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 // Valid values for [hitType] are: 'pageview', 'screenview', 'event', | 177 // Valid values for [hitType] are: 'pageview', 'screenview', 'event', |
| 178 // 'transaction', 'item', 'social', 'exception', and 'timing'. | 178 // 'transaction', 'item', 'social', 'exception', and 'timing'. |
| 179 Future _sendPayload(String hitType, Map args) { | 179 Future _sendPayload(String hitType, Map<String, dynamic> args) { |
| 180 if (_bucket.removeDrop()) { | 180 if (_bucket.removeDrop()) { |
| 181 _initClientId(); | 181 _initClientId(); |
| 182 | 182 |
| 183 _variableMap.forEach((key, value) { | 183 _variableMap.forEach((key, value) { |
| 184 args[key] = value; | 184 args[key] = value; |
| 185 }); | 185 }); |
| 186 | 186 |
| 187 args['v'] = '1'; // protocol version | 187 args['v'] = '1'; // protocol version |
| 188 args['tid'] = trackingId; | 188 args['tid'] = trackingId; |
| 189 args['cid'] = _clientId; | 189 args['cid'] = _clientId; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 /** | 221 /** |
| 222 * A utility class to perform HTTP POSTs. An [AnalyticsImpl] instance expects to | 222 * A utility class to perform HTTP POSTs. An [AnalyticsImpl] instance expects to |
| 223 * have one of these injected into it. There are default implementations for | 223 * have one of these injected into it. There are default implementations for |
| 224 * `dart:io` and `dart:html` clients. | 224 * `dart:io` and `dart:html` clients. |
| 225 * | 225 * |
| 226 * The POST information should be sent on a best-effort basis. The `Future` from | 226 * The POST information should be sent on a best-effort basis. The `Future` from |
| 227 * [sendPost] should complete when the operation is finished, but failures to | 227 * [sendPost] should complete when the operation is finished, but failures to |
| 228 * send the information should be silent. | 228 * send the information should be silent. |
| 229 */ | 229 */ |
| 230 abstract class PostHandler { | 230 abstract class PostHandler { |
| 231 Future sendPost(String url, Map<String, String> parameters); | 231 Future sendPost(String url, Map<String, dynamic> parameters); |
| 232 } | 232 } |
| OLD | NEW |