Latest 1.0.1
Homepage https://github.com/limadeveloper/BaseTracking
License MIT
Platforms ios 9.3, requires ARC
Authors

GitHub release
Build Status
CocoaPods
GitHub repo size
License

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

Requirements

  • iOS 9.3+
  • Swift 4.0+

Installation

CocoaPods

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

pod 'BaseTracking', '~> 1.0'

and run pod install

Manual

Just copy source folder to your project.

Framework > BaseTracking > Source

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() {
    FirebaseApp.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.
Example:

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() {
    super.viewDidLoad()
  }

  override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    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.

Latest podspec

{
    "name": "BaseTracking",
    "version": "1.0.1",
    "summary": "BaseTracking is the easiest way to setup your analytics in Swift",
    "requires_arc": true,
    "homepage": "https://github.com/limadeveloper/BaseTracking",
    "license": "MIT",
    "authors": {
        "John Lima": "[email protected]"
    },
    "social_media_url": "https://twitter.com/johncarloslima",
    "platforms": {
        "ios": "9.3"
    },
    "source": {
        "git": "https://github.com/limadeveloper/BaseTracking.git",
        "tag": "1.0.1"
    },
    "source_files": "Framework/BaseTracking/Source/*.{swift}",
    "swift_version": "4.0"
}

Pin It on Pinterest

Share This