|
22 | 22 | import com.instabug.library.logging.InstabugLog;
|
23 | 23 | import com.instabug.library.bugreporting.model.ReportCategory;
|
24 | 24 | import com.instabug.library.InstabugCustomTextPlaceHolder;
|
| 25 | +import com.instabug.library.user.UserEventParam; |
25 | 26 |
|
26 | 27 | import java.util.ArrayList;
|
27 | 28 | import java.util.HashMap;
|
@@ -845,6 +846,66 @@ public void logUserEventWithName(String name) {
|
845 | 846 | }
|
846 | 847 | }
|
847 | 848 |
|
| 849 | + /** |
| 850 | + * Logs a user event that happens through the lifecycle of the application. |
| 851 | + * Logged user events are going to be sent with each report, as well as at the end of a session. |
| 852 | + * |
| 853 | + * @param {string} name Event name. |
| 854 | + * @param {ReadableMap} params An optional ReadableMap to be associated with the event. |
| 855 | + */ |
| 856 | + @ReactMethod |
| 857 | + public void logUserEventWithNameAndParams(String name, ReadableMap params) { |
| 858 | + try { |
| 859 | + Map paramsMap = toMap(params); |
| 860 | + UserEventParam[] userEventParams = new UserEventParam[paramsMap.size()]; |
| 861 | + int index = 0; |
| 862 | + UserEventParam userEventParam; |
| 863 | + for (Map.Entry<String, String> entry : paramsMap.entrySet()) { |
| 864 | + userEventParam = new UserEventParam().setKey(entry.getKey()) |
| 865 | + .setValue(entry.getValue()); |
| 866 | + userEventParams[index] = userEventParam; |
| 867 | + index++; |
| 868 | + } |
| 869 | + |
| 870 | + mInstabug.logUserEvent(name, userEventParams); |
| 871 | + } catch (java.lang.Exception exception) { |
| 872 | + exception.printStackTrace(); |
| 873 | + } |
| 874 | + } |
| 875 | + |
| 876 | + private Map<String, Object> toMap(ReadableMap readableMap) { |
| 877 | + Map<String, Object> map = new HashMap<>(); |
| 878 | + ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); |
| 879 | + |
| 880 | + while (iterator.hasNextKey()) { |
| 881 | + String key = iterator.nextKey(); |
| 882 | + ReadableType type = readableMap.getType(key); |
| 883 | + |
| 884 | + switch (type) { |
| 885 | + case Null: |
| 886 | + map.put(key, null); |
| 887 | + break; |
| 888 | + case Boolean: |
| 889 | + map.put(key, readableMap.getBoolean(key)); |
| 890 | + break; |
| 891 | + case Number: |
| 892 | + map.put(key, readableMap.getDouble(key)); |
| 893 | + break; |
| 894 | + case String: |
| 895 | + map.put(key, readableMap.getString(key)); |
| 896 | + break; |
| 897 | + case Map: |
| 898 | + map.put(key, MapUtil.toMap(readableMap.getMap(key))); |
| 899 | + break; |
| 900 | + case cluster: |
| 901 | + map.put(key, ArrayUtil.toArray(readableMap.getArray(key))); |
| 902 | + break; |
| 903 | + } |
| 904 | + } |
| 905 | + |
| 906 | + return map; |
| 907 | + } |
| 908 | + |
848 | 909 | private InstabugCustomTextPlaceHolder.Key getStringToKeyConstant(String key) {
|
849 | 910 | String keyInLowerCase = key.toLowerCase();
|
850 | 911 | switch (keyInLowerCase) {
|
|
0 commit comments