Configuring Analytics via Segment

Step 1: Create new Class

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

public static void track(Analytics analytics, String eventName, Properties properties) {
        if (properties == null) {
            properties = new Properties();
        }
        HashMap<String, Object> propertiesMap = new HashMap<>(properties);
        //Please pass the string "sgmt" for vendor if you are using Segment to track the event.
        HashMap<String, Object> hanselData = HanselTracker.logEvent(eventName, "sgmt", propertiesMap);
        for (String key : hanselData.keySet()) {
            properties.put(key, hanselData.get(key));
        }

        analytics.track(eventName, properties);
    }
fun track(analytics: Analytics, eventName: String, properties: Properties?) {
        var properties = properties
        if (properties == null) {
            properties = Properties()
        }
        val propertiesMap = HashMap(properties)
        //Please pass the string "sgmt" for vendor if you are using Segment to track the event.
        val hanselData = HanselTracker.logEvent(eventName, "sgmt", propertiesMap)
        for (key in hanselData.keys) {
            properties[key] = hanselData[key]
        }

        analytics.track(eventName, properties)
    }
import {NativeModules} from 'react-native';

var AppSegment = (function () {
  function track(segmentClient, eventName, properties) {
    var mergedProperties = {};
    NativeModules.HanselTrackerRn.logEvent(eventName,"sgmt",properties,(hanselData) => {
        if(!properties) {properties = {};}
        mergedProperties = Object.assign(properties, hanselData);   
        segmentClient.track(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
Analytics.with(context).track(eventName, properties);

//it would get updated to
AppSegment.track(Analytics.with(context), eventName, properties);
//If the original code was
Analytics.with(context).track(eventName, properties);

//it would get updated to
AppSegment.track(Analytics.with(context), eventName, properties);
//If the original code was
segmentClicnet.track(eventName, properties);

//it would get updated to
AppSegment.track(segmentClicnet, eventName, properties);