Swift – Google Analytics

I really wanted a simple way to add Google Analytics to my iOS (swift) app without subclassing the way they recommend. Swift makes this easy with Extensions. All you have to do add GA to your swift app (I highly recommend using cocoapods) and add this extension to your code base.

Extensions are essentially a category, if you’re coming from objective-c. From there, it’s as simple as adding this code in your viewDidLoad method.

self.setScreeName("My Screen Name")

I won’t cover adding Cocoapods to a Swift project since it’s been covered many times.

, , ,