Notification open tracking


#1

Hey folks :wave:

I’m using Expo’s push notification setup and we’re looking to track an event to Segment (and then onto Mixpanel) when a user taps and opens a notification. From reading the docs I can’t see any way of hooking into a callback to fire off an event to Segment.

Does Expo’s Push Notification setup have any way of firing some code when a notification is opened by the user?

Any help much appreciated :pray:


#2

Hi @fredrivett!

You could use Notifications.addListener to set up a callback that would get executed whenever app receives a notification or a user taps on a notification. To verify whether the notification has been tapped or just received, use the origin property, which will be equal to selected if the user tapped the notification. You should be able to send a Segment event in the callback.

(shameless plug) Remember to remove the listener whenever you add it or you’ll have to face memory leaks in your app! For a great resource on hunting memory leaks, check out https://blog.swmansion.com/hunting-js-memory-leaks-in-react-native-apps-bd73807d0fde. :slightly_smiling_face:


#3

Oh goodness I didn’t see that in the docs, now I feel dumb. Thanks so much for your response here @sjchmiela! I’m gonna look into this this week and try and get something setup. Good to know on memory leaks too, will read! :raised_hands:


closed #4

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.