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. Filter iOS Platform only
// 3. Scroll down, select `Device` under the "What is your audience like?" widget
// 4. Export the CSV data (top right corner, there's a download button with Download CSV option)
// 5. Open the file and select the iOS breakdown raw data
// 6. Replace your data with the sample data in this script
// 7. Run the script in a Xcode Playground
// 8. See the terminal output
import Foundation
var data = """
ios 13.1.3,38215
iOS 13.1.3,14333
ios 13.2.3,12667
iOS 13.2.3,9568
ios 12.4.1,8392
ios 13.2.2,6816
ios 13.1.2,6652
ios 13.2,5439
ios 12.4.2,4008
ios 12.4.3,3715
iOS 12.4.1,3111
ios 12.3.1,3021
iOS 13.1.2,2514
iOS 12.4.3,2455
"""
let lines = data.split { $0.isNewline }
var iOSDictionary: [String: Int] = [:]
for line in lines {
let iOSVersion: String = String(line.split(separator: ".").first!).lowercased()
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