Skip to content

Instantly share code, notes, and snippets.

@zntfdr
Last active September 24, 2024 06:29
Show Gist options
  • Save zntfdr/450fb3ee35ccde3f34085269eecafb9a to your computer and use it in GitHub Desktop.
Save zntfdr/450fb3ee35ccde3f34085269eecafb9a to your computer and use it in GitHub Desktop.
Firebase iOS Version breakdown
// How to:
// 1. Go in the Firebase Analytics Dashboard
// 2. Scroll down, select `Device` under the "What is your audience like?" widget
// 3. Export the CSV data (top right of the corner, there's a `...` menu with Download CSV option)
// 4. Open the file and select the iOS breakdown raw data
// 5. Replace your data with the sample data in this script
// 6. Run the script in a Xcode Playground
// 7. See the terminal output
var data = """
ios 13.1.3,60599
ios 13.1.2,43022
ios 12.4.1,24814
ios 12.4.2,11399
ios 12.3.1,6736
ios 13.2,6170
ios 12.4,4643
ios 13.0,4474
ios 13.1.1,3476
ios 12.2,2475
ios 13.1,2263
ios 11.4.1,1906
ios 12.1.4,1498
ios 12.1.2,876
ios 12.1,668
ios 11.4,581
ios 10.3.3,532
ios 12.3.2,452
ios 12.0.1,433
ios 10.3.4,410
ios 11.3.1,385
ios 11.2.6,361
ios 12.0,348
ios 12.4.3,274
ios 11.3,256
ios 10.2.1,224
ios 11.2.1,221
ios 12.3,192
ios 11.1.2,179
ios 11.2.5,179
ios 10.3.2,158
ios 11.0.3,149
ios 12.1.3,128
ios 12.1.1,115
ios 10.1.1,105
ios 10.2,97
ios 11.2.2,90
ios 11.2,82
ios 11.0,78
ios 11.1,64
ios 11.0.2,62
ios 10.3.1,61
ios 11.1.1,54
ios 10.0.2,40
ios 11.0.1,39
ios 10.1,12
ios 10.0.1,11
ios 10.3,8
ios 10.0.3,2
ios 9.1,1
"""
let lines = data.split { $0.isNewline }
var iOSDictionary: [String: Int] = [:]
for line in lines {
let iOSVersion: String = String(line.split(separator: ".").first!)
let numberOfUsers = Int(line.split(separator: ",").last!)!
iOSDictionary[iOSVersion, default: 0] += numberOfUsers
}
let totalUsers: Int = iOSDictionary.values.reduce(into: 0, { $0 += $1 })
for (iOSVersion, numberOfUsers) in iOSDictionary {
let percent = String(format: "%.2f", Double(numberOfUsers) / Double(totalUsers) * Double(100))
print("\(iOSVersion): \(percent)%")
}
@steipete
Copy link

Thank you, this has been really helpful!

@Bunn
Copy link

Bunn commented Jun 16, 2020

Thank you for this.

@Jimmy-Prime
Copy link

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

Adding version sort for output would be better.

@gtsifrikas
Copy link

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

@paulhimes
Copy link

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])!

@zntfdr
Copy link
Author

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