在为 iOS 实施增强的电子商务功能后,谷歌分析电子商务概览显示收入为零。我已经直接实施了交易测量,没有任何结帐步骤。控制台输出与其他变量一起打印正确的收入值,但之后是“http status -1”。我已经启动了“缺少电子商务数据”通知检查,但已经 3 天了,它仍然处于等待状态。有谁知道如何解决这个问题?
我一直在关注官方的谷歌电子商务指南(衡量交易部分): https ://developers.google.com/analytics/devguides/collection/ios/v3/enhanced-ecommerce#measuring-transactions
PS:Google Analytics 已启用增强型电子商务,GoogleService-Info.plist 已添加到项目中。
我的代码:
static func tagCheckoutFromBookingInfo(bookingInfo: BookingInfo?, discountCode: String?) {
//#if ANALYTICS
let eventData = ProductInfo()
let generalProductDict = eventData.getPayload(bookingInfo?.property, priceInfo: bookingInfo?.propertyPriceInfo(), specificInfo: nil, positionInList: nil)
let product = ecommerceProductFromGeneralProductDict(generalProductDict, discountCode: discountCode)
let builder = GAIDictionaryBuilder.createEventWithCategory(GTMEcommerceKeys.CheckoutCategory.rawValue, action: GTMEcommerceKeys.CheckoutPurchase.rawValue, label: nil, value: nil)
let action = GAIEcommerceProductAction()
action.setAction(kGAIPAPurchase)
action.setTransactionId("T123")
action.setAffiliation(GTMEcommerceKeys.CheckoutAffiliaction.rawValue)
action.setRevenue(NSNumber(double: GTMHelper.priceFromDict(generalProductDict)))
action.setCouponCode(discountCode ?? "")
builder.setProductAction(action)
builder.addProduct(product)
let build: [NSObject: AnyObject] = builder.build() as [NSObject : AnyObject]
tracker.send(build)
//#endif
}
static func ecommerceProductFromGeneralProductDict(dict: [String: AnyObject]?, discountCode: String?) -> GAIEcommerceProduct {
let product = GAIEcommerceProduct()
let productId = (dict?[GTMKeys.ProductId.rawValue] as? String) ?? ""
let productName = (dict?[GTMKeys.ProductName.rawValue] as? String) ?? ""
product.setId(productId)
product.setName(productName)
if discountCode != nil {
product.setCouponCode(discountCode ?? "")
}
if let productCategory = dict?[GTMKeys.ProductType.rawValue] as? String {
product.setCategory(productCategory)
}
product.setPrice(GTMHelper.priceFromDict(dict))
product.setQuantity(NSNumber(integer: 1))
return product
}
控制台输出:
2016-08-05 16:41:28.986 Belvilla[1435:339806] VERBOSE: GoogleAnalytics 3.14 -[GAIBatchingDispatcher persist:] (GAIBatchingDispatcher.m:517): Saved hit: {
parameters = {
"&_crc" = 0;
"&_s" = 3;
"&_u" = ".nteynL";
"&_v" = "mi3.1.4";
"&a" = 655...;
"&aid" = "--------------";
"&an" = Name;
"&ate" = "<null>";
"&av" = "3.4.0";
"&cid" = "f40c6c80-3ec9-43...";
"&dm" = "iPhone6,1";
"&ds" = app;
"&ea" = Purchase;
"&ec" = Ecommerce;
"&el" = "<null>";
"&ev" = "<null>";
"&idfa" = "<null>";
"&pa" = purchase;
"&pr1ca" = "Holiday home";
"&pr1cc" = "";
"&pr1id" = "XX-00-20-00";
"&pr1nm" = "Test House";
"&pr1pr" = "456.7";
"&pr1qt" = 1;
"&sr" = 640x1136;
"&t" = event;
"&ta" = "Booking";
"&tcc" = "";
"&ti" = T123;
"&tid" = "UA-.....";
"&tr" = "456.7";
"&ul" = "en-fr";
"&v" = 1;
"&z" = 740324....;
gaiVersion = "3.14";
};
timestamp = "2016-08-05 13:41:28 +0000";
}