An injectable analytics wrapper for Apple platforms.
This lightweight framework provides a generic wrapper for analytics SDK’s that is suitable for Dependency Injection. Its objective is to avoid tightly coupling an application with a specific analytics provider.
Documentation is automatically generated from source code comments and rendered as a static website hosted via GitHub Pages at: https://yml-org.github.io/yanalytics-ios/
Usage
AnalyticsEngine
is an abstraction meant to represent any analytics package, whether that be Firebase, Adobe, any other 3rd party analytics vendor, or your own custom implementation.
The point is to abtract away the specifics of choice of analytics vendor, so that it may be swapped at any time without incurring major tech debt.
It also encourages the use of dependency injection to provide the analytics engine to components that require it. This should make it easier to write unit tests for all these components (by either injecting a mock or even nothing at all).
AnalyticsEngine has exactly one method:
public protocol AnalyticsEngine {
/// Track an analytics event
/// - Parameter event: the event to log
func track(event: AnalyticsEvent)
}
AnalyticsEvent
is an enum with a few cases for typical events.
public enum AnalyticsEvent {
/// Screen view event
/// - Parameter screenName: screen name
case screenView(screenName: String)
/// User property event
/// - Parameters:
/// - name: user property name
/// - value: user property value
case userProperty(name: String, value: String)
/// Generic event
/// - Parameters:
/// - name: event name
/// - parameters: event metadata to track
case event(name: String, parameters: Metadata?)
}
CompoundAnalyticsEngine
is a helper implementation of AnalyticsEngine that lets you specify an array of engines. This would allow you to combine a logger together with your actual analytics engine (e.g. Firebase) to assist with debugging.
ConsoleAnalyticsEngine
is a simple implementation of AnalyticsEngine that logs output using print statements. (For most cases you should use LoggerAnalyticsEngine instead.)
LoggerAnalyticsEngine
is a simple implementation of AnalyticsEngine that logs output using Apple’s’ Logger api.
Installation
You can add Y—Analytics to an Xcode project by adding it as a package dependency.
If you’re submitting before and after screenshots, movies, or GIF’s, enter them in a two-column table so that they can be viewed side-by-side.
When merging a pull request:
Make sure the branch is rebased (not merged) off of the latest HEAD from the parent branch. This keeps our git history easy to read and understand.
Make sure the branch is deleted upon merge (should be automatic).
Releasing new versions
Tag the corresponding commit with the new version (e.g. 1.0.5)
Push the local tag to remote
Generating Documentation (via Jazzy)
You can generate your own local set of documentation directly from the source code using the following command from Terminal:
jazzy
This generates a set of documentation under /docs. The default configuration is set in the default config file .jazzy.yaml file.
To view additional documentation options type:
jazzy --help
A GitHub Action automatically runs each time a commit is pushed to main that runs Jazzy to generate the documentation for our GitHub page at: https://yml-org.github.io/yanalytics-ios/
An injectable analytics wrapper for Apple platforms.
This lightweight framework provides a generic wrapper for analytics SDK’s that is suitable for Dependency Injection. Its objective is to avoid tightly coupling an application with a specific analytics provider.
Licensing
Y—Analytics is licensed under the Apache 2.0 license.
Documentation
Documentation is automatically generated from source code comments and rendered as a static website hosted via GitHub Pages at: https://yml-org.github.io/yanalytics-ios/
Usage
AnalyticsEngine
is an abstraction meant to represent any analytics package, whether that be Firebase, Adobe, any other 3rd party analytics vendor, or your own custom implementation.
The point is to abtract away the specifics of choice of analytics vendor, so that it may be swapped at any time without incurring major tech debt.
It also encourages the use of dependency injection to provide the analytics engine to components that require it. This should make it easier to write unit tests for all these components (by either injecting a mock or even nothing at all).
AnalyticsEngine
has exactly one method:AnalyticsEvent
is an enum with a few cases for typical events.
CompoundAnalyticsEngine
is a helper implementation of
AnalyticsEngine
that lets you specify an array of engines. This would allow you to combine a logger together with your actual analytics engine (e.g. Firebase) to assist with debugging.ConsoleAnalyticsEngine
is a simple implementation of
AnalyticsEngine
that logs output usingprint
statements. (For most cases you should useLoggerAnalyticsEngine
instead.)LoggerAnalyticsEngine
is a simple implementation of
AnalyticsEngine
that logs output using Apple’s’Logger
api.Installation
You can add Y—Analytics to an Xcode project by adding it as a package dependency.
Contributing to Y—Analytics
Requirements
SwiftLint (linter)
Jazzy (documentation)
Setup
Clone the repo and open
Package.swift
in Xcode.Versioning strategy
We utilize semantic versioning.
e.g.
Branching strategy
We utilize a simplified branching strategy for our frameworks.
main
main
main
as they are completed and approved.main
gets tagged with an updated version # for each releaseBranch naming conventions:
e.g.
Pull Requests
Prior to submitting a pull request you should:
swiftlint
from the command line and confirm that there are no violations.jazzy
from the command line and confirm that you have 100% documentation coverage.git rebase -i HEAD~{commit-count}
to squash your last {commit-count} commits together into functional chunks.main
) has been updated since you created your branch, usegit rebase main
to rebase your branch.When submitting a pull request:
When merging a pull request:
Releasing new versions
1.0.5
)Generating Documentation (via Jazzy)
You can generate your own local set of documentation directly from the source code using the following command from Terminal:
This generates a set of documentation under
/docs
. The default configuration is set in the default config file.jazzy.yaml
file.To view additional documentation options type:
A GitHub Action automatically runs each time a commit is pushed to
main
that runs Jazzy to generate the documentation for our GitHub page at: https://yml-org.github.io/yanalytics-ios/