Thursday 21 October 2021

Expo / React Native problem displaying events in Firebase Analytics

I build an ecommerce application using expo / firebase / react native, my client asked me to add analytical events in the application from where he would see in firbase all the data provided.

How I started the implementation: Fallowind documentation provided by Expo I installed expo-firebase-analytics module,after than I fallow the implementation provided by expo I config my app.json adding file that I generated when I created project on firbase "googleServicesFile":"./google-services.json", I learned from their documentation that in order to test these events in the emulator I will have to add siweb config only during development.

"web": {
  "favicon": "./assets/favicon.png",
  "config": {
    "firebase": {
    "apiKey": "............",
    "authDomain":"...........",
    "projectId": "..........",
    "storageBucket": "..........",
    "messagingSenderId": ".........",
    "appId": "..............",
    "measurementId": ".................."
    }
  }
}

Below I tried to implement the add_to_cart event trying as much as possible to add the data I discovered on this site Google Analytics 4 Events.

addItemsToCart = async (product,qty) => {
    //Object that I created to save on redux
    const cartProd = {
        id:product.id_produs,
        product:product,
        qty:qty
    }
    //Call function that save date on redux store...
    this.props.addToCartValue(cartProd);

       //Firebae Await Event that I implemented 
        await Analytics.logEvent('add_to_cart', {
            currency:"RON",
            value:product.pret_mobile*qty,
            items:[
                {
                    item_id:cartProd.id,
                    item_name:product.nume_produs,
                    affiliation: "Google Store",
                    currency: "RON",
                    price: product.pret_mobile,
                    quantity: qty
                } 
            ]
        }).then(() => {
            console.log(' ---------------- Logging add to cart success ------------- ');
        }).catch((err)=>{
            console.log(' ---------------- Logging add to cart failed -------------- ');
        });
    }

I don't know now if this is a better implementation but I have a problem when I send the events from the expo go they are registered and items are sent. enter image description here

but when I compiled the application and adapted it on google play and when I create events in the application it appears like this.

enter image description here

At build I removed that web config because as they said in the documentation it's just testing, I don't know if I'm wrong in the implementation, I don't send the data correctly considering that value and currency are sent correctly the problem is to items.

Has anyone tried to implement Firebase Analytics with Expo before they run into the same conva problems, if so how did you manage to get through them. enter image description here



from Expo / React Native problem displaying events in Firebase Analytics

No comments:

Post a Comment