Configuring Analytics via Amplitude

Step 1: Create new Class

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

public static void logEvent(AmplitudeClient amplitudeClient, String eventName, JSONObject properties) {

        if (properties == null) {
            properties = new JSONObject();
        }
        HashMap<String, Object> propertiesMap = new HashMap<>();
        for (Iterator<String> it = properties.keys(); it.hasNext(); ) {
            String key = it.next();
            propertiesMap.put(key, properties.opt(key));
        }
        //Please pass the string "amp" for vendor if you are using Amplitude to track the event.
        HashMap<String, Object> hanselData = HanselTracker.logEvent(eventName, "amp", propertiesMap);
        if (hanselData != null) {
            for (String key : hanselData.keySet()) {
                try {
                    properties.put(key, hanselData.get(key));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }

        amplitudeClient.logEvent(eventName, properties);
    }
fun logEvent(amplitudeClient: AmplitudeClient, eventName: String, properties: JSONObject?) {
        var properties = properties

        if (properties == null) {
            properties = JSONObject()
        }
        val propertiesMap = HashMap<String, Any>()
        val it = properties.keys()
        while (it.hasNext()) {
            val key = it.next()
            propertiesMap[key] = properties.opt(key)
        }
        //Please pass the string "amp" for vendor if you are using Amplitude to track the event.
        val hanselData = HanselTracker.logEvent(eventName, "amp", propertiesMap)
        if (hanselData != null) {
            for (key in hanselData.keys) {
                try {
                    properties.put(key, hanselData[key])
                } catch (e: JSONException) {
                    e.printStackTrace()
                }

            }
        }

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

var AppAmplitude = (function () {
  function logEvent(amplitudeClient, eventName, properties) {
    var mergedProperties = {};
    NativeModules.HanselTrackerRn.logEvent(eventName,"amp",properties,(hanselData) => {
        if(!properties) {properties = {};}
        mergedProperties = Object.assign(properties, hanselData);   
        amplitudeClient.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
amplitudeClient.logEvent(eventName, properties);

//it would get updated to
AppAmplitude.logEvent(amplitudeClient, eventName, properties);
//If the original code was
amplitudeClient.logEvent(eventName, properties)

//it would get updated to
AppAmplitude.logEvent(amplitudeClient, eventName, properties)
//If the original code was
amplitudeClient.logEvent(eventName, mergedProperties);

//it would get updated to
AppAmplitude.logEvent(amplitudeClient, 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!