Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Unified Diff: packages/usage/example/example.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/usage/changelog.md ('k') | packages/usage/example/example.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/usage/example/example.dart
diff --git a/packages/usage/example/example.dart b/packages/usage/example/example.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d570341621a7fe9f6241844169dc7b9235929b1c
--- /dev/null
+++ b/packages/usage/example/example.dart
@@ -0,0 +1,47 @@
+// Copyright (c) 2015, 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.
+
+/**
+ * A simple web app to hand-test the usage library.
+ */
+library usage_example;
+
+import 'dart:html';
+
+import 'package:usage/usage_html.dart';
+
+Analytics _analytics;
+String _lastUa;
+int _count = 0;
+
+void main() {
+ querySelector('#foo').onClick.listen((_) => _handleFoo(getAnalytics()));
+ querySelector('#bar').onClick.listen((_) => _handleBar(getAnalytics()));
+ querySelector('#page').onClick.listen((_) => _changePage(getAnalytics()));
+}
+
+String _ua() => (querySelector('#ua') as InputElement).value.trim();
+
+Analytics getAnalytics() {
+ if (_analytics == null || _lastUa != _ua()) {
+ _lastUa = _ua();
+ _analytics = new AnalyticsHtml(_lastUa, 'Test app', '1.0');
+ _analytics.sendScreenView(window.location.pathname);
+ }
+
+ return _analytics;
+}
+
+void _handleFoo(Analytics analytics) {
+ analytics.sendEvent('main', 'foo');
+}
+
+void _handleBar(Analytics analytics) {
+ analytics.sendEvent('main', 'bar');
+}
+
+void _changePage(Analytics analytics) {
+ window.history.pushState(null, 'new page', '${++_count}.html');
+ analytics.sendScreenView(window.location.pathname);
+}
« no previous file with comments | « packages/usage/changelog.md ('k') | packages/usage/example/example.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698