@JavascriptInterface
  public void logEvent(String json) {
    try {
      JSONObject event = new JSONObject(json);

      String name = event.getString(JS_KEY_EVENT_NAME);
      EventType eventType = convertEventType(event.getInt(JS_KEY_EVENT_CATEGORY));
      Map<String, String> eventAttributes =
          convertToMap(event.optJSONObject(JS_KEY_EVENT_ATTRIBUTES));

      int messageType = event.getInt(JS_KEY_EVENT_DATATYPE);
      switch (messageType) {
        case JS_MSG_TYPE_PE:
          MParticle.getInstance().logEvent(name, eventType, eventAttributes);
          break;
        case JS_MSG_TYPE_PV:
          MParticle.getInstance().logScreen(name, eventAttributes);
          break;
        case JS_MSG_TYPE_OO:
          MParticle.getInstance().setOptOut(event.optBoolean(JS_KEY_OPTOUT));
          break;
        case JS_MSG_TYPE_CR:
          MParticle.getInstance().logError(name, eventAttributes);
          break;
        case JS_MSG_TYPE_SE:
        case JS_MSG_TYPE_SS:
          // swallow session start and end events, the native SDK will handle those.
        default:
      }

    } catch (JSONException jse) {
      ConfigManager.log(MParticle.LogLevel.WARNING, String.format(errorMsg, jse.getMessage()));
    }
  }
 @JavascriptInterface
 public void removeUserTag(String json) {
   try {
     JSONObject attribute = new JSONObject(json);
     MParticle.getInstance().removeUserTag(attribute.getString("key"));
   } catch (JSONException jse) {
     ConfigManager.log(MParticle.LogLevel.WARNING, String.format(errorMsg, jse.getMessage()));
   }
 }
 @JavascriptInterface
 public void setUserIdentity(String json) {
   try {
     JSONObject attribute = new JSONObject(json);
     MParticle.getInstance()
         .setUserIdentity(
             attribute.getString("Identity"),
             MParticle.IdentityType.parseInt(attribute.getInt("Type")));
   } catch (JSONException jse) {
     ConfigManager.log(MParticle.LogLevel.WARNING, String.format(errorMsg, jse.getMessage()));
   }
 }
 public static void requestInstanceId(Context context) {
   requestInstanceId(context, MParticle.getInstance().getConfigManager().getPushSenderId());
 }