Smartech

Configuring Analytics via Mixpanel

Step 1: Creating new Class

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

public static void track(MixpanelAPI mixPanel, 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 "mxp" for vendor if you are using Mixpanel to track the event.
        HashMap<String, object> hanselData = HanselTracker.logEvent(eventName, "mxp", propertiesMap);
        for (String key : hanselData.keySet()) {
            try {
                properties.put(key, hanselData.get(key));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        mixPanel.track(eventName, properties);
    }
fun track(mixPanel: MixpanelAPI, 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 "mxp" for vendor if you are using Mixpanel to track the event.
        val hanselData = HanselTracker.logEvent(eventName, "mxp", propertiesMap)
        for (key in hanselData.keys) {
            try {
                properties.put(key, hanselData[key])
            } catch (e: JSONException) {
                e.printStackTrace()
            }

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

var AppMixPanel = (function () {
  function track(eventName, properties) {
    var mergedProperties = {};
    NativeModules.HanselTrackerRn.logEvent(eventName,"mxp",properties,(hanselData) => {
        if(!properties) {properties = {};}
        mergedProperties = Object.assign(properties, hanselData);   
        MixPanel.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
mixPanel.track(eventName, properties);

//it would get updated to
AppMixPanel.track(mixPanel, eventName, properties);
//If the original code was
mixPanel.track(eventName, properties)

//it would get updated to
AppMixPanel.track(eventName, properties)
//If the original code was
MixPanel.track(eventName, properties);

//it would get updated to
AppMixPanel.track(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 Mixpanel


Suggested Edits are limited on API Reference Pages

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