gtag_analytics 0.1.4 copy "gtag_analytics: ^0.1.4" to clipboard
gtag_analytics: ^0.1.4 copied to clipboard

outdatedDart 1 only

A minimal Google Analytics interop library.

gtag_analytics #

A library for Google Analytics tracking through the gtag function.

Usage #

Add the gtag Google Analytics tracking code to your HTML:

<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-123456-42"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-123456-42');
</script>

In Dart, import this package.

import 'package:gtag_analytics/gtag_analytics.dart';

Create an instance of the GoogleAnalytics class:

final ga = new GoogleAnalytics();

Or, if you want to ignore errors:

final ga = new GoogleAnalytics(failSilently: true);

Use the instance to send data:

ga.sendPageView();
ga.sendException("Exception: $e", fatal: true);
ga.sendSignUp(method: "email");
ga.sendCustom("play_video");

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

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 #

Please file feature requests and bugs at the issue tracker. Pull requests welcome.

3
likes
0
pub points
42%
popularity

Publisher

unverified uploader

A minimal Google Analytics interop library.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

js, meta

More

Packages that depend on gtag_analytics