Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error sending event to firebase analytics. W/FA: Value is too long #491

Closed
5 tasks done
alyleite opened this issue Aug 27, 2020 · 6 comments
Closed
5 tasks done

Error sending event to firebase analytics. W/FA: Value is too long #491

alyleite opened this issue Aug 27, 2020 · 6 comments

Comments

@alyleite
Copy link

Bug 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:

image

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

  [email protected]          
  [email protected]          
  [email protected]            
  [email protected]            
                                 
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
@marcelonnunes
Copy link

@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 -> #501

@dpa99c
Copy link
Owner

dpa99c commented Sep 7, 2020

@alyleite the eventProperties object should be a flat (non-nested) key/value object where the value is a primitive type such as string/integer/float/etc.
This is because Firebase Analytics does not support complex types such as arrays or objects for analytics event parameters.
I would suggest flattening any complex values in Javascript before passing to the logEvent function however bear in mind there is a limit of 100 characters for event values.
I will update the documentation to clarify this.

@dpa99c dpa99c closed this as completed in e848ade Sep 7, 2020
@alyleite
Copy link
Author

alyleite commented Sep 7, 2020

@dpa99c Firebase is actually accepting objects with lists.
Just see the PURCHASE event where it contains a list of ITEMS.

I also analyzed the Firebase javascript sdk. In EventParams there is an item array.

image

image

image

This link has an example of e-commerce using the PURCHASE event where a list of products (items) are sent

Sorry for my bad English.

@dpa99c
Copy link
Owner

dpa99c commented Sep 9, 2020

OK, I would be happy accept a PR that implements this for iOS & Android

@alyleite
Copy link
Author

alyleite commented Sep 9, 2020

@dpa99c I could make a Pull request for Android, but I don't have the knowledge to make the changes in IOS

@alyleite
Copy link
Author

@dpa99c Could I pull for Android only?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants