pendo_sdk 2.21.0
pendo_sdk: ^2.21.0 copied to clipboard
This is a flutter plugin that wraps the native iOS and Android Pendo SDK
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:pendo_sdk/pendo_sdk.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
dynamic arguments = {
"visitorId": "flutter_visitorId1",
"accountId": "flutter_accountId"
};
var originalVisitorId = "original visitor id";
var originalAccountId = "original account id";
dynamic originalVisitorData = {"Age": 27, "Country": "USA"};
dynamic originalAccountData = {"Tier": 1, "Timezone": "EST"};
var newVisitorId = "new visitor id";
var newAccountId = "new account id";
dynamic newVisitorData = {"Age": 33, "Country": "Canada"};
dynamic newAccountData = {"Tier": 3, "Timezone": "PST"};
// Setup the Pendo SDK
await PendoFlutterPlugin.setup(
"eyJhbGciOiJSUzI1NiIsImtpZCI6IiIsInR5cCI6IkpXVCJ9.eyJkYXRhY2VudGVyIjoidXMiLCJrZXkiOiJjYTg0ZjRmNGQ4YTFhMThjOGQ5YmRmMmE2NzM3ZTE2ZTY5NjY3MDEzODFmNTg2Mzk0OTE0Mjk0OGVkZTEzMDUzZGJjZDdiZDdiN2FjZjNkYWVjNTMzZDRkNjFhZjFkNGEyNzIzZWQ4NTc5M2EyZTM3ZjBmYzY5YzQ3ZTJkZTcwMTFlNjg2MjMwN2NkMDQyM2QxMGExMzFhYjcyY2Y2YzczZDNjZjZiYWQyNDJkNjMyYmZlMWViNmE5ZTlkNTgxOGMwYmZiZjg0NDJhNmFhMGRiYTM5OTMwZWE2YzZmMTg0Zi43OGY3NWRjN2VkOTY4ODViZTU4NTY4ZTk1YmE2MjM4My4xMDkyMTY2M2YzM2JhNWYwZDMxZWM5MGM5ZTUzNzJlYzc5YjA5MWZhMWYwNTY2ZjQ5ZTYxMTY2ZGE2M2EzNjIzIn0.UROw9SPhRs1q9U3R7KvwonJDLPN8PkPlDIYzdeTSi2vV0VDRGQDbgKxbgqrRYlKcHdvZDzv5VlGFpwLPZ8OXMb9dzd63HqF3rV0RxdTosd6cmRxD21jY0GOSt1hcLEzOEsEnzdF_L6PHPbcWbO71KKmAfHIuhz37DlOXMZyK6vo");
// Start a new session with an identified visitor
await PendoFlutterPlugin.startSession(originalVisitorId,
originalAccountId, originalVisitorData, originalAccountData);
// End the current session, and start a new session with an anonymous visitor.
await PendoFlutterPlugin.clearVisitor();
// End the current session without starting a new one.
await PendoFlutterPlugin.endSession();
// End the current session, and start a new session with a different identifier visitor.
// (Since there wasn't an active session, no session will end, just a new one will be created).
await PendoFlutterPlugin.startSession(
newVisitorId, newAccountId, newVisitorData, newAccountData);
// Change the visitor data for the current visitor.
await PendoFlutterPlugin.setVisitorData(originalVisitorData);
// Change the account data for the current visitor.
await PendoFlutterPlugin.setAccountData(originalAccountData);
// Track an event that is happening in your application.
await PendoFlutterPlugin.track(
"Screen Visit", {"Screen Name": "Main Screen"});
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Running on: $_platformVersion\n'),
),
),
);
}
}