Chromium Code Reviews| Index: microlytics/lib/microlytics.dart |
| diff --git a/microlytics/lib/microlytics.dart b/microlytics/lib/microlytics.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b3f8d9bc8ec1781a59762a45180c0efd37ad08e6 |
| --- /dev/null |
| +++ b/microlytics/lib/microlytics.dart |
| @@ -0,0 +1,61 @@ |
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library microlytics; |
| + |
| +import 'channels.dart'; |
| +import 'io_channels.dart'; |
| + |
| +/// Very limited implementation of an API to report usage to Google Analytics. |
| +/// No Personally Identifiable Information must ever be passed to this class. |
| +class AnalyticsLogger { |
| + final Channel _channel; |
| + final String _clientID; |
| + final String _analyticsID; |
| + final String _appName; |
| + final String _appVersion; |
| + final String _messagePrefix; //Computed prefix for analytics messages |
| + |
| + /// Create a new logger |
| + /// [_channel] represents how this is going to be sent, this would typically |
|
danrubel
2014/09/03 11:19:48
Either remove the '_' on the comments to match the
lukechurch
2014/09/04 12:58:42
Done.
|
| + /// be a [RateLimitingBufferedChannel] wrapping either a [HttpRequestChannel] |
| + /// or a [HttpClientChannel]. |
| + /// [_clientID] is a version 4 UUID associated with the site or app. |
| + /// [_appName] is an application name. |
| + /// [_appVersion] is a verion string. |
| + AnalyticsLogger(channel, clientID, analyticsID, appName, appVersion) |
|
danrubel
2014/09/03 11:19:48
all public API should be fully typed...
https://ww
lukechurch
2014/09/03 11:27:17
Arrg, yes, this was caused by the adjustment to us
|
| + : this._channel = channel, |
| + this._clientID = clientID, |
| + this._analyticsID = analyticsID, |
| + this._appName = appName, |
| + this._appVersion = appVersion, |
| + this._messagePrefix = |
| + "v=1" |
| + "&tid=$analyticsID" |
| + "&cid=$clientID" |
| + "&an=$appName" |
| + "&av=$appVersion"; |
| + |
| + void logAnonymousTiming(String category, String variable, int ms) { |
| + category = Uri.encodeComponent(category); |
| + variable = Uri.encodeComponent(variable); |
| + _channel.sendData( |
| + "${this._messagePrefix}" |
| + "&t=timing" |
| + "&utc=$category" |
| + "&utv=$variable" |
| + "&utt=$ms"); |
| + } |
| + |
| + void logAnonymousEvent(String category, String event) { |
| + category = Uri.encodeComponent(category); |
| + event = Uri.encodeComponent(event); |
| + _channel.sendData( |
| + "${this._messagePrefix}" |
| + "&t=event" |
| + "&ec=$category" |
| + "&ea=$event"); |
| + } |
| +} |
| + |