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

How to pass item value and quantity to analytics? #4578

Closed
hwq0521 opened this issue Nov 20, 2020 · 11 comments
Closed

How to pass item value and quantity to analytics? #4578

hwq0521 opened this issue Nov 20, 2020 · 11 comments

Comments

@hwq0521
Copy link

hwq0521 commented Nov 20, 2020

Hi, I unable to pass the value and quantity of item with the code:
await analytics().logEvent('purchase', {
value: parseFloat(amount),
currency: 'USD',
items: [
{
item_name: PRODUCT_NAME,
item_category: ITEM_CATEGORY,
price: parseFloat(amount),
quantity: 1
},
],
});

Screenshot 2020-11-20 at 11 48 10 AM

May I know any missing code from my part?

@hwq0521 hwq0521 changed the title How to pass item value to analytics? How to pass item value and quantity to analytics? Nov 20, 2020
@PlatonSotnykov
Copy link

I have the same issue. They added the "quantity" field in the version 10.1.1 but still there is no any price related fields.

@mikehardy
Copy link
Collaborator

@PlatonSotnykov "they" was @Danchoys generously advancing the state of react-native-firebase for himself and everyone in #4536 - if you require price-related fields, please examine that PR (to see roughly how it's done) and propose a PR! I'll happily work with you to merge it

@brerdem
Copy link

brerdem commented Jan 28, 2021

Hello! I want to display price of the item that being sent with purchase method. I carefully read all comments and took a look at the solution that have been made for quantity in #4536. So I changed structs and modified native Java code for Items, in the end came up with the result below. As you can see the price is showing up but in incorrect format. In this case it has to be 234.3. Any idea how to fix it or anybody experienced such issue?

image

@mikehardy
Copy link
Collaborator

Oh that's great @brerdem - it sounds like it's really really close - perhaps @Danchoys might be able to lend a hand, if it's down to just formatting it should be something trivial

@Danchoys
Copy link
Contributor

Danchoys commented Jan 28, 2021

Hi, @brerdem ! I think your issue is that you copied this code when adding the new price parameter:

      if (item instanceof Bundle && ((Bundle) item).containsKey(FirebaseAnalytics.Param.QUANTITY)) {
        double number = ((Bundle) item).getDouble(FirebaseAnalytics.Param.QUANTITY);
        ((Bundle) item).putInt(FirebaseAnalytics.Param.QUANTITY, (int) number);
      }

It was meant to fix the problem of quantity being passed as floating point, which obviously doesn't apply to prices, that are supposed to be such.

In fact I think in your case it is enough to update structs.js and index.d.ts, no need to modify any native iOS or Android code.

@aalmodovarr
Copy link

Hi @brerdem @Danchoys !

I have the same problem. Using the version "@react-native-firebase/analytics": "10.5.1" I cannot get the price of the item to be obtained correctly in firebase, it only comes out in integer format. If I pass price: 211.48 I get:

image

I have modified the structs.js and index.d.ts files to add the price (and also the currency), but the currency doesn't even appear in the item's properties.

@Danchoys
Copy link
Contributor

Danchoys commented Feb 2, 2021

@aalmodovarr Hi! I have investigated this issue further and set up a native iOS project (using the latest SDK of 7.5.0) with this code:

- (IBAction)sendEvent:(id)sender {
    NSMutableDictionary *jeggings = [@{
      kFIRParameterItemID: @"SKU_123",
      kFIRParameterItemName: @"jeggings",
      kFIRParameterItemCategory: @"pants",
      kFIRParameterItemVariant: @"black",
      kFIRParameterItemBrand: @"Google",
      kFIRParameterPrice: @9.99,
    } mutableCopy];
    
    jeggings[kFIRParameterQuantity] = @2;

    NSMutableDictionary *itemDetails = [@{
      kFIRParameterCurrency: @"USD",
      kFIRParameterValue: @19.98
    } mutableCopy];
    
    itemDetails[kFIRParameterItems] = @[jeggings];
    
    [FIRAnalytics logEventWithName:kFIREventAddToCart parameters:itemDetails];
}

While 100% legit, it still results in the following:

Screen Shot 2021-02-02 at 18 06 54

This makes me believe that this is an internal Firebase problem, and this issue has to be reported there.

Update

It also doesn't seem to be an SDK issue, rather it is either processed or displayed badly as native logs show things as expected:

2021-02-02 18:04:26.120745+0300 FirebaseTest[10483:325006] 7.5.0 - [Firebase/Analytics][I-ACS023105] Event is not subject to real-time event count daily limit. Marking an event as real-time. Event name, parameters: add_to_cart, {
    currency = USD;
    ga_debug (_dbg) = 1;
    ga_event_origin (_o) = app;
    ga_realtime (_r) = 1;
    ga_screen_class (_sc) = ViewController;
    ga_screen_id (_si) = 8091968057265159745;
    items = (
        {
        "item_brand" = Google;
        "item_category" = pants;
        "item_id" = "SKU_123";
        "item_name" = jeggings;
        "item_variant" = black;
        price = "9.99";
        quantity = 2;
    }
);
    value = 19.98;
}

@mikehardy
Copy link
Collaborator

One person's "problem" is another person's "avoid IEEE Floating Point errors when dealing with monetary values at all costs by internally using an integer with enough significant digits to carry any sub-currency-unit partial amounts"

Just sayin' :-)

@aalmodovarr
Copy link

Thanks @Danchoys for the clarification, it's appreciated!
Right, in Analytics we see the price information correctly, so it seems like a firebase display problem

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

8 participants
@brerdem @mikehardy @Danchoys @PlatonSotnykov @aalmodovarr @andersonaddo @hwq0521 and others