The Piano Analytics Flutter SDK allows you to collect audience measurement data for the Piano Analytics solution. It can be used with Flutter applications.
This SDK makes the implementation of Piano Analytics as simple as possible, while keeping all the flexibility of the solution. By using this plugin in your applications, and using dedicated and documented methods, you will be able to send powerful events.
-
Add this to your pubspec.yaml file:
dependencies: piano_analytics: ^1.0.1
-
Install the plugin using the command
flutter pub get
Initialize PianoAnalytics with your site and collect domain in your application initialization
import 'package:piano_analytics/piano_analytics.dart';
import 'package:piano_analytics/enums.dart';
...
class _MyAppState extends State<MyApp> {
final _pianoAnalytics = PianoAnalytics(
site: 123456789,
collectDomain: "xxxxxxx.pa-cd.com",
visitorIDType: VisitorIDType.uuid,
storageLifetimeVisitor: 395,
visitorStorageMode: VisitorStorageMode.fixed,
ignoreLimitedAdvertisingTracking: true,
visitorId: "WEB-192203AJ"
);
@override
void initState() {
super.initState();
initPlugins();
}
Future<void> initPlugins() async {
...
await _pianoAnalytics.init();
}
...
}
await _pianoAnalytics.sendEvents(events: [
Event(name: "page.display", properties: [
Property.bool(name: "bool", value: true),
Property.int(name: "int", value: 1),
Property.int(name: "long", value: 9007199254740992),
Property.double(name: "double", value: 1.0),
Property.string(name: "string", value: "value"),
Property.date(name: "date", value: DateTime.now()),
Property.intArray(name: "intArray", value: [1, 2, 3]),
Property.doubleArray(name: "doubleArray", value: [1.0, 2.0, 3.0]),
Property.stringArray(name: "stringArray", value: ["a", "b", "c"])
])
]);
You can get/set/delete a user
var user = await _pianoAnalytics.getUser();
await _pianoAnalytics.setUser(
id: "WEB-192203AJ",
category: "premium",
enableStorage: false
);
await _pianoAnalytics.deleteUser();
You can get/set visitor ID (only for VisitorIDType.custom
)
var user = await _pianoAnalytics.getVisitorId();
await _pianoAnalytics.setVisitorId(
visitorId: "WEB-192203AJ"
);
You can change privacy parameters
await _pianoAnalytics.privacyIncludeStorageFeatures(
features: [
PrivacyStorageFeature.crash,
PrivacyStorageFeature.visitor
],
modes: [
PrivacyMode.custom
]
);
await _pianoAnalytics.privacyExcludeStorageFeatures(
features: [
PrivacyStorageFeature.crash,
PrivacyStorageFeature.visitor
],
modes: [
PrivacyMode.custom
]
);
await _pianoAnalytics.privacyIncludeProperties(
propertyNames: [
"allowed_property_1",
"allowed_property_2"
],
modes: [
PrivacyMode.custom
],
eventNames: [
"page.display",
"click.action"
]
);
await _pianoAnalytics.privacyExcludeProperties(
propertyNames: [
"forbidden_property_1",
"forbidden_property_2"
],
modes: [
PrivacyMode.custom
]
);
await _pianoAnalytics.privacyIncludeEvents(
eventNames: ["page.display"],
modes: [PrivacyMode.custom]
);
await _pianoAnalytics.privacyExcludeEvents(
eventNames: ["click.action"],
modes: [PrivacyMode.custom]
);
Important: Initialize PianoConsents before initializing PianoAnalytics
Use the piano_consents package