Skip to content

Commit

Permalink
Merge pull request #2 from at-internet/develop
Browse files Browse the repository at this point in the history
v1.0.1
  • Loading branch information
alexey-troshkov authored Nov 6, 2024
2 parents c9dfd27 + 9b97cea commit 485be8b
Show file tree
Hide file tree
Showing 23 changed files with 1,571 additions and 812 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.0.1
* PianoConsents has been moved to the piano_consents package
* Added feature to specify property type via forceType argument
* Added new features for privacy customization
* Added new features for user customization
* Added feature for set visitorId

## 1.0.0

* Added plugins for PianoAnalytics and PianoConsents
253 changes: 160 additions & 93 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## About The Project

The Piano Analytics Apple SDK allows you to collect audience measurement data for the [Piano Analytics](https://piano.io/product/analytics/) solution.
The Piano Analytics Flutter SDK allows you to collect audience measurement data for the [Piano Analytics](https://piano.io/product/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](https://developers.atinternet-solutions.com/piano-analytics/), you will be able to send powerful events.
Expand All @@ -17,7 +17,7 @@ This SDK makes the implementation of Piano Analytics as simple as possible, whil
1. Add this to your pubspec.yaml file:
```yaml
dependencies:
piano_analytics: ^1.0.0
piano_analytics: ^1.0.1
```
2. Install the plugin using the command
Expand All @@ -27,102 +27,169 @@ This SDK makes the implementation of Piano Analytics as simple as possible, whil

## Usage

1. Initialize PianoAnalytics with your site and collect domain in your application initialization
```dart
import 'package:piano_analytics/piano_analytics.dart';
...
class _MyAppState extends State<MyApp> {
final _pianoAnalytics = PianoAnalytics(
site: 123456789,
collectDomain: "xxxxxxx.pa-cd.com"
);
@override
void initState() {
super.initState();
initPlugins();
}
Initialize PianoAnalytics with your site and collect domain in your application initialization
```dart
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();
}
Future<void> initPlugins() async {
...
await _pianoAnalytics.init();
}
```

2. Send events
```dart
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"])
])
]);
```
...
}
```

### Send events
```dart
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"])
])
]);
```

## User
You can get/set/delete a user

### Get user
```dart
var user = await _pianoAnalytics.getUser();
```

### Set user
```dart
await _pianoAnalytics.setUser(
id: "WEB-192203AJ",
category: "premium",
enableStorage: false
);
```

### Delete user
```dart
await _pianoAnalytics.deleteUser();
```

## Visitor ID
You can get/set visitor ID (*only for `VisitorIDType.custom`*)

### Get visitor ID
```dart
var user = await _pianoAnalytics.getVisitorId();
```

### Set visitor ID
```dart
await _pianoAnalytics.setVisitorId(
visitorId: "WEB-192203AJ"
);
```

## Privacy
You can change privacy parameters

### Include storage features
```dart
await _pianoAnalytics.privacyIncludeStorageFeatures(
features: [
PrivacyStorageFeature.crash,
PrivacyStorageFeature.visitor
],
modes: [
PrivacyMode.custom
]
);
```

### Exclude storage features
```dart
await _pianoAnalytics.privacyExcludeStorageFeatures(
features: [
PrivacyStorageFeature.crash,
PrivacyStorageFeature.visitor
],
modes: [
PrivacyMode.custom
]
);
```

### Include properties
```dart
await _pianoAnalytics.privacyIncludeProperties(
propertyNames: [
"allowed_property_1",
"allowed_property_2"
],
modes: [
PrivacyMode.custom
],
eventNames: [
"page.display",
"click.action"
]
);
```

### Exclude properties
```dart
await _pianoAnalytics.privacyExcludeProperties(
propertyNames: [
"forbidden_property_1",
"forbidden_property_2"
],
modes: [
PrivacyMode.custom
]
);
```

### Include events
```dart
await _pianoAnalytics.privacyIncludeEvents(
eventNames: ["page.display"],
modes: [PrivacyMode.custom]
);
```

### Exclude events
```dart
await _pianoAnalytics.privacyExcludeEvents(
eventNames: ["click.action"],
modes: [PrivacyMode.custom]
);
```

## Consents

> **Important:** Initialize PianoConsents before initializing PianoAnalytics

1. Initialize PianoConsents
```dart
import 'package:piano_analytics/piano_analytics.dart';
import 'package:piano_analytics/piano_consents.dart';
...
class _MyAppState extends State<MyApp> {
final _pianoConsents = PianoConsents(
requireConsents: true,
defaultPurposes: {
PianoConsentProduct.pa: PianoConsentPurpose.audienceMeasurement
}
);
final _pianoAnalytics = PianoAnalytics(
site: 1,
collectDomain: "piano.io"
);
@override
void initState() {
super.initState();
initPlugins();
}
Future<void> initPlugins() async {
...
await _pianoConsents.init();
await _pianoAnalytics.init();
}
...
}
```
2. Set consents
```dart
await _pianoConsents.set(
purpose: PianoConsentPurpose.audienceMeasurement,
mode: PianoConsentMode.essential,
products: [PianoConsentProduct.pa]);
```

3. Set all consents
```dart
await _pianoConsents.setAll(mode: PianoConsentMode.essential);
```

4. Set default consents
```dart
await _pianoConsents.clear();
```
*Use the **[piano_consents](https://pub.dev/packages/piano_consents)** package*
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = "io.piano.flutter.piano_analytics"
version = "1.0"
version = "1.0.1"

buildscript {
ext.kotlin_version = "1.9.0"
Expand Down
Loading

0 comments on commit 485be8b

Please sign in to comment.