Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WildStudio/77b3374445132b9f8bf2e007690eb394 to your computer and use it in GitHub Desktop.
Save WildStudio/77b3374445132b9f8bf2e007690eb394 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)%")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment