Error sending event to firebase analytics. W/FA: Value is too long
See original GitHub issueBug Report
Problem
I searched but found nothing related to it.
I’m developing an e-commerce app with ionic
in wich i’m sending events to the firebase analytics using this plugin following the steps described here.
However, when I try to send a list of products in the event view_cart
I get the following error in logcat:
W/FA: Value is too long; discarded. Value kind, name, value length: param, items, 204
This is the log of the event I sent:
V/FA-SVC: Logging event: origin=app,name=view_cart,params=Bundle[{ga_event_origin(_o)=app, ga_error_length(_el)=204, ga_error_value(_ev)=items, ga_screen_class(_sc)=MainActivity, ga_screen_id(_si)=-6971504103994550923, ga_screen(_sn)=carrinho, ga_error(_err)=4, value=36.0, currency=BRL, local_nome=Pizzaria CNM, local_id=108}]
Code
const items = [];
this.listaPedidoClienteProduto.forEach(item => {
const prod: Produto = new Produto(item.produto);
const valor = prod.valorPromocao ? prod.valorPromocao : prod.valorVenda;
items.push({
item_id: prod.id.toString(),
item_name: prod.descricaoPnm,
quantity: item.quantidade ? item.quantidade : 1,
price: valor
});
});
this.firebaseCordova.logEvent('view_cart', {
currency: 'BRL',
value: this.valorTotalPedido,
items: items
}).then((res: any) => {
if(res !== "OK") {
console.log(res);
}
}).catch((error: any) => console.error(error));
I decided to debug the plugin code (src/android/FirebasePlugin.java) and realized that the JsonArray is not being verified, only the Integer and Double are:
The array ‘items’ is send as a string exceeding the limit of 100 character array allowed by Firebase.
I changed the code on my local machine so I get it working as expected:
...
if (value instanceof Integer || value instanceof Double) {
bundle.putFloat(key, ((Number) value).floatValue());
} else if(value instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) value;
final Bundle itemListBundle = new Bundle();
ArrayList<Parcelable> bundles = new ArrayList<>();
for (int index = 0 ; index < jsonArray.length(); index++) {
JSONObject jsonObject = jsonArray.getJSONObject(index);
Iterator<String> iterator = jsonObject.keys();
while (iterator.hasNext()) {
String keyObj = iterator.next();
Object valueObj = jsonObject.get(keyObj);
if (valueObj instanceof Integer || valueObj instanceof Double) {
itemListBundle.putFloat(keyObj, ((Number) valueObj).floatValue());
} else {
itemListBundle.putString(keyObj, valueObj.toString());
}
}
bundles.add(itemListBundle);
}
bundle.putParcelableArrayList(key, bundles);
} else {
bundle.putString(key, value.toString());
}
...
I didn’t make a pull request because I believe I should change it on IOS too, but I have no knowledge in this area.
Version information
cordova info
cordova-common@3.2.1
cordova-create@2.0.0
cordova-fetch@2.0.1
cordova-serve@3.0.0
Environment:
OS: win32
Node: v12.18.0
npm: 6.14.6
Plugins:
cordova-custom-config
cordova-plugin-androidx
cordova-plugin-androidx-adapter
cordova-plugin-badge
cordova-plugin-device
cordova-plugin-facebook4
cordova-plugin-firebasex
cordova-plugin-geolocation
cordova-plugin-inappbrowser
cordova-plugin-ionic-keyboard
cordova-plugin-ionic-webview
cordova-plugin-local-notificati
cordova-plugin-sign-in-with-app
cordova-plugin-splashscreen
cordova-plugin-statusbar
cordova-plugin-uniquedeviceid
cordova-plugin-whitelist
cordova-support-android-plugin
cordova-support-google-services
Checklist
- I have read the issue reporting guidelines
- I confirm this is a suspected bug or issue that will affect other users
- I have read the documentation thoroughly and it does not help solve my issue.
- I searched for existing GitHub issues
- I included all the necessary information above
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
@alyleite , All right ?
Could you help me with an issue I’m facing with Remote Config. I saw that you managed to solve a bug in (src / android / FirebasePlugin.java). I think the error is also in that file, but I don’t know much about Java. If you can help me, thank you very much 😃.
Error with Remote Config -> https://github.com/dpa99c/cordova-plugin-firebasex/issues/501
@dpa99c Could I pull for Android only?