bump to 3.0
diff --git a/.travis.yml b/.travis.yml
index 35def79..fa1f329 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,9 +3,4 @@
- dev
sudo: false
-# before_install:
-# - "export CHROME_ARGS=--no-sandbox"
-# - "export DISPLAY=:99.0"
-# - "sh -e /etc/init.d/xvfb start"
-
script: ./tool/travis.sh
diff --git a/example/ga.dart b/example/ga.dart
index e905ea6..1676699 100644
--- a/example/ga.dart
+++ b/example/ga.dart
@@ -21,7 +21,7 @@
String ua = args.isEmpty ? DEFAULT_UA : args.first;
- Analytics ga = await Analytics.create(ua, 'ga_test', '1.0');
+ Analytics ga = await Analytics.create(ua, 'ga_test', '3.0');
ga.sendScreenView('home').then((_) {
return ga.sendScreenView('files');
diff --git a/lib/src/usage_impl_flutter.dart b/lib/src/usage_impl_flutter.dart
index 58f90a3..d6b7a05 100644
--- a/lib/src/usage_impl_flutter.dart
+++ b/lib/src/usage_impl_flutter.dart
@@ -12,6 +12,7 @@
import '../usage.dart';
import 'usage_impl.dart';
+import 'usage_impl_io.dart';
Future<Analytics> createAnalytics(
String trackingId,
@@ -39,18 +40,17 @@
}
String _createUserAgent() {
- // Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en)
- // Dart/1.8.0-edge.41170 (macos; macos; macos; null)
- String os = Platform.operatingSystem;
- String locale = Platform.environment['LANG'];
- return "Dart/${_dartVersion()} (${os}; ${os}; ${os}; ${locale})";
-}
+ final String locale = getPlatformLocale() ?? '';
-String _dartVersion() {
- String ver = Platform.version;
- int index = ver.indexOf(' ');
- if (index != -1) ver = ver.substring(0, index);
- return ver;
+ if (Platform.isAndroid) {
+ return 'Mozilla/5.0 (Android; Mobile; ${locale})';
+ } else if (Platform.isIOS) {
+ return 'Mozilla/5.0 (iPhone; U; CPU iPhone OS like Mac OS X; ${locale})';
+ } else {
+ // Dart/1.8.0 (macos; macos; macos; en_US)
+ final String os = Platform.operatingSystem;
+ return "Dart/${getDartVersion()} (${os}; ${os}; ${os}; ${locale})";
+ }
}
class FlutterPostHandler extends PostHandler {
@@ -60,10 +60,6 @@
FlutterPostHandler({HttpClient this.mockClient}) : _userAgent = _createUserAgent();
Future sendPost(String url, Map<String, dynamic> parameters) {
- // Add custom parameters for OS and the Dart version.
- parameters['cd1'] = Platform.operatingSystem;
- parameters['cd2'] = 'dart ${_dartVersion()}';
-
String data = postEncode(parameters);
Map<String, String> headers = <String, String>{ 'User-Agent': _userAgent };
@@ -75,6 +71,7 @@
class FlutterPersistentProperties extends PersistentProperties {
File _file;
Map _map;
+
FlutterPersistentProperties(String name, this._file, this._map) : super(name);
dynamic operator[](String key) => _map[key];
diff --git a/lib/src/usage_impl_io.dart b/lib/src/usage_impl_io.dart
index fff224a..358f204 100644
--- a/lib/src/usage_impl_io.dart
+++ b/lib/src/usage_impl_io.dart
@@ -39,18 +39,18 @@
}
String _createUserAgent() {
+ final String locale = getPlatformLocale() ?? '';
+
if (Platform.isMacOS) {
- return 'Mozilla/5.0 (Macintosh; Intel Mac OS X)';
- } else if (Platform.isMacOS) {
- return 'Mozilla/5.0 (Windows; Windows)';
+ return 'Mozilla/5.0 (Macintosh; Intel Mac OS X; Macintosh; ${locale})';
+ } else if (Platform.isWindows) {
+ return 'Mozilla/5.0 (Windows; Windows; Windows; ${locale})';
} else if (Platform.isLinux) {
- return 'Mozilla/5.0 (Linux; Linux)';
+ return 'Mozilla/5.0 (Linux; Linux; Linux; ${locale})';
} else {
- // Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en)
- // Dart/1.8.0-edge.41170 (macos; macos; macos; null)
+ // Dart/1.8.0 (macos; macos; macos; en_US)
String os = Platform.operatingSystem;
- String locale = Platform.environment['LANG'];
- return "Dart/${_dartVersion()} (${os}; ${os}; ${os}; ${locale})";
+ return "Dart/${getDartVersion()} (${os}; ${os}; ${os}; ${locale})";
}
}
@@ -60,7 +60,7 @@
return value == null ? '.' : value;
}
-String _dartVersion() {
+String getDartVersion() {
String ver = Platform.version;
int index = ver.indexOf(' ');
if (index != -1) ver = ver.substring(0, index);
@@ -74,10 +74,6 @@
IOPostHandler({HttpClient this.mockClient}) : _userAgent = _createUserAgent();
Future sendPost(String url, Map<String, dynamic> parameters) async {
- // Add custom parameters for OS and the Dart version.
- parameters['cd1'] = Platform.operatingSystem;
- parameters['cd2'] = 'dart ${_dartVersion()}';
-
String data = postEncode(parameters);
HttpClient client = mockClient != null ? mockClient : new HttpClient();
@@ -129,3 +125,22 @@
} catch (_) { }
}
}
+
+/// Return the string for the platform's locale; return's `null` if the locale
+/// can't be determined.
+String getPlatformLocale() {
+ String locale = Platform.environment['LANG'];
+ if (locale == null) return null;
+
+ if (locale != null) {
+ // Convert `en_US.UTF-8` to `en_US`.
+ int index = locale.indexOf('.');
+ if (index != null) locale = locale.substring(0, index);
+
+ // Convert `en_US` to `en`.
+ index = locale.indexOf('_');
+ if (index != null) locale = locale.substring(0, index);
+ }
+
+ return locale;
+}
diff --git a/test/usage_impl_io_test.dart b/test/usage_impl_io_test.dart
index 31e8ac8..98da432 100644
--- a/test/usage_impl_io_test.dart
+++ b/test/usage_impl_io_test.dart
@@ -39,6 +39,16 @@
expect(props['foo'], null);
});
});
+
+ group('usage_impl_io', () {
+ test('getPlatformLocale', () {
+ expect(getPlatformLocale(), isNotNull);
+ });
+
+ test('getDartVersion', () {
+ expect(getDartVersion(), isNotNull);
+ });
+ });
}
class MockHttpClient implements HttpClient {
diff --git a/tool/travis.sh b/tool/travis.sh
index e6f3aca..a3f3082 100755
--- a/tool/travis.sh
+++ b/tool/travis.sh
@@ -15,11 +15,7 @@
test/all.dart
# Run the tests.
-dart --conditional_directives -c test/all.dart
-
-# Run the UI/web tests as well.
-#pub build test
-#pub run grinder:test build/test/web.html
+dart -c test/all.dart
# Measure the size of the compiled JS, for the dart:html version of the library.
dart tool/grind.dart build