How to create application wide listener

I have a live view phoenix app. I want that on every page the user will notify how many messages waiting for him

I know how to do that on a specific page using pub/sub. My problem is that I want to show the notification on every page, so the reasonable place is to put in on the root.html.leex but where sould I put the listener?
Even if I will create a plug to get the current notification, how to update it without refresh the page?

You might be able to subscribe for notifications in on_mount hook and use it on all your routes that need it.

Thanks, I will try that