Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Playground] [Frontend] Migrate Playground to Google Analytics 4 #24957

Merged
merged 51 commits into from
Apr 12, 2023
Merged
Changes from 3 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
daa56b5
removed goToContextLine
Jan 10, 2023
e143de9
PG analytics refactoring (#24901) (#24924):
Jan 10, 2023
6ae97ef
AnalyticsCategories, AnalyticsEvents (#24924)
Jan 10, 2023
50adca2
comment fixes (#24924)
Jan 10, 2023
74531cb
renamed playground demo widget (#24924)
Jan 10, 2023
50b1fba
tob analytics, generic analytics, events, categories (#24924)
Jan 12, 2023
61a7764
deleted GenericAnalyticsService (#24924)
Jan 13, 2023
5057195
trackRunExample usage (#24924)
Jan 13, 2023
a3b8460
added events (#24924)
Jan 16, 2023
a8316c3
Merge branch 'master' into issue24924-tobf-analytics
Jan 17, 2023
d29eb80
new pubspec.lock (#24924)
Jan 17, 2023
de999f1
open and complete unit event implementations (#24924)
Jan 17, 2023
5981c6b
time spent in unit on close (#24924)
Jan 23, 2023
9b67020
on before load to track time on close (#24924)
Jan 23, 2023
324137f
_onTabClosed (#24924)
Jan 23, 2023
866bbb1
Merge master
Jan 24, 2023
e2e270d
comment fixes (#24924)
Jan 26, 2023
6084e18
Merge branch 'master' into issue24924-tobf-analytics
Feb 6, 2023
5b06e3f
comment fixes (#24924)
Feb 7, 2023
3c481b3
made test tasks work (#24924)
Feb 7, 2023
c007d6f
Use Google Analytics 4 JS in Playground (#24924)
alexeyinkin Feb 9, 2023
4c1932e
Update staging URLs and Google Analytics property ID (#24924)
alexeyinkin Feb 9, 2023
c496f09
Fix Playground integation tests (#24924)
alexeyinkin Feb 9, 2023
e68e03c
Disable old Tour of Beam analytics (#24924)
alexeyinkin Feb 9, 2023
004de5d
Clean up (#24924)
alexeyinkin Feb 9, 2023
bec4342
Fix notifying when window closes (#24924)
alexeyinkin Feb 10, 2023
19d9de6
Submit page layout to analytics (#24924)
alexeyinkin Feb 10, 2023
b1dd4a2
Address review comments (#24924)
alexeyinkin Feb 10, 2023
bbd2e38
Merge branch 'master' into issue24924-tobf-analytics
alexeyinkin Feb 10, 2023
42c9d32
Upgrade Flutter to 3.7.2 (#24924)
alexeyinkin Feb 14, 2023
1090e73
Merge branch 'issue24924_flutter37' into issue24924-tobf-analytics
alexeyinkin Feb 14, 2023
de115db
Merge remote-tracking branch 'apache/master' into issue24924-tobf-ana…
alexeyinkin Feb 14, 2023
02b56f7
Upgrade integration tests to Flutter 3.7.3
alexeyinkin Feb 14, 2023
71d26ac
Clean up (#24924)
alexeyinkin Feb 14, 2023
ea7c165
Merge remote-tracking branch 'origin/master' into issue24924-tobf-ana…
alexeyinkin Feb 16, 2023
bbd7024
Use the production Google Analytics property, rename event parameters…
alexeyinkin Feb 22, 2023
ec1f7df
Add LoadedAnalyticsEvent (#24924)
alexeyinkin Feb 23, 2023
45a1fc3
Fix (#24924)
alexeyinkin Feb 23, 2023
7b14534
[Tour of Beam] [Frontend] Tour of Beam Analytics (#431)
nausharipov Feb 27, 2023
ed1fac5
Fix Run hot key (#24924)
alexeyinkin Mar 7, 2023
385132c
Address review comments (#24924)
alexeyinkin Mar 9, 2023
cd79651
Added comments (#24924)
alexeyinkin Mar 10, 2023
fb34d74
Added comments (#24924)
alexeyinkin Mar 10, 2023
183fb61
Add comments (#24924)
alexeyinkin Mar 10, 2023
df7700c
Merge remote-tracking branch 'apache/master' into issue24924-tobf-ana…
alexeyinkin Mar 10, 2023
08f05a8
Fix SDK switching (#24924)
alexeyinkin Mar 10, 2023
2ca8e2c
Fix integration tests (#24924)
alexeyinkin Mar 13, 2023
34310a3
Test analytics events for feedback, report issue, and external url na…
alexeyinkin Mar 14, 2023
2966768
Merge remote-tracking branch 'apache/master' into issue24924-tobf-ana…
alexeyinkin Mar 28, 2023
fbefe85
Fix tests (#24924)
alexeyinkin Mar 28, 2023
9eb41e7
Differentiate production and dev analytics (#24924)
alexeyinkin Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -48,7 +48,6 @@ class PlaygroundDemoWidget extends StatelessWidget {
first: SnippetEditor(
controller: snippetController,
isEditable: true,
goToContextLine: false,
),
second: OutputWidget(
playgroundController: playgroundController,
Original file line number Diff line number Diff line change
@@ -17,9 +17,10 @@
*/

import 'package:flutter_test/flutter_test.dart';
import 'package:playground/modules/analytics/analytics_event.dart';
import 'package:playground/modules/analytics/analytics_events.dart';
import 'package:playground/modules/analytics/analytics_service.dart';
import 'package:playground/modules/analytics/categories.dart';
import 'package:playground/modules/analytics/events.dart';
import 'package:playground/modules/analytics/service.dart';
import 'package:playground_components/playground_components.dart';

import '../common/common_finders.dart';

@@ -58,13 +59,12 @@ Future<void> _checkEnjoyingAndSendFeedback(WidgetTester wt) async {
await wt.tap(find.feedbackDropdownSendButton());
await wt.pumpAndSettle();

final context = wt.element(find.feedbackThumbUp());
final lastSentEvent = AnalyticsService.get(context).lastSentEvent;
final lastSentEvent = AnalyticsService.get().lastSentEvent;
expect(
lastSentEvent,
AnalyticsEvent(
category: kFeedbackCategory,
action: kClickSendFeedbackEvent,
category: AnalyticsCategories.feedback,
action: AnalyticsEvents.clickSendPositiveFeedback,
label: text,
),
);
@@ -87,13 +87,12 @@ Future<void> _checkNotEnjoyingAndSendFeedback(WidgetTester wt) async {
await wt.tap(find.feedbackDropdownSendButton());
await wt.pumpAndSettle();

final context = wt.element(find.feedbackThumbDown());
final lastSentEvent = AnalyticsService.get(context).lastSentEvent;
final lastSentEvent = AnalyticsService.get().lastSentEvent;
expect(
lastSentEvent,
AnalyticsEvent(
category: kFeedbackCategory,
action: kClickSendFeedbackEvent,
category: AnalyticsCategories.feedback,
action: AnalyticsEvents.clickSendNegativeFeedback,
label: text,
),
);
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ import 'package:flutter/widgets.dart';
import 'package:playground_components/playground_components.dart';
import 'package:provider/provider.dart';

import '../modules/analytics/analytics_service.dart';
import '../modules/analytics/service.dart';
import '../utils/analytics_utils.dart';

class PlaygroundRunOrCancelButton extends StatelessWidget {
@@ -29,29 +29,28 @@ class PlaygroundRunOrCancelButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Consumer<PlaygroundController>(
builder: (context, playgroundController, child) {
final analyticsService = AnalyticsService.get(context);
final stopwatch = Stopwatch();
final exampleName = getAnalyticsExampleName(playgroundController);
builder: (context, playgroundController, child) {
final analyticsService = AnalyticsService.get();
final stopwatch = Stopwatch();
final exampleName = getAnalyticsExampleName(playgroundController);

return RunOrCancelButton(
playgroundController: playgroundController,
beforeCancel: () {
final exampleName = getAnalyticsExampleName(playgroundController);
analyticsService.trackClickCancelRunEvent(exampleName);
},
beforeRun: () {
stopwatch.start();
analyticsService.trackClickRunEvent(exampleName);
},
onComplete: () {
analyticsService.trackRunTimeEvent(
exampleName,
stopwatch.elapsedMilliseconds,
);
},
);
}
);
return RunOrCancelButton(
playgroundController: playgroundController,
beforeCancel: () {
final exampleName = getAnalyticsExampleName(playgroundController);
analyticsService.trackClickCancelRunEvent(exampleName);
},
beforeRun: () {
stopwatch.start();
analyticsService.trackClickRunEvent(exampleName);
},
onComplete: () {
analyticsService.trackRunTimeEvent(
exampleName,
stopwatch.elapsedMilliseconds,
);
},
);
});
}
}
6 changes: 6 additions & 0 deletions playground/frontend/lib/locator.dart
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@

import 'package:app_state/app_state.dart';
import 'package:get_it/get_it.dart';
import 'package:playground/modules/analytics/google_analytics_service.dart';
import 'package:playground_components/playground_components.dart';

import 'config.g.dart';
@@ -28,6 +29,7 @@ import 'router/route_information_parser.dart';
Future<void> initializeServiceLocator() async {
_initializeRepositories();
_initializeState();
_initializeAnalyticsService();
}

void _initializeRepositories() {
@@ -57,3 +59,7 @@ void _initializeState() {
),
);
}

void _initializeAnalyticsService() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void _initializeAnalyticsService() {
void _initializeServices() {

GetIt.instance.registerSingleton(GoogleAnalyticsService());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can register a single object under two handles:

Suggested change
GetIt.instance.registerSingleton(GoogleAnalyticsService());
GetIt.instance.registerSingleton<AnalyticsService>(service);
GetIt.instance.registerSingleton<PlaygroundAnalyticsService>(service);

This way playground_components will request <AnalyticsService> and be able to submit generic events, while Playground and ToB will fetch their own subclasses to submit their specific events.

}
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:playground/modules/analytics/analytics_service.dart';
import 'package:playground/modules/analytics/service.dart';
import 'package:playground/modules/shortcuts/constants/global_shortcuts.dart';
import 'package:playground_components/playground_components.dart';
import 'package:url_launcher/url_launcher.dart';
@@ -38,7 +38,7 @@ class NewExampleAction extends StatelessWidget {
label: 'intents.playground.newExample'.tr(),
onPressed: () {
launchUrl(Uri.parse('/'));
AnalyticsService.get(context).trackClickNewExample();
AnalyticsService.get().trackClickNewExample();
},
),
);
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
*/

import 'package:flutter/material.dart';
import 'package:playground/modules/analytics/analytics_service.dart';
import 'package:playground/modules/analytics/service.dart';
import 'package:playground_components/playground_components.dart';
import 'package:provider/provider.dart';

@@ -26,7 +26,7 @@ class ResetAction extends StatelessWidget {

@override
Widget build(BuildContext context) {
final analyticsService = AnalyticsService.get(context);
final analyticsService = AnalyticsService.get();
return Consumer<PlaygroundController>(
builder: (context, playgroundController, child) => ResetButton(
playgroundController: playgroundController,
38 changes: 0 additions & 38 deletions playground/frontend/lib/modules/analytics/analytics_events.dart

This file was deleted.

26 changes: 26 additions & 0 deletions playground/frontend/lib/modules/analytics/categories.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY IND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

class AnalyticsCategories {
static const sdk = 'SDK';
static const example = 'Example';
static const common = 'Common';
static const link = 'Link';
static const feedback = 'Feedback';
static const runCode = 'Run Code';
}
34 changes: 34 additions & 0 deletions playground/frontend/lib/modules/analytics/events.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY IND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

class AnalyticsEvents {
static const selectSdk = 'select_new_sdk';
static const selectExample = 'select_new_example';
static const clickNewExample = 'click_new_example';
static const clickReset = 'click_reset';
static const clickToggleTheme = 'click_toggle_theme';
static const openShortcutsModal = 'open_shortcuts_modal';
static const openLink = 'open_link';
static const clickEnjoyPlayground = 'click_enjoy_playground';
static const clickRun = 'click_run';
static const clickCancelRun = 'click_cancel_run';
static const runTime = 'run_time';
static const clickReportIssue = 'click_report_issue';
static const clickSendPositiveFeedback = 'click_send_positive_feedback';
static const clickSendNegativeFeedback = 'click_send_negative_feedback';
}
Loading