0

I use firebase infrastructure as backend to process my in-app-purchases... as i have many gateways and accept offline payments i cannot rely only on google-billing to log the purchase events.

I would like to do it in my firebase function that process gateway payment status and updates the database, but seams that firebase analytics is not well imported to the cloud functions infrastructure

    var firebase = require('firebase');
var analytics = firebase.initializeApp().analytics();

exports.teste = (req, res) => {

    analytics.logEvent('analytics.EventName.PURCHASE', {
        currency: 'BRL',
        items: [{
            item_id: 'sku'
        }],
        shipping: 1.00,
        tax: 2.00,
        transaction_id: 'SM_1234',
        value: 20.0
    });

    let message = req.query.message || req.body.message || 'Hello World!';
    res.status(200).send(message);
};


A 2020-06-25T20:50:37.613Z teste Provided module can't be loaded. teste  
A 2020-06-25T20:50:37.613Z teste Is there a syntax error in your code? teste  

the admin sdk doesn't include the analytics module.

is there any way to log the events in the cloud functions?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Rafael Lima
  • 3,079
  • 3
  • 41
  • 105

1 Answers1

1

There is no provided backend SDK for logging events to Analytics. This can only be done in the client app. Your only alternative is to get the client app to log the event somehow.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • i tried that by sending a notification (through cloud functions) with the purchase in the data field of the notification but i get the feeling that some purchases werent being logged (like 20%) so maybe some users ignore the notification... or have any connection issues when opening it. any suggestion about what to do? – Rafael Lima Jun 25 '20 at 21:29
  • No, that's my only suggestion. – Doug Stevenson Jun 25 '20 at 21:30