Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Unified Diff: dart_microlytics/lib/microlytics.dart

Issue 515993003: Minimalistic analytics library used by Dart Server and try.dartlang.org (Closed) Base URL: https://github.com/lukechurch/dart-mircolytics.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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.
+ }
+}
+

Powered by Google App Engine
This is Rietveld 408576698