Source: https://nishanth-fern-test.docs-staging.pageloop.ai/mobile/setup-whatfix-mobile-callbacks

# Setup Whatfix Mobile Callbacks

Whenever an end user interacts with Walkthroughs or other Whatfix Mobile elements, events are generated to track the Insights enabling you to analyze and refine your app experience based on real time data. For more information on Insights, see [Insights Overview](/mobile/analytics-dashboard).

> [!INFO]
>
> Listen to all events in your `Application(Android) / AppDelegate(iOS)` class.

Use the following code snippets to listen to the Whatfix Mobile callbacks:

> [!WARNING]
>
> Whatfix Mobile supports only versions greater than or equal to and above the following versions:
>
> - Android: 2.0.16
> - iOS: 2.0.16
> - React Native: 2.0.19
> - Cordova (Android): 2.0.10
> - Cordova (iOS): 2.0.13
> - Xamarin (Android): 2.0.9
> - Xamarin (iOS): 2.0.17
> - Ionic: 2.0.17
> - Jetpack Compose: 2.0.8
> - MAUI (Android): 2.0.9

AndroidSwiftObjective-CReact NativeCordovaXamarinIonicJetpackMAUI

### Swift

```swift
Leap.shared.callback = self

extension AppDelegate:LeapCallback {
    func eventNotification(eventInfo: Dictionary<String, Any>) {
        
    }
}
```

### Android

```java
import is.leap.android.LeapEventListener;

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        LeapEventCallbacks eventListener = new LeapEventCallbacks() {
            @Override
            public void onEvent(Map<String, String> eventData) {
                
            }
        };
      Leap.setLeapEventCallbacks(eventListener);
    }
 }
```

### MAUI

```javascript
LeapPlugin.start({apiKey:"<YOUR_API_KEY>"});
LeapPlugin.addListener("leapCallbacks", (event: LeapCallbacks) => {
    console.log("Leap Events: ", event);
})
```

### Jetpack

```javascript
LeapPlugin.start({apiKey:"<YOUR_API_KEY>"});
LeapPlugin.addListener("leapCallbacks", (event: LeapCallbacks) => {
    console.log("Leap Events: ", event);
})
```

### Ionic

The following code snippet has to be added where the app component is rendered.

```javascript
LeapPlugin.start({apiKey:"<YOUR_API_KEY>"});
LeapPlugin.addListener("leapCallbacks", (event: LeapCallbacks) => {
    console.log("Leap Events: ", event);
})
```

### React Native

```javascript
import {  NativeEventEmitter } from 'react-native';
export class App extends React.Component {

  componentDidMount() {
    // Register for callbacks
    const eventEmitter = new NativeEventEmitter(LeapReactNative);
    const onSessionConnect = (event) => {
      console.log(event);
    }
    eventEmitter.addListener('LeapCallbacks', onSessionConnect);
  }
}
```

### Objective-C

```objectivec
@interface AppDelegate () <LeapCallback>

Leap.shared.callback = self;

- (void)eventNotificationWithEventInfo:(NSDictionary<NSString *,id> *)eventInfo {
    
}
```

### Xamarin (Android)

```java
using static IS.Leap.Android.ILeapEventCallbacks
using IS.Leap.Android;

public class MainActivity : AppCompatActivity, ILeapEventCallbacks 
{
    protected override void OnCreate(Bundle savedInstanceState){
        Leap.SetLeapEventCallbacks(eventCallbacks: this);
    }
    
    public void OnEvent(IDictionary<string, string> keyValues)
    {
            
    }
}
```

### Xamarin (iOS)

```javascript
public class AppDelegate : UIResponder, IUIApplicationDelegate
{
    private LeapEventsCallback callback = null;
    public bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        Leap.Shared.Start("f4f460a6-9e04-4114-9da4-410659427c6a");
        callback = new LeapEventsCallback();
        Leap.Shared.SetCallback(callback);
        return true;
    }
}

public class LeapEventsCallback : LeapCallback
{
    public override void EventNotificationWithEventInfo(NSDictionary<NSString, NSObject> eventInfo)
    {
        System.Diagnostics.Debug.WriteLine(eventInfo);
    }
}
```

### Cordova (Android)

```javascript
cordova.plugins.LeapAndroid.setLeapEventCallback((leapEvent)=> {
    console.log(JSON.stringify(leapEvent, null, 2))
})
```

### Cordova (iOS)

```javascript
cordova.plugins.LeapiOS.setLeapEventCallback((leapEvent) =>{
    console.log(JSON.stringify(leapEvent, null, 2));
})
```
