I am building a Flutter mobile application and want to implement targeted push notifications based on the user’s preferences. Currently, I can send notifications to everyone (by registering the app to a single topic I have, and then I said notifications to that topic), which means everyone gets the same notification.
What I want to achieve is so to send each user the notification he is actually interested in (based on his profile preferences, that are stored in my laravel API (MySQL database). Note that a not logged in user should also receive notifications (random ones).
So my workflow, in a nutshell, is that a not logged-in user would receive random notifications, while a logged-in user should receive notifications tailored to his preferences.
Has anybody implemented such behavior? The idea I am having in my mind is that I should send device tokens to my API and link that token with the user, but I am not sure whether this is the most efficient way to do; and I kinda still have some questions I don’t know how to answer, like how to handle not logged-in users (does the fcm device token change when a user logs out? if not when exactly does a device token change? how can I and when should I invalidate/delete tokens from my backend so that my database doesn’t grow indefinitely with tokens that are not valid anymore? which part of my system should initiate sending notifications? the mobile app or the API server?)