Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Firebase iOS Version breakdown
// How to:
// 1. Open the Firebase Analytics Dashboard
// 2. Scroll to bottom, where you see the "Users by Device model" widget
// 3. Click "View device models" in that widget (this opens the "Tech details" Firebase Analytics page)
// 4. Above the table shown in the new page, click on the “Device model” drop down menu and select “OS with Version”
// 5. Make sure to select “OS with version” and not “OS Version”
// 6. On the top right corner of the page, click on the “Share this report” icon (next to the date)
// 7. Click “Download file” on the new side bar, then “Download CSV"
// 8. Open the file and select the iOS/Android breakdown raw data
// 9. Replace the sample data in this script with your data
// 10. Run the script in a Xcode Playground or command line
// 11. See the terminal output
import Foundation
var data = """
iOS 15.0.2,3160,890
iOS 15.1,3049,814
iOS 14.8,2882,574
Android 11,2636,743
iOS 14.8.1,1877,234
Android 10,1255,280
iOS 14.7.1,1155,261
Android 9,459,122
iOS 15.0,411,209
iOS 14.6,391,92
iOS 15.0.1,353,175
iOS 14.4.2,147,39
iOS 15.1.1,135,28
let lines = data.split { $0.isNewline }
var iOSDictionary: [String: Int] = [:]
for line in lines where line.hasPrefix("iOS"){
let iOSVersion: String = String(line.split(separator: ".").first!)
let numberOfUsers = Int(line.split(separator: ",")[1])!
iOSDictionary[iOSVersion, default: 0] += numberOfUsers
let totalUsers: Int = iOSDictionary.values.reduce(into: 0, { $0 += $1 })
for (iOSVersion, numberOfUsers) in iOSDictionary.sorted(by: >) {
let percent = String(format: "%.2f", Double(numberOfUsers) / Double(totalUsers) * Double(100))
print("\(iOSVersion): \(percent)%")
Copy link

steipete commented Jun 16, 2020

Thank you, this has been really helpful!

Copy link

Bunn commented Jun 16, 2020

Thank you for this.

Copy link

Jimmy-Prime commented Jun 16, 2020

iOSDictionary.sorted(by: { $0.key.localizedStandardCompare($1.key) == .orderedDescending })

Adding version sort for output would be better.

Copy link

gtsifrikas commented Nov 11, 2020

This is great! I don't know why firebase still hasn't such a breakdown..

Copy link

paulhimes commented Nov 22, 2021

The CSV format I get from Firebase labels the columns like this:
OS with version,Users,New users

It looks like your script is adding up the numbers in the last column (New users) like this:
let numberOfUsers = Int(line.split(separator: ",").last!)!

Should it instead add up the numbers in the second-to-last column (Users) like this?
let numberOfUsers = Int(line.split(separator: ",")[1])!

Copy link

zntfdr commented Nov 23, 2021

@paulhimes nice catch 👏🏻 Gist updated, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment