Getting started
Our Flutter SDK lets you collect user data from mobile apps. It contains over 40 methods that make it easy to track screen views, goals, ecommerce orders and more. To get started, you need to set up your account in Piwik PRO, install our library and set up the tracker.
Set up Piwik PRO
Before you install our library for Flutter, you need to set up Piwik PRO. Here's what you need to do:
- Log in to Piwik PRO.
- Go to Menu > Administration.
- Navigate to Sites & apps.
- Click Add a site or app.
- Type the app name and address, and click Save.
- Set the time zone and currency.
- Note the site/app ID. The ID is under the app name. Example:
00000000-0000-0000-0000-000000000000. - Note your tracking endpoint URL. This is the base URL where the SDK sends collected events. By default, this is the same as your Piwik PRO instance address (for example,
https://example.piwik.pro). If your organization uses a custom tracking endpoint, check with your Piwik PRO administrator.
Install the library
To install the library with Flutter or Dart, follow these steps:
- Run the following command:
$ flutter pub add flutter_piwikpro$ dart pub add flutter_piwikpro- This adds a line to your package’s pubspec.yaml and automatically runs
dart pub get:
dependencies:
flutter_piwikpro: ^2.1.1- (Optional) Your editor might support
dart pub getorflutter pub get. Check the docs for your editor to learn more. - Now in your Dart code, you can use the following method:
import 'package:flutter_piwikpro/flutter_piwikpro.dart';Set up the tracker
To set up the Piwik PRO tracker, follow these steps:
- Run the following command. Provide your tracking endpoint URL, which is the base URL where the SDK posts events, for example, (
https://example.piwik.pro/) and the site/app ID (Where to find it?).
await FlutterPiwikPro.sharedInstance.configureTracker(baseURL: 'https://example.piwik.pro/', siteId: '01234567-89ab-cdef-0123-456789abcdef');How to use our SDK
All SDK methods are asynchronous and can throw exceptions. For example, calling SDK methods before configuring the tracker results in an error. You can handle this error with a standard try-catch block. See the example below:
try {
final result =
await FlutterPiwikPro.sharedInstance.trackDownload('http://your.server.com/bonusmap2.zip');
print(result);
} catch (exception) {
//handle an exception
}If a method call is successful, most methods return a string that describes the called method and the parameters used, unless stated otherwise. For example:
FlutterPiwikPro - configureTracker completed with parameters: baseURL: https://example.piwik.pro/, siteId: 01234567-89ab-cdef-0123-456789abcdefUpdated 10 days ago