diff --git a/pkg/microlytics/example/simple.dart b/pkg/microlytics/example/simple.dart index b0b6792fc3b..42b323e2114 100644 --- a/pkg/microlytics/example/simple.dart +++ b/pkg/microlytics/example/simple.dart @@ -8,8 +8,8 @@ import 'package:microlytics/microlytics.dart'; void main(List arguments) { // Create the channel that will be used to communicate to analytics. - var channel = new RateLimitingBufferedChannel( - new HttpClientChannel(), packetsPerSecond: 1.0); + var channel = new RateLimitingBufferedChannel(new HttpClientChannel(), + packetsPerSecond: 1.0); if (arguments.length != 1) { print("usage: dart simple.dart GA-Client-ID"); @@ -23,4 +23,4 @@ void main(List arguments) { // Send some messages. lg.logAnonymousEvent("hello", "world"); lg.logAnonymousTiming("loader", "var", 42); -} \ No newline at end of file +} diff --git a/pkg/microlytics/lib/channels.dart b/pkg/microlytics/lib/channels.dart index 88dee4988d8..18f233c19f9 100644 --- a/pkg/microlytics/lib/channels.dart +++ b/pkg/microlytics/lib/channels.dart @@ -22,10 +22,8 @@ class RateLimitingBufferedChannel extends Channel { final int _bufferSizeLimit; Timer _timer; - RateLimitingBufferedChannel( - this._innerChannel, - {int bufferSizeLimit: 10, - double packetsPerSecond: 1.0}) + RateLimitingBufferedChannel(this._innerChannel, + {int bufferSizeLimit: 10, double packetsPerSecond: 1.0}) : this._bufferSizeLimit = bufferSizeLimit { if (!(packetsPerSecond > 0)) { throw new ArgumentError("packetsPerSecond must be larger than zero."); @@ -52,4 +50,4 @@ class RateLimitingBufferedChannel extends Channel { _timer.cancel(); _innerChannel.shutdown(); } -} \ No newline at end of file +} diff --git a/pkg/microlytics/lib/io_channels.dart b/pkg/microlytics/lib/io_channels.dart index 035e9a1a76c..044005cef8a 100644 --- a/pkg/microlytics/lib/io_channels.dart +++ b/pkg/microlytics/lib/io_channels.dart @@ -18,4 +18,3 @@ class HttpClientChannel extends Channel { }); } } - diff --git a/pkg/microlytics/lib/microlytics.dart b/pkg/microlytics/lib/microlytics.dart index 84d89e3257d..509ae26dea7 100644 --- a/pkg/microlytics/lib/microlytics.dart +++ b/pkg/microlytics/lib/microlytics.dart @@ -26,22 +26,20 @@ class AnalyticsLogger { 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"; + 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}" + _channel.sendData("${this._messagePrefix}" "&t=timing" "&utc=$category" "&utv=$variable" @@ -51,11 +49,9 @@ class AnalyticsLogger { void logAnonymousEvent(String category, String event) { category = Uri.encodeComponent(category); event = Uri.encodeComponent(event); - _channel.sendData( - "${this._messagePrefix}" + _channel.sendData("${this._messagePrefix}" "&t=event" "&ec=$category" "&ea=$event"); } } - diff --git a/pkg/microlytics/test/dart_microlytics_test.dart b/pkg/microlytics/test/dart_microlytics_test.dart index eab10025ee3..ca76b7592f6 100644 --- a/pkg/microlytics/test/dart_microlytics_test.dart +++ b/pkg/microlytics/test/dart_microlytics_test.dart @@ -17,16 +17,15 @@ void main() { } void testBasicEventRead() { - TestChannel c = new TestChannel(); - AnalyticsLogger logger = new AnalyticsLogger( + TestChannel c = new TestChannel(); + AnalyticsLogger logger = new AnalyticsLogger( c, "2cfac780-31e2-11e4-8c21-0800200c9a66", "UA-53895644-1", "TestApp", "0.42"); - logger.logAnonymousEvent("video", "play"); - Expect.isTrue(c.contains( - "v=1" + logger.logAnonymousEvent("video", "play"); + Expect.isTrue(c.contains("v=1" "&tid=UA-53895644-1" "&cid=2cfac780-31e2-11e4-8c21-0800200c9a66" "&an=TestApp" @@ -37,84 +36,79 @@ void testBasicEventRead() { } void testBasicNegativeEventRead() { - TestChannel c = new TestChannel(); - AnalyticsLogger logger = new AnalyticsLogger( - c, - "2cfac780-31e2-11e4-8c21-0800200c9a66", - "UA-53895644-1", - "TestApp", - "0.42"); - logger.logAnonymousEvent("video", "play"); - Expect.isFalse(c.contains( - "v=1" - "&tid=UA-53895644-1" - "&cid=2cfac780-31e2-11e4-8c21-0800200c9a66" - "&an=TestApp" - "&av=XXX" - "&t=event" - "&ec=video" - "&ea=play")); + TestChannel c = new TestChannel(); + AnalyticsLogger logger = new AnalyticsLogger( + c, + "2cfac780-31e2-11e4-8c21-0800200c9a66", + "UA-53895644-1", + "TestApp", + "0.42"); + logger.logAnonymousEvent("video", "play"); + Expect.isFalse(c.contains("v=1" + "&tid=UA-53895644-1" + "&cid=2cfac780-31e2-11e4-8c21-0800200c9a66" + "&an=TestApp" + "&av=XXX" + "&t=event" + "&ec=video" + "&ea=play")); } void testBasicTimingRead() { - TestChannel c = new TestChannel(); - AnalyticsLogger logger = new AnalyticsLogger( - c, - "2cfac780-31e2-11e4-8c21-0800200c9a66", - "UA-53895644-1", - "TestApp", - "0.42"); - logger.logAnonymousTiming("video", "delay", 157); - Expect.isTrue(c.contains( - "v=1" - "&tid=UA-53895644-1" - "&cid=2cfac780-31e2-11e4-8c21-0800200c9a66" - "&an=TestApp" - "&av=0.42" - "&t=timing" - "&utc=video" - "&utv=delay" - "&utt=157")); + TestChannel c = new TestChannel(); + AnalyticsLogger logger = new AnalyticsLogger( + c, + "2cfac780-31e2-11e4-8c21-0800200c9a66", + "UA-53895644-1", + "TestApp", + "0.42"); + logger.logAnonymousTiming("video", "delay", 157); + Expect.isTrue(c.contains("v=1" + "&tid=UA-53895644-1" + "&cid=2cfac780-31e2-11e4-8c21-0800200c9a66" + "&an=TestApp" + "&av=0.42" + "&t=timing" + "&utc=video" + "&utv=delay" + "&utt=157")); } void testBasicTimingMultiread() { - TestChannel c = new TestChannel(); - AnalyticsLogger logger = new AnalyticsLogger( - c, - "2cfac780-31e2-11e4-8c21-0800200c9a66", - "UA-53895644-1", - "TestApp", - "0.42"); - logger.logAnonymousTiming("video", "delay", 159); - logger.logAnonymousTiming("video", "delay", 152); - Expect.isTrue(c.contains( - "v=1" - "&tid=UA-53895644-1" - "&cid=2cfac780-31e2-11e4-8c21-0800200c9a66" - "&an=TestApp" - "&av=0.42" - "&t=timing" - "&utc=video" - "&utv=delay" - "&utt=152")); - Expect.isTrue(c.contains( - "v=1" - "&tid=UA-53895644-1" - "&cid=2cfac780-31e2-11e4-8c21-0800200c9a66" - "&an=TestApp" - "&av=0.42" - "&t=timing" - "&utc=video" - "&utv=delay" - "&utt=159")); - Expect.isFalse(c.contains( - "v=1" - "&tid=UA-53895644-1" - "&cid=2cfac780-31e2-11e4-8c21-0800200c9a66" - "&an=TestApp" - "&av=0.42" - "&t=timing" - "&utc=video" - "&utv=delay" - "&utt=19")); -} \ No newline at end of file + TestChannel c = new TestChannel(); + AnalyticsLogger logger = new AnalyticsLogger( + c, + "2cfac780-31e2-11e4-8c21-0800200c9a66", + "UA-53895644-1", + "TestApp", + "0.42"); + logger.logAnonymousTiming("video", "delay", 159); + logger.logAnonymousTiming("video", "delay", 152); + Expect.isTrue(c.contains("v=1" + "&tid=UA-53895644-1" + "&cid=2cfac780-31e2-11e4-8c21-0800200c9a66" + "&an=TestApp" + "&av=0.42" + "&t=timing" + "&utc=video" + "&utv=delay" + "&utt=152")); + Expect.isTrue(c.contains("v=1" + "&tid=UA-53895644-1" + "&cid=2cfac780-31e2-11e4-8c21-0800200c9a66" + "&an=TestApp" + "&av=0.42" + "&t=timing" + "&utc=video" + "&utv=delay" + "&utt=159")); + Expect.isFalse(c.contains("v=1" + "&tid=UA-53895644-1" + "&cid=2cfac780-31e2-11e4-8c21-0800200c9a66" + "&an=TestApp" + "&av=0.42" + "&t=timing" + "&utc=video" + "&utv=delay" + "&utt=19")); +}