Read more about these events and their fields in the official
documentation.

Only throwing in development, not in production

While analytics is important, you probably don't want it to break your whole
app when something is wrong in the measurement code. And since calling out to
gtag can go wrong for a number of reasons (forgotten tracking snippet
in HTML, gtag not defined in time, etc.), this package provides
a "keep on trucking" mode.

You can ignore errors by constructing the GoogleAnalytics class like this:

final ga = new GoogleAnalytics(failSilently: true);

The more realistic approach is to use an environment variable to switch this
behavior on and off depending on whether the code is running in development or
in production mode:

Then make sure you're building your production code with production=true,
like this:

pub build --define production=true

You could also go the other way around, and use something like
development=true. That way, you won't accidentally deploy a version that fails
on Google Analytics when you forget to provide the production=true option
on pub build.
(On the other hand, you might unknowingly be ignoring a valid error when you
forget to provide the development=true option in development on pub serve.)

Testing

Most of the functionality lives in the Google Analytics JavaScript code,
but there are some tests that cover the wrapper. They will only work
in a browser, so you'll have to run them with the -p option, like
this:

pub run test -p chrome

Features and bugs

0.1.7+2

Dart 2 compatibility

0.1.6

Add Travis CI testing

example/gtag_analytics_example.dart

// Copyright (c) 2017, filiph. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.
import 'package:gtag_analytics/gtag_analytics.dart';
void main() {
final inProduction = const String.fromEnvironment('production') == 'true';
final ga = new GoogleAnalytics(failSilently: inProduction);
ga.sendCustom('choose_action', category: 'play');
}