简体   繁体   English

Google Analytics(分析):Swift 2中的createScreenView和createItemWithTransactionId

[英]Google Analytics: createScreenView and createItemWithTransactionId in Swift 2

I'm trying to update my Google Analytics code, I have found subjects about but all are different, in some files it's gonna work and not in the others, I don't know if I implement it as well, the part of the code: 我正在尝试更新我的Google Analytics(分析)代码,我发现的主题有关,但都不同,在某些文件中它可以工作而在其他文件中却不起作用,我不知道我是否也实现了它,代码的一部分:

/*******************************
 * Tracker écran
 ********************************/

let tracker = GAI.sharedInstance().defaultTracker

tracker.set(kGAIDescription, value: "Demande Envoyé")

let eventTracker: NSObject = GAIDictionaryBuilder.createScreenView().build()

tracker.send(eventTracker as! [NSObject : AnyObject])

/*******************************
 * Tracker transaction
 ********************************/


var rangeName = ""

if let startRange = String(xml).rangeOfString("<Logement>"), endRange = String(xml).rangeOfString("</Logement>") where startRange.endIndex <= endRange.startIndex {
    rangeName = String(xml)[startRange.endIndex..<endRange.startIndex]
} else {
    print("invalid input")
}

tracker.send(NSObject = GAIDictionaryBuilder.createItemWithTransactionId(String(format: (NSUserDefaults.standardUserDefaults().objectForKey("ApplicationUniqueIdentifier")!) as! String + String(id)), name: rangeName, sku: "", category: Configuration.MyVariables.typeForm, price: 1, quantity: 1, currencyCode: "").build() as! [NSObject : AnyObject])

The screenView is working, but I it an error for the transaction: screenView正在运行,但我对交易出错:

Cannot assign to immutable expression of type 'NSObject.Type' 无法分配给'NSObject.Type'类型的不可变表达式

In your last line, you are trying to assign your newly created object to the NSObject class, hence the Cannot assign to immutable expression of type 'NSObject.Type' error. 在最后一行中,您尝试将新创建的对象分配给NSObject类,因此“ Cannot assign to immutable expression of type 'NSObject.Type'错误。

You should create your transaction item the same way as the screen view so you should change your code to make it look like this: 您应该以与屏幕视图相同的方式创建交易项目,因此您应该更改代码以使其看起来像这样:

let eventTracker2: NSObject = GAIDictionaryBuilder.createItemWithTransactionId(String(format: (NSUserDefaults.standardUserDefaults().objectForKey("ApplicationUniqueIdentifier")!) as! String + String(id)), name: rangeName, sku: "", category: Configuration.MyVariables.typeForm, price: 1, quantity: 1, currencyCode: "").build()

tracker.send(eventTracker2 as! [NSObject : AnyObject])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM