This is an automated email from the ASF dual-hosted git repository. pabloem pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push: new 402bb56 Merge pull request #16283 from [BEAM-13448] [Playground] track run code time to the analytics 402bb56 is described below commit 402bb56483148d8e09cdbc3fdd270493628a7cd4 Author: Aydar Farrakhov <stranni...@gmail.com> AuthorDate: Wed Dec 22 01:46:01 2021 +0300 Merge pull request #16283 from [BEAM-13448] [Playground] track run code time to the analytics * [BEAM-13448]: playground - track run time * [BEAM-13448]: remove pring * [BEAM-13448]: fix tracking run time example name --- .../frontend/lib/modules/analytics/analytics_events.dart | 1 + .../lib/modules/analytics/analytics_service.dart | 16 ++++++++++++++-- .../playground/components/editor_textarea_wrapper.dart | 12 +++++++++++- .../lib/pages/playground/states/playground_state.dart | 5 ++++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/playground/frontend/lib/modules/analytics/analytics_events.dart b/playground/frontend/lib/modules/analytics/analytics_events.dart index 0f747b8..cd68f24 100644 --- a/playground/frontend/lib/modules/analytics/analytics_events.dart +++ b/playground/frontend/lib/modules/analytics/analytics_events.dart @@ -32,4 +32,5 @@ const kOpenShortcutsModalEvent = 'open_shortcuts_modal'; const kOpenLinkEvent = 'open_link'; const kClickEnjoyPlaygroundEvent = 'click_enjoy_playground'; const kClickRunEvent = 'click_run'; +const kRunTimeEvent = 'run_time'; const kClickReportIssueEvent = 'click_report_issue'; diff --git a/playground/frontend/lib/modules/analytics/analytics_service.dart b/playground/frontend/lib/modules/analytics/analytics_service.dart index fc746ea..865191b 100644 --- a/playground/frontend/lib/modules/analytics/analytics_service.dart +++ b/playground/frontend/lib/modules/analytics/analytics_service.dart @@ -31,7 +31,7 @@ class AnalyticsService { _analytics = AnalyticsHtml(kAnalyticsUA, 'beam', '1.0'); } - static get(BuildContext context) { + static AnalyticsService get(BuildContext context) { return Provider.of<AnalyticsService>(context, listen: false); } @@ -99,12 +99,24 @@ class AnalyticsService { ); } - void safeSendEvent(String category, String action, {String? label}) { + void trackRunTimeEvent(String exampleName, int runTimeMs) { + safeSendEvent( + kRunCodeCategory, + kRunTimeEvent, + label: exampleName, + value: runTimeMs, + ); + } + + void safeSendEvent(String category, String action, + {String? label, int? value, Map<String, String>? parameters}) { try { _analytics.sendEvent( category, action, label: label, + value: value, + parameters: parameters, ); } catch (e) { // ignore analytics errors sync they don't affect app diff --git a/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart b/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart index 3e2e916..c5719ba 100644 --- a/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart +++ b/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart @@ -29,6 +29,7 @@ import 'package:playground/pages/playground/states/playground_state.dart'; import 'package:provider/provider.dart'; const kNotificationTitle = 'Run Code'; +const kUnknownExamplePrefix = 'Unknown Example'; class CodeTextAreaWrapper extends StatelessWidget { const CodeTextAreaWrapper({Key? key}) : super(key: key); @@ -67,7 +68,16 @@ class CodeTextAreaWrapper extends StatelessWidget { child: RunButton( isRunning: state.isCodeRunning, runCode: () { - state.runCode(); + final stopwatch = Stopwatch()..start(); + state.runCode( + onFinish: () { + AnalyticsService.get(context).trackRunTimeEvent( + state.selectedExample?.path ?? + '$kUnknownExamplePrefix, sdk ${state.sdk.displayName}', + stopwatch.elapsedMilliseconds, + ); + }, + ); AnalyticsService.get(context) .trackClickRunEvent(state.selectedExample); }, diff --git a/playground/frontend/lib/pages/playground/states/playground_state.dart b/playground/frontend/lib/pages/playground/states/playground_state.dart index 93747b0..b2021ca 100644 --- a/playground/frontend/lib/pages/playground/states/playground_state.dart +++ b/playground/frontend/lib/pages/playground/states/playground_state.dart @@ -110,7 +110,7 @@ class PlaygroundState with ChangeNotifier { _pipelineOptions = options; } - void runCode() { + void runCode({Function? onFinish}) { final parsedPipelineOptions = parsePipelineOptions(pipelineOptions); if (parsedPipelineOptions == null) { _result = RunCodeResult( @@ -136,6 +136,9 @@ class PlaygroundState with ChangeNotifier { ); _codeRepository?.runCode(request).listen((event) { _result = event; + if (event.isFinished && onFinish != null) { + onFinish(); + } notifyListeners(); }); }