Configuring Analytics via Firebase

Step 1: Create new Class

Create a new class "AppFirebase" and add the following method to it.

public static void logEvent(FirebaseAnalytics firebaseAnalytics, String eventName, Bundle properties) {
        if (properties == null) {
            properties = new Bundle();
        }
        HashMap<String, Object> propertiesMap = new HashMap<>();
        for (String key : properties.keySet()) {
            propertiesMap.put(key, properties.get(key));
        }
        //Please pass the string "fbs" for vendor if you are using Firebase to track the event.
        HashMap<String, Object> hanselData = HanselTracker.logEvent(eventName, "fbs", propertiesMap);
        for (String key : hanselData.keySet()) {
            properties.putString(key, hanselData.get(key));
        }
        firebaseAnalytics.logEvent(eventName, properties);
    }
fun logEvent(firebaseAnalytics: FirebaseAnalytics, eventName: String, properties: Bundle?) {
        var properties = properties
        if (properties == null) {
            properties = Bundle()
        }
        val propertiesMap = HashMap<String, Any>()
        for (key in properties.keySet()) {
            propertiesMap[key] = properties.get(key)
        }
        //Please pass the string "fbs" for vendor if you are using Firebase to track the event.
        val hanselData = HanselTracker.logEvent(eventName, "fbs", propertiesMap)
        for (key in hanselData.keys) {
            properties.putString(key, hanselData[key])
        }
        firebaseAnalytics.logEvent(eventName, properties)
    }
import {NativeModules} from 'react-native';

var AppFirebase = (function () {
  function logEvent(firebaseClient, eventName, properties) {
    var mergedProperties = {};
    NativeModules.HanselTrackerRn.logEvent(eventName,"fbs",properties,(hanselData) => {
        if(!properties) {properties = {};}
        mergedProperties = Object.assign(properties, hanselData); 
        firebaseClient.logEvent(eventName, mergedProperties);
    }); 
  }
})();

Step 2: Tracking Hansel changes

For all those events on which you want to track the impact of Hansel changes, make the updates as suggested in the snippet below:

//If the original code was
FirebaseAnalytics.getInstance(context).logEvent(eventName, properties);

//it would get updated to
AppFirebase.logEvent(FirebaseAnalytics.getInstance(context), eventName, properties);
//If the original code was
FirebaseAnalytics.getInstance(context).logEvent(eventName, properties);

//it would get updated to
AppFirebase.logEvent(FirebaseAnalytics.getInstance(context), eventName, properties);
//If the original code was
firebaseClient.logEvent(eventName, properties);

//it would get updated to
AppFirebase.logEvent(firebaseClient, eventName, properties);

Next

You are done configuring analytics events for triggers and goals, go back to this page and follow further steps to complete the Product Experience integration!