Được TopGit lập chỉ mục từ metadata GitHub: devxoul/Umbrella có 615 sao, viết chủ yếu bằng Swift. ☂️ Analytics abstraction layer for Swift
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Analytics abstraction layer for Swift. Inspired by Moya.
Table of Contents
Why?
Features
At a Glance
Getting Started
Defining Events
Using Analytics
Built-in Providers
Creating Custom Providers
Installation
Contributing
Generating Xcode Workspace
Creating New Provider
License
Why?
There are many tools for mobile app analytics such as Firebase, Google Analytics, Fabric Answers, Flurry, Mixpanel, etc. You might use one or more of those in your application. But most of those SDKs have some problems: if you use multiple analytics tools, your code will be messed up. And the SDKs take event name as a string and parameters as a dictionary which is not guaranteed by Swift compiler. It means that if you change the event definition, you should find all related code by your hand. It has an opportunity that cause a human error. Umbrella uses Swift enums and the associated values to solve these problems.
Features
💪 Taking advantages of Swift compiler by using an enum and associated values.
🎯 Logging events to multiple analytics providers at once.
First of all, you should define all of your events in a single enum. Let's assume that we have three events that have associated parameters.
enum MyAppEvent {
case signup(username: String)
case viewContent(productID: Int)
case purchase(productID: Int, price: Float)
}
Then make the enum to conform the protocol EventType. It requires two functions: name(for:) and parameters(for:).
extension MyAppEvent: EventType {
/// An event name to be logged
func name(for provider: ProviderType) -> String? {
switch self {
case .signup: return "signup"
case .viewContent: return "view_content"
case .purchase: return "purchase"
}
}
/// Parameters to be logged
func parameters(for provider: ProviderType) -> [String: Any]? {
switch self {
case let .signup(username):
return ["username": username]
case let .viewContent(productID):
return ["product_id": productID]
case let .purchase(productID, price):
return ["product_id": productID, "price": price]
}
}
}
You can even provide different event names and parameters by providers.
Using Analytics
You can define an Analytics instance anywhere but it's recommended to define at a global scope.
let analytics = Analytics<MyAppEvent>()
Then you should register providers. A prodiver is a wrapper for an actual analytics service such as Firebase and Fabric Answers. It's recommended to register providers in application(_:didFinishLaunchingWithOptions:).
If you finished those steps, you can now log the events 🎉
analytics.log(.signup(username: "devxoul"))
Built-in Providers
There are several built-in providers.
AmplitudeProvider (Amplitude-iOS)
AnswersProvider (Answers)
AppboyProvider (Appboy-iOS-SDK)
AppsFlyerProvider (AppsFlyerFramework)
FacebookProvider (FBSDKCoreKit)
FirebaseProvider (Firebase/Analytics)
FlurryProvider (Flurry-iOS-SDK/FabricSDK)
IntercomProvider (Intercom)
LocalyticsProvider (Localytics)
MixpanelProvider (Mixpanel)
SegmentProvider (Analytics)
If there's no provider you're looking for, you can create an issue or create custom providers. It's also welcomed to create a pull request for missing services 🎉
Creating Custom Providers
If there's no built-in provider for the serivce you're using, you can also create your own. It's easy to create a provider: just create a class and conform to the protocol ProviderType.
final class MyAwesomeProvider: ProviderType {
func log(_ eventName: String, parameters: [String: Any]?) {
AwesomeAnalytics.logEvent(withName: eventName, parameters: parameters)
}
}
Installation
Umbrella currently support CocoaPods only.
pod 'Umbrella'
pod 'Umbrella/Firebase' # using with built-in FirebaseProvider
pod 'Umbrella/...'
Contributing
Any discussions and pull requests are welcomed 💖
Generating Xcode Workspace
$ make project
This will automatically generate Umbrella.xcworkspace and perform pod install.
Creating New Provider
For example, imagine that we are going to create a new provider for an analytics service 'Raincoat'.
Add a library and a target definition in Package.swift.
target 'UmbrellaFirebaseTests' do
platform :ios, '8.0'
pod 'Firebase/Analytics'
end
target 'UmbrellaMixpanelTests' do
platform :ios, '8.0'
pod 'Mixpanel'
end
+ target 'UmbrellaRaincoatTests' do
+ platform :ios, '8.0'
+ pod 'Raincoat'
+ end
Add a CocoaPods subspec in Umbrella.podspec.
s.subspec "Firebase" do |ss|
ss.source_files = "Sources/UmbrellaFirebase/*.swift"
ss.dependency "Umbrella/Core"
end
s.subspec "Mixpanel" do |ss|
ss.source_files = "Sources/UmbrellaMixpanel/*.swift"
ss.dependency "Umbrella/Core"
end
+ s.subspec "Raincoat" do |ss|
+ ss.source_files = "Sources/UmbrellaRaincoat/*.swift"
+ ss.dependency "Umbrella/Core"
+ end
Create a Xcode workspace and run tests. Don't forget to check the code coverage to ensure that tests can cover the new provider.
$ make project
License
Umbrella is under MIT license. See the LICENSE file for more info.
devxoul/Umbrella thuộc nhóm Data trên TopGit, cùng 2 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
devxoul/Umbrella có bao nhiêu sao?
devxoul/Umbrella có 615 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/devxoul/Umbrella. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
devxoul/Umbrella có phải mã nguồn mở không?
Có — devxoul/Umbrella phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/devxoul/Umbrella.
devxoul/Umbrella có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho devxoul/Umbrella. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
devxoul/Umbrella là gì?
devxoul/Umbrella (devxoul/Umbrella) là dự án Swift trên GitHub. Theo mô tả gốc: ☂️ Analytics abstraction layer for Swift
devxoul/Umbrella so với các dự án Data khác thế nào?
devxoul/Umbrella được TopGit xếp vào nhóm Data, với 615 sao GitHub và viết bằng Swift. Xem trang chủ đề Data trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc thêm về devxoul/Umbrella ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/devxoul/Umbrella là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc Umbrella có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về Umbrella.