Skip to content

EasyPackages/EasyAnalytics

Repository files navigation

EasyAnalytics Documentation

Overview

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.

Installation

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"])

Usage

Tracking Events

EasyAnalytics provides two types of events: ScreenEvent and ClickEvent.

ScreenEvent

Use ScreenEvent to track screen views in your application.

let screenEvent = ScreenEvent(screen: "HomeScreen", class: "MainViewController")
analytics.trackEvent(screenEvent)

ClickEvent

Use ClickEvent to track user interactions with UI components.

let clickEvent = ClickEvent(screen: "HomeScreen", contentType: "Button", component: "LoginButton")
analytics.trackEvent(clickEvent)

Setting Properties

You can set various properties to provide additional context for your analytics.

App Properties

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)

Device Properties

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)

User Properties

Set properties related to the user, such as user ID.

let userProperties = UserProperties(userId: "12345")
analytics.setUserProperties(userProperties)

Custom Properties

You can also set custom properties using key-value pairs.

analytics.setProperty("theme", value: "dark")

API Reference

Protocol: Analytics

The Analytics protocol defines the core methods for tracking events and setting properties.

Methods

  • 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.

Structs

ScreenEvent

Represents a screen view event.

  • screen: String - The name of the screen.
  • class: String - The class name associated with the screen.

ClickEvent

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.

AppProperties

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).

DeviceProperties

Represents device-related properties.

  • devideModel: String - The model of the device.
  • osVersion: String - The operating system version.

UserProperties

Represents user-related properties.

  • userId: String - The unique identifier for the user.

Extensibility

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.

License

This library is available under the MIT license. See the LICENSE file for more information.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages