My app contains in-app products that can be purchased. I use the billing API to retrieve the list of products that can be purchased and their prices. The retrieved price is a formatted String containing both the currency and price, for instance "$2.50".
Now I use as well Google Analytics API to track purchases. For sending the price, this API takes a long parameter in micros. So I should send (2.50*1000000).
Is there an API to convert the first price (retrieved from Billing API) to the second one (to send to Analytics API)?
Of course I could do a simple String parsing conversion myself, but I'm afraid of unexpected cases if I do so. For instance, in some locales, the price would contain "," instead of ".".
Edit
A natural solutions would be to use NumberFormat to convert from "$2.50" to 2.50.
Double price = NumberFormat.getCurrencyInstance().parse(priceStr).doubleValue();
However, the price string format retrieved from Google Play is apparently in the locale of the country where the phone is located, but the NumberFormat would use the locale of the phone which is not necessarily the same...
Use Tag Manager with Google Analytics and Firebase. To get the latest mobile app report features in Google Analytics, use Firebase in your Android and iOS apps. Once enabled in your app, Google Analytics will automatically collect and report on built-in events and user properties.
Log in to your Google Analytics account and go to Admin settings, then go to View Settings. Change your currency and hit the save button.
Although it's not officially documented the Billing API already provides the necessary data in the getSkuDetails()
response.
Besides the price
field you also retrieve the following:
price_currency_code
The ISO currency code
price_amount_micros
The product price in micros (Note: net price)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With