Reputation: 849
I'm integrating my android app with Google analytics v4. I'm in Argentina, so my currency code is "ARS", not "USD". I need to specify the local currency code (of any other country), otherwise it sends wrong information. For example, the price tag of an article says it costs "9,32 ARS", if I don't specify the currency code it sends "9,32 USD". Thanks
// Send Item
googleTracker.send(new HitBuilders.ItemBuilder()
.setTransactionId(purchase.getOrderId())
.setName(purchase.getPackageName())
.setSku(purchase.getSku())
.setCategory("Coins")
.setPrice(skuDetails.getPriceMicros())
.setQuantity(1)
.setCurrencyCode(????)
.build());
Upvotes: 2
Views: 2490
Reputation: 73
In android many ways to get local currency. But the bad thing is, In some cases, we got device-specific issues.
val currency = Currency.getInstance(Locale.getDefault())
currency.currencyCode
currency.symbol
The above code gives the currency code a and symbol, But have an issue, If we change the phone locale, the currency also changed.
We have another way to get local currency, if we change the Phone locale, the local currency is not affected
Currency.getInstance(Locale("",tm.networkCountryIso)).currencyCode.toString()
Currency.getInstance(Locale("",tm.networkCountryIso)).symbol.toString()
Upvotes: 0
Reputation: 5767
According to the measurement protocol definition for currency code you need to pass a valid ISO 4217 currency code to HitBuilders.ItemBuilder.setCurrencyCode() call. Android provides Currency class that support ISO 4217. You should be able to use it to compose the parameter you need for the setCurrencyCode call.
Upvotes: 0
Reputation: 849
I actually could get it working using this answer here: SOLUTION
Google added to its API a new field which is "price_currency_code", to getSkuDetails, which allows us to get the currency code of a transaction. You must edit SkuDetails.java as this answer shows.
Upvotes: 0
Reputation: 3885
You can try like this
Currency currency = Currency.getInstance(Locale.getDefault());
String currencyCode = currency. getCurrencyCode();
Upvotes: 5