Swiftpack.co - Package - thejohnlima/BaseTracking


GitHub release Build Status CocoaPods GitHub repo size License Platform Donate

BaseTracking is the easiest way to setup your analytics in Swift.


  • iOS 9.3+
  • Swift 5.0+

βš’ Installation

Swift Package Manager

BaseTracking is available through SPM. To install it, follow the steps:

Open Xcode project > File > Swift Packages > Add Package Dependecy

After that, put the url in the field: https://github.com/thejohnlima/BaseTracking.git


BaseTracking is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'BaseTracking'

and run pod install

πŸŽ“ How to use

Example using Firebase Analytics:

Import library in your swift file

import BaseTracking

In your tracking manager file create an extension for BaseTrackingProtocol:

extension TrackingManager: BaseTrackingProtocol {
  func configure() {

  func track(event log: BaseTrackingEventLogData) {
    Analytics.logEvent(log.name, parameters: log.parameters)

  func track(view data: BaseTrackingViewData) {
    Analytics.setScreenName(data.name, screenClass: data.className)

And create another one to prepare protocol methods

extension BaseTrackingEventLog {
  static func trackView(name: ScreenName, className: ClassName? = nil) {
    let data = BaseTrackingViewData(
      name: name.rawValue as? String ?? "",
      className: className?.rawValue as? String
    TrackingManager.shared.track(view: data)

  static func trackEvent(name: EventName, parameters: EventParameters? = nil) {
    let data = BaseTrackingEventLogData(
      name: name.rawValue as? String ?? "",
      parameters: parameters?.rawValue as? [String: Any]
    TrackingManager.shared.track(event: data)

Now, create a tracking file for some area of the app.

struct HomeTracking: BaseTrackingEventLog {
  enum ScreenName: String {
    case home

  enum EventName: String {
    case showDetails = "show_home_details"

  typealias ClassName = CustomRawRepresentable
  typealias EventParameters = CustomRawRepresentable

extension HomeTracking {
  static func getSelectButtonParameter(_ value: Any) -> EventParameters? {
    let item: [String: Any] = ["button_name": value]
    return EventParameters(rawValue: item)

Than, let's get tracking some data:

class HomeViewController: UIViewController {

  override func viewDidLoad() {

  override func viewWillAppear(_ animated: Bool) {
    HomeTracking.trackView(name: .home)

  @IBAction private func showDetails(sender: Any?) {
    let buttonName = (sender as? UIBarButtonItem)?.title ?? ""
    let parameters = HomeTracking.getSelectButtonParameter(buttonName)
    HomeTracking.trackEvent(name: .showDetails, parameters: parameters)

If you need examples unsing GA, take a look at demo project.

πŸ™‹πŸ»β€ Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request. πŸ‘¨πŸ»β€πŸ’»

πŸ“œ License

BaseTracking is under MIT license. See the LICENSE file for more info.


Stars: 1


Used By

Total: 0


Version 1.0.3 - 2019-12-19 01:18:04

  • Update dependencies;
  • Add Github actions;

Version 1.0.2 - 2019-08-25 15:24:35

  • Add support for SPM;

Version 1.0.1 - 2019-03-14 03:42:51

β€’ Adjust demo project; β€’ Adjust extension access modifier;

Version 1.0.0 - 2019-03-14 03:10:35

First release version