package com.sudoplz.reactnativeamplitudeanalytics;

import com.amplitude.api.Amplitude;

import android.app.Activity;
import android.app.Application;

import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.ReadableType;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Map;

public class RNAmplitudeSDK extends ReactContextBaseJavaModule {

  private Activity mActivity = null;
  private Application mApplication = null;

  public RNAmplitudeSDK(ReactApplicationContext reactContext, Application mApplication) {
    super(reactContext);
    this.mActivity = getCurrentActivity();
    this.mApplication = mApplication;
  }

  @Override
  public String getName() {
    return "RNAmplitudeSDK";
  }

  @ReactMethod
  public void initialize(String apiKey, Boolean trackSessionEvents) {
    Amplitude.getInstance().initialize(getReactApplicationContext(), apiKey).enableForegroundTracking(this.mApplication);
    Amplitude.getInstance().trackSessionEvents(trackSessionEvents);
  }

  @ReactMethod
  public void setUserId(String id) {
    Amplitude.getInstance().setUserId(id);
  }

  @ReactMethod
  public void setUserProperties(ReadableMap properties) {
    try {
      JSONObject jProperties = convertReadableToJsonObject(properties);
      Amplitude.getInstance().setUserProperties(jProperties);
    } catch (JSONException e) {
      return;
    }
  }

  @ReactMethod
  public void clearUserProperties() {
    try {
      Amplitude.getInstance().clearUserProperties();
    } catch (JSONException e) {
      return;
    }
  }

  @ReactMethod
  public void logEvent(String identifier) {
    Amplitude.getInstance().logEvent(identifier);
  }

  @ReactMethod
  public void logEventWithProps(String identifier, ReadableMap properties) {

    try {
      JSONObject jProperties = convertReadableToJsonObject(properties);
      Amplitude.getInstance().logEvent(identifier, jProperties);
    } catch (JSONException e) {
      return;
    }

  }

  @ReactMethod
  public void logRevenue(String productIdentifier, int quantity, double amount) {
    Amplitude.getInstance().logRevenue(productIdentifier, quantity, amount);
  }

  public static JSONObject convertReadableToJsonObject(ReadableMap map) throws JSONException{
    JSONObject jsonObj = new JSONObject();
    ReadableMapKeySetIterator it = map.keySetIterator();

    while (it.hasNextKey()) {
      String key = it.nextKey();
      ReadableType type = map.getType(key);
      switch (type) {
        case Map:
            jsonObj.put(key, convertReadableToJsonObject(map.getMap(key)));
            break;
        case String:
            jsonObj.put(key, map.getString(key));
            break;
        case Number:
            jsonObj.put(key, map.getDouble(key));
            break;
        case Boolean:
            jsonObj.put(key, map.getBoolean(key));
            break;
        case Array:
            jsonObj.put(key, map.getArray(key));
            break;
        case Null:
            jsonObj.put(key, null);
            break;
      }
    }
    return jsonObj;
 }

}

@@ -1766,36 +1766,24 @@
 perties() %7B%0A
-    try %7B%0A  
     Amplitud
@@ -1825,60 +1825,8 @@
 ();%0A
-    %7D catch (JSONException e) %7B%0A      return;%0A    %7D%0A
   %7D%0A

Remove unneeded try/catch