Chromium Code Reviews| Index: dart_microlytics/lib/microlytics.dart |
| diff --git a/dart_microlytics/lib/microlytics.dart b/dart_microlytics/lib/microlytics.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7be485e34d2a0ce981b8cdcd4a8a10215b793a49 |
| --- /dev/null |
| +++ b/dart_microlytics/lib/microlytics.dart |
| @@ -0,0 +1,63 @@ |
| +// 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. |
|
ahe
2014/09/02 13:44:24
Add line between copyright and library declaration
lukechurch
2014/09/03 11:27:16
Done.
|
| +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; |
| + |
| + /// Create a new logger |
| + /// [_channel] represents how this is going to be sent, this would typically |
| + /// be a [RateLimitingBufferedChannel] wrapping either a [HttpRequestChannel] |
| + /// or a [HttpClientChannel] |
| + /// [_clientID] is a version 4 UUID associated with the particular site or app |
| + /// [_appName] is an application name |
| + /// [_appVersion] is a verion string |
| + AnalyticsLogger( |
| + this._channel, |
| + this._clientID, |
| + this._analyticsID, |
| + this._appName, |
| + this._appVersion); |
| + |
| + void logAnonymousTiming(String category, String variable, int ms) { |
| + category = Uri.encodeComponent(category); |
| + variable = Uri.encodeComponent(variable); |
| + _channel.sendData( |
| + "v=1" |
| + "&tid=${this._analyticsID}" |
| + "&cid=${this._clientID}" |
| + "&t=timing" |
| + "&utc=$category" |
| + "&utv=$variable" |
| + "&utt=$ms" |
| + "&an=${this._appName}" |
| + "&av=${this._appVersion}" |
|
ahe
2014/09/02 13:44:24
Can you share (some of) this string between the tw
lukechurch
2014/09/02 19:52:37
Done.
|
| + ); |
|
ahe
2014/09/02 13:44:24
Move to previous line.
lukechurch
2014/09/02 19:52:37
Done.
|
| + } |
| + |
| + void logAnonymousEvent(String category, String event) { |
| + category = Uri.encodeComponent(category); |
| + event = Uri.encodeComponent(event); |
| + _channel.sendData( |
| + "v=1" |
| + "&tid=${this._analyticsID}" |
| + "&cid=${this._clientID}" |
| + "&t=event" |
| + "&ec=$category" |
| + "&ea=$event" |
| + "&an=${this._appName}" |
| + "&av=${this._appVersion}" |
| + ); |
|
ahe
2014/09/02 13:44:24
Move to previous line.
lukechurch
2014/09/02 19:52:37
Done.
|
| + } |
| +} |
| + |