Reputation: 4882
I am trying to implement Firebase Analytics into my React Native app, and I want to log an event every time a user selected a certain category in my app:
categoryPressed(category) {
console.log('selected: ', category.props.title)
//firebase.analytics().
firebase.analytics().logEvent('Category', String(category.props.title))
this.props.navigation.navigate('ItemOverview', {
category: category,
});
}
This, however, outputs the next error:
analytics.logEvent(): Second optional argument 'params' must be an object if provided
The documentation doesn't say anything about this. I tried putting my string in an array, which doesn't help either.
Does anyone know what the proper way of logging an event with parameters is in React Native?
Upvotes: 2
Views: 2271
Reputation: 594
It says that params must be an object https://rnfirebase.io/reference/analytics#logEvent
Example:
const ecommerce = {
promotions: [{
item_id: 'sku1234',
item_name: 'Android Jogger Sweatpants',
item_category: 'Apparel/Men/Pants',
item_variant: 'Blue',
item_brand: 'Google',
price: 39.99,
currency: 'USD',
quantity: 1
}]
}
await firebase.analytics().logEvent('add_to_cart', ecommerce);
Upvotes: 1