OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library microlytics; |
| 6 |
| 7 import 'channels.dart'; |
| 8 |
| 9 /// Very limited implementation of an API to report usage to Google Analytics. |
| 10 /// No Personally Identifiable Information must ever be passed to this class. |
| 11 class AnalyticsLogger { |
| 12 final Channel _channel; |
| 13 final String _clientID; |
| 14 final String _analyticsID; |
| 15 final String _appName; |
| 16 final String _appVersion; |
| 17 final String _messagePrefix; //Computed prefix for analytics messages |
| 18 |
| 19 /// Create a new logger |
| 20 /// [channel] represents how this is going to be sent, this would typically |
| 21 /// be a [RateLimitingBufferedChannel] wrapping either a [HttpRequestChannel] |
| 22 /// or a [HttpClientChannel]. |
| 23 /// [clientID] is a version 4 UUID associated with the site or app. |
| 24 /// [appName] is an application name. |
| 25 /// [appVersion] is a verion string. |
| 26 AnalyticsLogger(Channel channel, String clientID, String analyticsID, |
| 27 String appName, String appVersion) |
| 28 : this._channel = channel, |
| 29 this._clientID = clientID, |
| 30 this._analyticsID = analyticsID, |
| 31 this._appName = appName, |
| 32 this._appVersion = appVersion, |
| 33 this._messagePrefix = |
| 34 "v=1" |
| 35 "&tid=$analyticsID" |
| 36 "&cid=$clientID" |
| 37 "&an=$appName" |
| 38 "&av=$appVersion"; |
| 39 |
| 40 void logAnonymousTiming(String category, String variable, int ms) { |
| 41 category = Uri.encodeComponent(category); |
| 42 variable = Uri.encodeComponent(variable); |
| 43 _channel.sendData( |
| 44 "${this._messagePrefix}" |
| 45 "&t=timing" |
| 46 "&utc=$category" |
| 47 "&utv=$variable" |
| 48 "&utt=$ms"); |
| 49 } |
| 50 |
| 51 void logAnonymousEvent(String category, String event) { |
| 52 category = Uri.encodeComponent(category); |
| 53 event = Uri.encodeComponent(event); |
| 54 _channel.sendData( |
| 55 "${this._messagePrefix}" |
| 56 "&t=event" |
| 57 "&ec=$category" |
| 58 "&ea=$event"); |
| 59 } |
| 60 } |
| 61 |
OLD | NEW |