Google Analytics未在Swift中初始化 [英] Google Analytics not initialising in Swift
本文介绍了Google Analytics未在Swift中初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#importGAI.h
# importGAIDictionaryBuilder.h
#importGAIEcommerceFields.h
#importGAIEcommerceProduct.h
#importGAIEcommerceProductAction.h
#importGAIEcommercePromotion.h
#importGAIFields.h
#importGAILogger.h
#importGAITrackedViewController.h
#importGAITracker.h
这是我的AppDelegate.swift文件的一部分:
<$ p $ func application(application:UIApplication,didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) - > Bool {
//在应用程序启动后替代自定义点。
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
}
如果我检查设备的系统日志,我没有说Google Analytics发生了什么。 解决方案
这样做。
GAI.sharedInstance()。trackerWithTrackingId(UA - ******* - 1)
GAI.sharedInstance()。defaultTracker..allowIDFACollection = true
GAI.sharedInstance()。defaultTracker.send(GAIDictionaryBuilder.createEventWithCategory(ui_action,action:app_launched,label:launch,值:无).build ())
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.
解决方案
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())
这篇关于Google Analytics未在Swift中初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文