Files
sdk/pkg/microlytics/lib/microlytics.dart
T
lukechurch@google.com 710bf6f401 First cut of basic functionality
This CL addresses comments from the previous Pull Request https://github.com/lukechurch/dart-microlytics/pull/1

It can be used to reporting usage and performance data to Google Analytics.

Known issues:

-> unittest library is still used
-> some comments are still not in full sentences

R=ahe@google.com, danrubel@google.com

Review URL: https://codereview.chromium.org//515993003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@39914 260f80e4-7a28-3924-810f-c04153c831b5
2014-09-05 14:00:08 +00:00

62 lines
2.0 KiB
Dart

// 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';
/// 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
/// 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 channel, String clientID, String analyticsID,
String appName, String appVersion)
: 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");
}
}