What I don’t understand, I tried to use the example provided with the SDK for Flutter. And this one doesn’t work either, is there a configuration in the dashboard that I haven’t forgotten?
import 'package:flutter/material.dart';
import 'package:flutter_piwikpro/model/ecommerce_transaction_item.dart';
import 'package:flutter_piwikpro/flutter_piwikpro.dart';
void main() {
final ecommerceTransactionItems = [
EcommerceTransactionItem(
category: 'cat1', sku: 'sku1', name: 'name1', price: 20, quantity: 1),
EcommerceTransactionItem(
category: 'cat2', sku: 'sku2', name: 'name2', price: 10, quantity: 1),
EcommerceTransactionItem(
category: 'cat3', sku: 'sku3', name: 'name3', price: 30, quantity: 2),
];
runApp(MyApp(
ecommerceTransactionItems: ecommerceTransactionItems,
));
}
class MyApp extends StatelessWidget {
const MyApp({
required this.ecommerceTransactionItems,
Key? key,
}) : super(key: key);
final List<EcommerceTransactionItem> ecommerceTransactionItems;
@override
Widget build(BuildContext context) {
FlutterPiwikPro flutterPiwik = FlutterPiwikPro.sharedInstance;
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Padding(
padding: const EdgeInsets.only(left: 32.0, right: 32.0, bottom: 32.0),
child: Center(
child: SingleChildScrollView(
child: Column(
children: [
_buildTextWidget('Configure Tracker', () async {
try {
final result = await flutterPiwik.configureTracker(
baseURL: 'https://preim.containers.piwik.pro',
siteId: 'ee3ebbd3-****-****-****-8bc61a575b62',
);
print(result);
} catch (exception) {
print(exception);
}
}),
_buildTextWidget('Set Anonymization State True', () async {
try {
final result =
await flutterPiwik.setAnonymizationState(true);
print(result);
} catch (exception) {
print(exception);
}
}),
_buildTextWidget('Set Anonymization State False', () async {
try {
final result =
await flutterPiwik.setAnonymizationState(false);
print(result);
} catch (exception) {
print(exception);
}
}),
_buildTextWidget(
'Track Screen',
() async {
try {
final result = await flutterPiwik.trackScreen(
screenName: "test", title: "test title");
print(result);
} catch (exception) {
print(exception);
}
},
),
_buildTextWidget('Track Custom Event', () async {
try {
final result = await flutterPiwik.trackCustomEvent(
action: 'test action',
category: 'test category',
name: 'test name',
path: 'test path',
value: 120);
print(result);
} catch (exception) {
print(exception);
}
}),
_buildTextWidget('Track Exception', () async {
try {
final result = await flutterPiwik.trackException(
description: "description of an exception");
print(result);
} catch (exception) {
print(exception);
}
}),
_buildTextWidget('Track Download', () async {
try {
final result = await flutterPiwik.trackDownload(
'http://your.server.com/bonusmap2.zip');
print(result);
} catch (exception) {
print(exception);
}
}),
_buildTextWidget('Track Ecommerce Transaction', () async {
try {
final result =
await flutterPiwik.trackEcommerceTransaction(
identifier: "testId",
grandTotal: 100,
subTotal: 10,
tax: 5,
shippingCost: 100,
discount: 6,
transactionItems: ecommerceTransactionItems,
);
print(result);
} catch (exception) {
print(exception);
}
}),
_buildTextWidget('Track Social Interaction', () async {
try {
final result = await flutterPiwik.trackSocialInteraction(
network: "facebook", interaction: "like");
print(result);
} catch (exception) {
print(exception);
}
}),
_buildTextWidget('Track goal', () async {
try {
final result = await flutterPiwik.trackGoal(
goal: "27ecc5e3-8ae0-40c3-964b-5bd8ee3da059",
revenue: 2.0);
print(result);
} catch (exception) {
print(exception);
}
}),
_buildTextWidget('Track outlink', () async {
try {
final result = await flutterPiwik
.trackOutlink("piwikPRO://piwikpro.com");
print(result);
} catch (exception) {
print(exception);
}
}),
_buildTextWidget('Track campaign', () async {
try {
final result = await flutterPiwik.trackCampaign(
"http://www.example.com?utm_campaign=camp_name3&pk_source=source&pk_medium=medium&pk_keyword=keyword&pk_content=content&pk_cid=id_code");
print(result);
} catch (exception) {
print(exception);
}
})
],
),
),
),
),
),
);
}
Widget _buildTextWidget(String title, VoidCallback? onPressed) {
return TextButton(
onPressed: onPressed,
child: Container(
color: Colors.blue,
child: Text(
title,
style: const TextStyle(color: Colors.white),
),
),
);
}
}