Freshchat 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);
NoteYou 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


Event Name
Description
FCEventFAQCategoryListOpen
When FAQ category list is opened
FCEventFAQListOpenWhen FAQ list is opened
FCEventFAQOpen
When FAQ is opened
FCEventFAQSearch
When FAQ is selected from search result or search results cancelled
FCEventFAQVote
When FAQ is voted
FCEventChannelListOpen
When Channel list is opened
FCEventMessageSent
When user message is sent
FCEventConversationOpen
When Channel is opened
FCEventCsatOpen
When CSAT is shown to user
FCEventCsatSubmit
When user responds to a CSAT
FCEventCsatExpiry
When CSAT expires and is not shown to user
FCEventLinkTap
When user clicks an external link
FCEventScreenView

When Freshchat SDK screen is visible to user

FCEventMessageReceive
When user receives a message
FCEventNotificationReceive
When user receives a Freshchat notification
FCEventIdTokenStatusChange
When user's JWT token status changes