Skip to content

Commit

Permalink
chore: update public API (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahroz16 authored Oct 29, 2024
1 parent 3225029 commit a783266
Show file tree
Hide file tree
Showing 9 changed files with 340 additions and 282 deletions.
2 changes: 1 addition & 1 deletion apps/amiapp_flutter/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void main() async {
onDidReceiveNotificationResponse: (NotificationResponse notificationResponse) async {
// Callback from `flutter_local_notifications` plugin for when a local notification is clicked.
// Unfortunately, we are only able to get the payload object for the local push, not anything else such as title or body.
CustomerIO.track(name: "local push notification clicked", attributes: {"payload": notificationResponse.payload});
CustomerIO.instance.track(name: "local push notification clicked", attributes: {"payload": notificationResponse.payload});
}
);

Expand Down
6 changes: 3 additions & 3 deletions apps/amiapp_flutter/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class _AmiAppState extends State<AmiApp> {
onLogin: (user) {
_auth.login(user).then((signedIn) {
if (signedIn) {
CustomerIO.identify(identifier: user.email, attributes: {
CustomerIO.instance.identify(identifier: user.email, attributes: {
"first_name": user.displayName,
"email": user.email,
"is_guest": user.isGuest,
Expand Down Expand Up @@ -216,14 +216,14 @@ class _AmiAppState extends State<AmiApp> {
if (_customerIOSDK.sdkConfig?.screenTrackingEnabled == true) {
final Screen? screen = _router.currentLocation().toAppScreen();
if (screen != null) {
CustomerIO.screen(name: screen.name);
CustomerIO.instance.screen(name: screen.name);
}
}
}

void _handleAuthStateChanged() {
if (_auth.signedIn == false) {
CustomerIO.clearIdentify();
CustomerIO.instance.clearIdentify();
_auth.clearUserState();
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/amiapp_flutter/lib/src/screens/attributes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ class _AttributesScreenState extends State<AttributesScreen> {
};
switch (widget._attributeType) {
case _attributeTypeDevice:
CustomerIO.setDeviceAttributes(
CustomerIO.instance.setDeviceAttributes(
attributes: attributes);
break;
case _attributeTypeProfile:
CustomerIO.setProfileAttributes(
CustomerIO.instance.setProfileAttributes(
attributes: attributes);
break;
}
Expand Down
14 changes: 7 additions & 7 deletions apps/amiapp_flutter/lib/src/screens/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,25 @@ class _DashboardScreenState extends State<DashboardScreen> {
.then((value) => setState(() => _buildInfo = value));

inAppMessageStreamSubscription =
CustomerIO.subscribeToInAppEventListener(handleInAppEvent);
CustomerIO.instance.subscribeToInAppEventListener(handleInAppEvent);

// Setup 3rd party SDK, flutter-fire.
// We install this SDK into sample app to make sure the CIO SDK behaves as expected when there is another SDK installed that handles push notifications.
FirebaseMessaging.instance.getInitialMessage().then((initialMessage) {
CustomerIO.track(name: "push clicked", attributes: {"push": initialMessage?.notification?.title, "app-state": "killed"});
CustomerIO.instance.track(name: "push clicked", attributes: {"push": initialMessage?.notification?.title, "app-state": "killed"});
});

// ...while app was in the background (but not killed).
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
CustomerIO.track(name: "push clicked", attributes: {"push": message.notification?.title, "app-state": "background"});
CustomerIO.instance.track(name: "push clicked", attributes: {"push": message.notification?.title, "app-state": "background"});
});

// Important that a 3rd party SDK can receive callbacks when a push is received while app in background.
//
// Note: A push will not be shown on the device while app is in foreground. This is a FCM behavior, not a CIO SDK behavior.
// If you send a push using Customer.io with the FCM service setup in Customer.io, the push will be shown on the device.
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
CustomerIO.track(name: "push received", attributes: {"push": message.notification?.title, "app-state": "foreground"});
CustomerIO.instance.track(name: "push received", attributes: {"push": message.notification?.title, "app-state": "foreground"});
});

super.initState();
Expand Down Expand Up @@ -111,7 +111,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
};
attributes.addAll(arguments);

CustomerIO.track(
CustomerIO.instance.track(
name: 'In-App Event',
attributes: attributes,
);
Expand Down Expand Up @@ -174,9 +174,9 @@ class _ActionList extends StatelessWidget {
final eventName = event.key;
final attributes = event.value;
if (attributes == null) {
CustomerIO.track(name: eventName);
CustomerIO.instance.track(name: eventName);
} else {
CustomerIO.track(name: eventName, attributes: attributes);
CustomerIO.instance.track(name: eventName, attributes: attributes);
}
context.showSnackBar('Event sent successfully');
}
Expand Down
2 changes: 1 addition & 1 deletion apps/amiapp_flutter/lib/src/screens/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class _CustomEventScreenState extends State<CustomEventScreen> {
attributes = propertyName.isEmpty
? {}
: {propertyName: _propertyValueController.text};
CustomerIO.track(
CustomerIO.instance.track(
name: _eventNameController.text,
attributes: attributes);
_onEventTracked();
Expand Down
Loading

0 comments on commit a783266

Please sign in to comment.