Google Analytics not initialising in Swift

放肆的年华 提交于 2019-12-06 01:04:52

问题


My new swift app does not initialise Google Analytics for some reason. I created a bridging header in my project for all the GAnalytics files:

#import "GAI.h"
#import "GAIDictionaryBuilder.h"
#import "GAIEcommerceFields.h"
#import "GAIEcommerceProduct.h"
#import "GAIEcommerceProductAction.h"
#import "GAIEcommercePromotion.h"
#import "GAIFields.h"
#import "GAILogger.h"
#import "GAITrackedViewController.h"
#import "GAITracker.h"

And this is part of my AppDelegate.swift file:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    if NSUserDefaults.standardUserDefaults().boolForKey("allowganalytics") {
        GAI.sharedInstance().trackUncaughtExceptions = true
        GAI.sharedInstance().dispatchInterval = 10
        var tracker = GAI.sharedInstance().trackerWithTrackingId("UA-******-1")
        tracker.send(GAIDictionaryBuilder.createEventWithCategory("ui_action", action: "app_launched",label:"launch",value:nil).build())
    }
    return true
}

If I check the system log of the device, I doesn't say anything occurring to Google Analytics.


回答1:


Do like this.

     GAI.sharedInstance().trackerWithTrackingId("UA-*******-1")
                GAI.sharedInstance().defaultTracker..allowIDFACollection = true
GAI.sharedInstance().defaultTracker.send(GAIDictionaryBuilder.createEventWithCategory("ui_action", action: "app_launched",label:"launch",value:nil).build())


来源:https://stackoverflow.com/questions/26380638/google-analytics-not-initialising-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!