-
Notifications
You must be signed in to change notification settings - Fork 55
Unable to get message payload for handling notification Redirects #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@snghnishant Are you sending the push via FCM or via CleverTap dashboard? |
We have integrations for both FCM and CleverTap, we are using FCM for user-level notification that we push from our custom dashboard/backend. This notification was pushed from the CleverTap dashboard. |
@snghnishant Where have you set the |
in main.dart file class _AppState extends State<App> {
static FirebaseAnalytics analytics = FirebaseAnalytics();
static FirebaseAnalyticsObserver observer = FirebaseAnalyticsObserver(
analytics: analytics); // instance used to track pages in the Material app
// For Clevertap
CleverTapPlugin _clevertapPlugin;
// var inboxInitialized = false;
@override
void initState() {
super.initState();
// Clevertap
initPlatformState();
activateCleverTapFlutterPluginHandlers();
CleverTapPlugin.setDebugLevel(3);
CleverTapPlugin.createNotificationChannel(
"CleverTapNotification",
"Stratzy Notifications",
"Marketing, Account related, and Investment Tips from Stratzy",
3,
true);
CleverTapPlugin.registerForPush(); //only for iOS
// CleverTapPlugin.initializeInbox();
CleverTapPlugin.enableDeviceNetworkInfoReporting(true);
/*
CleverTapPlugin.setOptOut(false); ///Will opt in the user to send data to CleverTap
CleverTapPlugin.setOptOut(true); ///Will opt out the user to send data to CleverTap
CleverTapPlugin.enableDeviceNetworkInfoReporting(false); // Will opt out the user to send Device Network data to CleverTap
CleverTapPlugin.enableDeviceNetworkInfoReporting(true); // Will opt in the user to send Device Network data to CleverTap
CleverTapPlugin.setOffline(false); // Will set the user online
CleverTapPlugin.setOffline(true); // Will set the user offline
*/
}
// Clevertap methods
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
if (!mounted) return;
}
void activateCleverTapFlutterPluginHandlers() {
_clevertapPlugin = new CleverTapPlugin();
_clevertapPlugin.setCleverTapPushAmpPayloadReceivedHandler(
pushAmplificationPayloadReceived);
// You can get the custom value after clicking the notification using the setCleverTapPushClickedPayloadReceivedHandler.
// This will give you the entire Push Notification payload as sent from CleverTap in the form of a Map.
_clevertapPlugin.setCleverTapPushClickedPayloadReceivedHandler(
pushClickedPayloadReceived);
// ... rest of the handlers
}
// ... rest of the handlers definitions
void pushAmplificationPayloadReceived(Map<String, dynamic> map) {
print("-------pushAmplificationPayloadReceived called------");
this.setState(() async {
var data = jsonEncode(map);
print("Push Amp Payload = " + data.toString());
CleverTapPlugin.createNotification(data);
});
}
void pushClickedPayloadReceived(Map<String, dynamic> message) {
print("------ Notification CT-------");
print("CT DATA: $message");
// Handle redirections
var screen = message['data']['screen'];
switch (screen) {
case "PortfolioScreen":
// root level
Provider.of<GlobalBottomBarNotifier>(context, listen: false)
.changeActiveTabIndex(1);
break;
case "ClubScreen":
// root level
Provider.of<GlobalBottomBarNotifier>(context, listen: false)
.changeActiveTabIndex(4);
break;
case "DiscoverScreen":
// root level
Provider.of<GlobalBottomBarNotifier>(context, listen: false)
.changeActiveTabIndex(2);
break;
case "InsightsScreen":
// root level
Provider.of<GlobalBottomBarNotifier>(context, listen: false)
.changeActiveTabIndex(3);
break;
case "ActiveTradesScreen":
Navigator.of(context).push(animatedRoute(
ActiveTrades(),
RouteType.RIGHT_TO_LEFT,
));
break;
case "ExitInvestmentScreen":
Navigator.of(context).push(animatedRoute(
ExitInvestmentPage(
strategyRealName: message['data']['strategyRealName']),
RouteType.RIGHT_TO_LEFT,
));
break;
case "StrategyListScreen":
Navigator.of(context).push(animatedRoute(
StrategyListPage(),
RouteType.RIGHT_TO_LEFT,
));
break;
case "IdeaListScreen":
Navigator.of(context).push(animatedRoute(
IdeasListScreen(),
RouteType.RIGHT_TO_LEFT,
));
break;
case "StrategyExploreScreen":
var strategy = message['data']['strategyRealName'];
var strategyData = Hive.box<Strategy>('strategiesData')
.get(strategy, defaultValue: null);
if (strategyData != null)
Navigator.of(context).push(animatedRoute(
ExploreStrategyScreen(
strategyRealName: strategy,
minInvestment: strategyData.minInvestmentVal,
),
RouteType.RIGHT_TO_LEFT,
));
break;
case "IdeaExploreScreen":
getIdeasAndSaveToHive().then((response) {
if (response) {
Navigator.of(context).push(animatedRoute(
ExploreIdeaScreen(
ideaName: message['data']['ideaName'],
),
RouteType.RIGHT_TO_LEFT,
));
} else {
Navigator.of(context).push(animatedRoute(
IdeasListScreen(),
RouteType.RIGHT_TO_LEFT,
));
}
});
break;
/*case "IndividualPortfolioScreen":
Navigator.of(context).push(animatedRoute(
IndividualPortfolioScreen(strategy: strategy),
RouteType.RIGHT_TO_LEFT,
));
break;*/
default:
debugPrint("No redirects present, Opening the App!");
}
} This is how I am invoking the handler (the way it was mentioned in your example project) |
// Initializing firebase background isolate
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call `initializeApp` before using other Firebase services.
// Used for CleverTap
// This will be called to render the Notification in System tray when app is in background/terminated state
await Firebase.initializeApp();
print("Im in the background handler");
await CleverTapPlugin();
await CleverTapPlugin.createNotification(jsonEncode(message.data));
print("Tried calling createNotification");
}
void main() async {
runZonedGuarded<Future<void>>(() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialization
await Firebase.initializeApp();
await Hive.initFlutter();
// register fcm handler to handle message on background/terminate state
// called for both FCM and CleverTap Notifications
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
// status bar color & brightness
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarBrightness: Brightness.light,
statusBarIconBrightness: Brightness.light,
),
);
// device orientation
await SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
runApp(
App(),
);
}, (error, stack) => FirebaseCrashlytics.instance.recordError(error, stack));
} |
these are the detailed logs on initiating the push notification from the clever tap dashboard
Detailed logs on Notification click
|
@snghnishant Are you calling I'm assuming your issue here is that the notification is getting rendered but with the click of the notification you are not getting the |
Yup, but also in the handler registered for push amplification void pushAmplificationPayloadReceived(Map<String, dynamic> map) {
print("-------pushAmplificationPayloadReceived called------");
this.setState(() async {
var data = jsonEncode(map);
print("Push Amp Payload = " + data.toString());
CleverTapPlugin.createNotification(data);
});
} The notification is rendering but when clicked nothing happens at all, i.e the call to |
@snghnishant Got it! I would suggest you try calling I think the callback listener is not getting set when the notification arrives on the device and hence you are not receiving the |
|
@darshanclevertap can you please give a solution for this. We are using Clevertap in our mobile app in production and are unable to do any marketing campaigns which requires us to send user level notifications with redirections. |
@darshanclevertap I have figured out a workaround for this which works for notification redirection. Instead of passing parameters as key-value pairs in notification data to get to a specific screen inside the app, we can use deep links with query parameters and use the firebase dynamic links package to handle the user notification click redirection. But this doesn't solve the actual issue. A solution will be really appreciated. |
Any update on this post? Our team also facing the same issue. Able to receive payload on FirebaseMessaging, but not on pushClickedPayloadReceived callback. Appreciate if anyone on CleverTap Team can follow up on this. |
Hey as of now there's no way to get the notification data and their tech team is working on that to get this resolved. If you want to try out my workaround to handle redirections through deeplinks then do let me know I'll share the code and steps in a gist. |
On tap of system tray notification from Clevertap still not able to get the payload in any 3 states of the app tested on |
@darshanclevertap would like to know the updates on this, please! |
@snghnishant I was also facing the same issue . I removed all firebase handlers and it started working. |
Any update on this @darshanclevertap the issue has been pending from a very long time now. |
@snghnishant same problem |
@darshanclevertap any news? |
@snghnishant Did Firebase Dynamic Links work when app is terminated |
@william-ct @darshanclevertap We are facing the same issue we started integrating clevertap in mid-January and we are still in the integration phase. Have a look at these ticket id's #122515 #119425 |
@darshanclevertap |
Hello @Mohanedy98. Could you please provide more details about the issue you are facing? |
Hello @shivamsharma2710 , Relevant code snippets: cleverTapPlugin.setCleverTapPushClickedPayloadReceivedHandler(pushClickedPayloadReceived);
void pushClickedPayloadReceived(Map<String, dynamic> map) {
Logger.debugLog('CleverTap push clicked payload received = $map');
_onPushNotificationClickedStreamController.add(map);
} FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
await localNotificationsDataSource.incrementUnreadNotifications();
if (onMessageReceived != null) {
onMessageReceived(message);
}
if (Platform.isAndroid) {
if (message.data.containsKey('wzrk_acct_id')) {
/// CleverTap notification
final dataPayload = jsonEncode(message.data);
CleverTapPlugin.createNotification(dataPayload);
} else {
/// Normal notification
onMessageReceivedHandler(message, onMessageClicked: onMessageClicked);
}
}
}); |
Hello y'all I'm facing the exact same issue on my flutter project (the push notification is rendered, but click events don't work...the callbacks registered are never triggered). Any solutions for this?...this bug is now 2 years old... |
@RamiroGarrido This issue has been fixed in version 1.8.0. Please refer to the ChangeLog and developer documentation for more information on this. |
I am still facing this issue again in latest version 3.0.0 |
Uh oh!
There was an error while loading. Please reload this page.
Hey, @darshanclevertap I have tried all the mentioned solutions in #46 to get the Notification Data for redirecting when the app is in the background or terminated state and this is still not working at all.
When the app is in Foreground I am able to get the message payload in
FirebaseMessaging.onMessage.listen((RemoteMessage message) {...}
and handle redirections through our custom made alert box. But we also get the Notification rendered in the System Tray, and on clicking that notification the app opens but there's no method handler calls tovoid pushClickedPayloadReceived(Map<String, dynamic> message) {...}
which you said will give you the message payload. So basically there's no way by which we can get the message payload on the onClick event of the Notification being rendered in the system tray in any of the app states.The text was updated successfully, but these errors were encountered: