Skip to content

Instantly share code, notes, and snippets.

@zntfdr
Last active March 27, 2024 15:06
  • Star 97 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save zntfdr/450fb3ee35ccde3f34085269eecafb9a to your computer and use it in GitHub Desktop.
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)%")
}
@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