Skip to content

Commit 23f0d18

Browse files
Prevent _gtagEvent from being called in a non-release builds (#4841)
* Prevent _gtagEvent from being called in a non-release builds * fixes * add missing new line
1 parent 76f17d9 commit 23f0d18

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

packages/devtools_app/lib/src/analytics/_analytics_web.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ class GtagEventDevTools extends GtagEvent {
171171
GtagEventDevTools _gtagEvent({
172172
String? event_category,
173173
String? event_label,
174-
String? Function()? send_to,
174+
String? send_to,
175175
bool non_interaction = false,
176176
int value = 0,
177177
ScreenAnalyticsMetrics? screenMetrics,
178178
}) {
179179
return GtagEventDevTools(
180180
event_category: event_category,
181181
event_label: event_label,
182-
send_to: send_to?.call(),
182+
send_to: send_to,
183183
non_interaction: non_interaction,
184184
value: value,
185185
user_app: userAppType,
@@ -385,10 +385,10 @@ void screen(
385385
]) {
386386
GTag.event(
387387
screenName,
388-
_gtagEvent(
388+
gaEventProvider: () => _gtagEvent(
389389
event_category: analytics_constants.screenViewEvent,
390390
value: value,
391-
send_to: () => gaDevToolsPropertyId(),
391+
send_to: gaDevToolsPropertyId(),
392392
),
393393
);
394394
}
@@ -528,11 +528,11 @@ void _timing(
528528
}) {
529529
GTag.event(
530530
screenName,
531-
_gtagEvent(
531+
gaEventProvider: () => _gtagEvent(
532532
event_category: analytics_constants.timingEvent,
533533
event_label: timedOperation,
534534
value: durationMicros,
535-
send_to: () => gaDevToolsPropertyId(),
535+
send_to: gaDevToolsPropertyId(),
536536
screenMetrics: screenMetrics,
537537
),
538538
);
@@ -547,12 +547,12 @@ void select(
547547
}) {
548548
GTag.event(
549549
screenName,
550-
_gtagEvent(
550+
gaEventProvider: () => _gtagEvent(
551551
event_category: analytics_constants.selectEvent,
552552
event_label: selectedItem,
553553
value: value,
554554
non_interaction: nonInteraction,
555-
send_to: () => gaDevToolsPropertyId(),
555+
send_to: gaDevToolsPropertyId(),
556556
screenMetrics:
557557
screenMetricsProvider != null ? screenMetricsProvider() : null,
558558
),
@@ -571,7 +571,7 @@ void reportError(
571571
_lastGaError = errorMessage;
572572

573573
GTag.exception(
574-
_gtagException(
574+
gaExceptionProvider: () => _gtagException(
575575
errorMessage,
576576
fatal: fatal,
577577
screenMetrics:

packages/devtools_app/lib/src/ui/gtags.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,23 @@ class GTag {
2929
static const String _event = 'event';
3030
static const String _exception = 'exception';
3131

32+
static bool get shouldSendAnalytics => kReleaseMode || _debugAnalytics;
33+
3234
/// Collect the analytic's event and its parameters.
33-
static void event(String eventName, GtagEvent gaEvent) async {
34-
if (kReleaseMode || _debugAnalytics) {
35-
if (await ga.isAnalyticsEnabled()) {
36-
_gTagCommandName(_event, eventName, gaEvent);
37-
}
35+
static void event(
36+
String eventName, {
37+
required GtagEvent Function() gaEventProvider,
38+
}) async {
39+
if (shouldSendAnalytics && await ga.isAnalyticsEnabled()) {
40+
_gTagCommandName(_event, eventName, gaEventProvider());
3841
}
3942
}
4043

41-
static void exception(GtagException gaException) async {
42-
if (await ga.isAnalyticsEnabled()) {
43-
_gTagCommandName(_event, _exception, gaException);
44+
static void exception({
45+
required GtagException Function() gaExceptionProvider,
46+
}) async {
47+
if (shouldSendAnalytics && await ga.isAnalyticsEnabled()) {
48+
_gTagCommandName(_event, _exception, gaExceptionProvider());
4449
}
4550
}
4651
}

0 commit comments

Comments
 (0)