Smartech

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 "smt" for vendor if you are using Segment to track the event.
        HashMap<String, Object> hanselData = HanselTracker.logEvent(eventName, "smt", 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 "smt" for vendor if you are using Segment to track the event.
        val hanselData = HanselTracker.logEvent(eventName, "smt", 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,"smt",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);

Updated about a month ago


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!

Product Experience

Configuring Analytics via Segment


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.