| Index: packages/usage/lib/src/usage_impl_html.dart
|
| diff --git a/packages/usage/lib/src/usage_impl_html.dart b/packages/usage/lib/src/usage_impl_html.dart
|
| index e3f64968fe1f23623253cc27bddc046bf9970ad4..c15cde6ce4159c1121b05991521c5a957606db13 100644
|
| --- a/packages/usage/lib/src/usage_impl_html.dart
|
| +++ b/packages/usage/lib/src/usage_impl_html.dart
|
| @@ -2,19 +2,43 @@
|
| // 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 usage_impl_html;
|
| -
|
| import 'dart:async';
|
| import 'dart:convert' show JSON;
|
| import 'dart:html';
|
|
|
| import 'usage_impl.dart';
|
|
|
| +/// An interface to a Google Analytics session, suitable for use in web apps.
|
| +///
|
| +/// [analyticsUrl] is an optional replacement for the default Google Analytics
|
| +/// URL (`https://www.google-analytics.com/collect`).
|
| +class AnalyticsHtml extends AnalyticsImpl {
|
| + AnalyticsHtml(
|
| + String trackingId, String applicationName, String applicationVersion,
|
| + {String analyticsUrl})
|
| + : super(trackingId, new HtmlPersistentProperties(applicationName),
|
| + new HtmlPostHandler(),
|
| + applicationName: applicationName,
|
| + applicationVersion: applicationVersion,
|
| + analyticsUrl: analyticsUrl) {
|
| + int screenWidth = window.screen.width;
|
| + int screenHeight = window.screen.height;
|
| +
|
| + setSessionValue('sr', '${screenWidth}x$screenHeight');
|
| + setSessionValue('sd', '${window.screen.pixelDepth}-bits');
|
| + setSessionValue('ul', window.navigator.language);
|
| + }
|
| +}
|
| +
|
| +typedef Future<HttpRequest> HttpRequestor(String url,
|
| + {String method, sendData});
|
| +
|
| class HtmlPostHandler extends PostHandler {
|
| - final Function mockRequestor;
|
| + final HttpRequestor mockRequestor;
|
|
|
| - HtmlPostHandler({Function this.mockRequestor});
|
| + HtmlPostHandler({this.mockRequestor});
|
|
|
| + @override
|
| Future sendPost(String url, Map<String, dynamic> parameters) {
|
| int viewportWidth = document.documentElement.clientWidth;
|
| int viewportHeight = document.documentElement.clientHeight;
|
| @@ -22,12 +46,16 @@ class HtmlPostHandler extends PostHandler {
|
| parameters['vp'] = '${viewportWidth}x$viewportHeight';
|
|
|
| String data = postEncode(parameters);
|
| - var request = mockRequestor == null ? HttpRequest.request : mockRequestor;
|
| - return request(url, method: 'POST', sendData: data).catchError((e) {
|
| + HttpRequestor requestor =
|
| + mockRequestor == null ? HttpRequest.request : mockRequestor;
|
| + return requestor(url, method: 'POST', sendData: data).catchError((e) {
|
| // Catch errors that can happen during a request, but that we can't do
|
| - // anything about, e.g. a missing internet conenction.
|
| + // anything about, e.g. a missing internet connection.
|
| });
|
| }
|
| +
|
| + @override
|
| + void close() {}
|
| }
|
|
|
| class HtmlPersistentProperties extends PersistentProperties {
|
| @@ -39,9 +67,11 @@ class HtmlPersistentProperties extends PersistentProperties {
|
| _map = JSON.decode(str);
|
| }
|
|
|
| - dynamic operator[](String key) => _map[key];
|
| + @override
|
| + dynamic operator [](String key) => _map[key];
|
|
|
| - void operator[]=(String key, dynamic value) {
|
| + @override
|
| + void operator []=(String key, dynamic value) {
|
| if (value == null) {
|
| _map.remove(key);
|
| } else {
|
| @@ -50,4 +80,7 @@ class HtmlPersistentProperties extends PersistentProperties {
|
|
|
| window.localStorage[name] = JSON.encode(_map);
|
| }
|
| +
|
| + @override
|
| + void syncSettings() {}
|
| }
|
|
|