Search code examples
iosgoogle-analyticsgoogle-tag-manageritunes-storegoogle-analytics-sdk

iOS app with iTunes store - get currency code (not priceLocal)


We have an iOS app with in-app purchase and we want to track transactions with Google Analytics (enhanced ecommerce). We already have the proper handling for priceLocal, that's not the issue... we need to tell GA the specific currency code in use by the user. This info doesn't seems to be available directly and we would rather not do our own lookup.

Current code abstract:

// Set locale
NSLocale *storeLocale = product.priceLocale;
// instead of storeCountry we need storeCurrency, like USD, CAD, EUR, GBP...
NSString *storeCountry = (NSString *)CFLocaleGetValue((CFLocaleRef)storeLocale, kCFLocaleCountryCode);
[ecommerced setObject:storeCountry forKey:@"currencyCode"];

Solution

  • I haven't run this code to see if it works but this is how to get what you want.

    NSNumberFormatter *formatter = [NSNumberFormatter new];
    [formatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    [formatter setLocale: storeLocale];
    
    NSLog("The currency code is: %@", formatter.currencyCode);
    

    NSNumberFormatter Documentation