Getting started
Our Flutter SDK lets you collect user data from mobile apps. It contains over 30 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 account address. Example:
https://example.piwik.pro
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: ^0.0.1
- (Optional) Your editor might support
dart pub get
orflutter 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. Use your account address (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 without configuring the tracker first will result in an error, which you can handle 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 will return a string describing the method called and the parameters used, unless stated otherwise. For example:
FlutterPiwikPro - configureTracker completed with parameters: baseURL: https://example.piwik.pro/, siteId: 01234567-89ab-cdef-0123-456789abcdef
Updated 15 days ago