Chat mobile SDK allows you to listen to user actions and related meta properties.
This feature is available starting with the following SDK versions,
Android: 2.7.0+
iOS: 2.7.0+
Based on your platform, you can listen to user events as follows.
Android:
Register for user events
We recommend you to register this in onCreate of your Application class.
IntentFilter userActionsIntentFilter = new IntentFilter(Freshchat.FRESHCHAT_EVENTS);
getLocalBroadcastManager().registerReceiver(receiver, userActionsIntentFilter);
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null || intent.getExtras() == null) {
return;
}
Event event = Freshchat.getEventFromBundle(intent.getExtras());
if (event != null) {
Log.d("Name", "Name : " + event.getEventName().getName());
Log.d("Prop", "Event Properties: " + event.getProperties());
}
}
};
Unregister for user events
You can unregister in onTerminate of your Application class.
getLocalBroadcastManager().unregisterReceiver(receiver);
Note: You can checkout our video on 'Tracking user events' here: https://freshchat.wistia.com/medias/cmgpce0usa
iOS:
Objective C
Register for user events
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(userActionEvent:)
name:FRESHCHAT_EVENTS
object:nil];
- (void) userActionEvent:(NSNotification *)notif {
FreshchatEvent *fcEvent = notif.userInfo[@"event"];
// Check with available event enum
if (fcEvent.name == FCEventFAQOpen){
// Log existing event meta / properties
NSLog(@"Event properties - %@",fcEvent.properties);
}
}
Unregister for user events
[[NSNotificationCenter defaultCenter]removeObserver: FRESHCHAT_EVENTS];
Swift
Register for user events
NotificationCenter.default.addObserver(self,selector: #selector(userActionEvent(_:)),name: NSNotification.Name(rawValue: FRESHCHAT_EVENTS),object: nil)
func userActionEvent(_ notification: Notification)
{
var fcEvent : FreshchatEvent? = nil
fcEvent = (notification.userInfo?["event"] as? FreshchatEvent)
//Check with available event enum
if fcEvent?.name == FCEventFAQOpen {
//Log existing event meta / properties
print ("Event properties - \(String(describing: fcEvent?.properties))")
}
}
Unregister for user events
NotificationCenter.default.removeObserver(FRESHCHAT_EVENTS)
Supported Events: