EasyAnalytics is a lightweight and extensible analytics library designed to simplify event tracking and property management in your application. It provides a structured way to track screen views, user interactions, and application/device/user properties.
To integrate EasyAnalytics into your project, add it as a dependency in your Package.swift
file:
.package(url: "https://github.com/your-repo/EasyAnalytics.git", from: "1.0.0")
Then, include it in the dependencies of your target:
.target(name: "YourTarget", dependencies: ["EasyAnalytics"])
EasyAnalytics provides two types of events: ScreenEvent
and ClickEvent
.
Use ScreenEvent
to track screen views in your application.
let screenEvent = ScreenEvent(screen: "HomeScreen", class: "MainViewController")
analytics.trackEvent(screenEvent)
Use ClickEvent
to track user interactions with UI components.
let clickEvent = ClickEvent(screen: "HomeScreen", contentType: "Button", component: "LoginButton")
analytics.trackEvent(clickEvent)
You can set various properties to provide additional context for your analytics.
Set properties related to the application, such as name, version, and environment.
let appProperties = AppProperties(appName: "MyApp", appVersion: "1.0.0", environment: "Production")
analytics.setAppProperties(appProperties)
Set properties related to the device, such as model and OS version.
let deviceProperties = DeviceProperties(devideModel: "iPhone 14", osVersion: "iOS 16.4")
analytics.setDeviceProperties(deviceProperties)
Set properties related to the user, such as user ID.
let userProperties = UserProperties(userId: "12345")
analytics.setUserProperties(userProperties)
You can also set custom properties using key-value pairs.
analytics.setProperty("theme", value: "dark")
The Analytics
protocol defines the core methods for tracking events and setting properties.
func trackEvent(_ event: ScreenEvent)
- Tracks a screen view event.
func trackEvent(_ event: ClickEvent)
- Tracks a click event.
func setProperty(_ property: String, value: String)
- Sets a custom property.
func setAppProperties(_ properties: AppProperties)
- Sets application-related properties.
func setDeviceProperties(_ properties: DeviceProperties)
- Sets device-related properties.
func setUserProperties(_ properties: UserProperties)
- Sets user-related properties.
Represents a screen view event.
screen: String
- The name of the screen.class: String
- The class name associated with the screen.
Represents a user interaction event.
screen: String
- The name of the screen where the interaction occurred.contentType: String
- The type of content interacted with.component: String
- The specific component interacted with.
Represents application-related properties.
appName: String
- The name of the application.appVersion: String
- The version of the application.environment: String
- The environment (e.g., Production, Staging).
Represents device-related properties.
devideModel: String
- The model of the device.osVersion: String
- The operating system version.
Represents user-related properties.
userId: String
- The unique identifier for the user.
You can extend the Analytics
protocol to integrate with third-party analytics providers. Implement the protocol in your custom adapter and use it in your application.
This library is available under the MIT license. See the LICENSE file for more information.