Firebase LogEvents 在网络视图中双打

Firebase LogEvents as doubles in a webview

按照 firebase reference/example code on github will result in values ending up in different value fields depending on the value. The reason is that javascript has a Number type and decimals don't show when a value is an integer (i.e. 5.00 is represented as 5 while 5.01 is represented as 5.01). When parameters are logged with logEvent() in the webview, the AnalyticsWebInterface.java 中的建议,在 webview 中将日志记录加倍到 firebase 分析 reference/example code on github will result in values ending up in different value fields depending on the value. The reason is that javascript has a Number type and decimals don't show when a value is an integer (i.e. 5.00 is represented as 5 while 5.01 is represented as 5.01). When parameters are logged with logEvent() in the webview, the AnalyticsWebInterface.java 测试参数值是字符串、整数还是双精度值,并将该值存储在相应的字段中(stringValue、intValue 或 floatValue) .因此,如果您将产品的价格记录为参数,如果价格为 5.00,它将以 intValue 结束,如果价格为 5.01,则以 floatValue 结束。这确实会使数据分析复杂化。

Object value = jsonObject.get(key);

   if (value instanceof String) {
       result.putString(key, (String) value);
   } else if (value instanceof Integer) {
       result.putInt(key, (Integer) value)      
   } else if (value instanceof Double) {
       result.putDouble(key, (Double) value);
   } else {
       Log.w(TAG, "Value for key " + key + " not one of [String, Integer, Double]");
   }

一种可能的解决方法是尝试转换值(如果它是字符串或整数)并将其记录到多个列中。示例:

if (value instanceof String) {
            try{
                result.putString(key, (String) value);
                result.putDouble(key, Double.parseDouble((String) value));
                result.putInt(key, Integer.parseInt((String) value));
            } catch(Exception e){}
        }
        if (value instanceof Integer) {
            try{
                result.putInt(key, (Integer) value);
                result.putDouble(key, Double.valueOf((Integer) value));
            }catch(Exception e){}
        }
        if (value instanceof Double){
            result.putDouble(key, (Double) value);
        }