Google Analytics

in bridging header

#import "GAI.h"
#import "GAIFields.h"
#import "GAILogger.h"
#import "GAITracker.h"
#import "GAIDictionaryBuilder.h"

in appdelegate

    GAI.sharedInstance().trackUncaughtExceptions = true
    GAI.sharedInstance().dispatchInterval = 20
    GAI.sharedInstance().logger.logLevel = GAILogLevel.Verbose
    GAI.sharedInstance().trackerWithTrackingId("XX-123123123-1")

event tracker

    var tracker = GAI.sharedInstance().defaultTracker
    tracker.send(GAIDictionaryBuilder.createEventWithCategory("Button", action: "Pressed", label: "Button", value: nil).build() as [NSObject : AnyObject])

swift 2.0

        let appDel = UIApplication.sharedApplication().delegate as! AppDelegate
        let tracker = appDel.tracker //GAI.sharedInstance().defaultTracker
        let eventTracker: NSObject = GAIDictionaryBuilder.createEventWithCategory( "Item bought", action: "bought", label: "itemId", value: 1).build()
        tracker.send(eventTracker as! [NSObject:AnyObject])

Tags: