繁体   English   中英

GA for iOS和自定义尺寸

[英]GA for iOS and custom dimensions

我们已经在iOS应用中设置了Google Analytics(分析),该应用会发送供应商标识符以区分报告中的用户。 这是我们所做的:

在Google Analytics(分析)中,我们设置了“自定义维度”,如下所示:

名称:用户标识符范围:用户有效:True

在应用程序中,我们在AppDelegate中添加以下内容:

[tracker set:[GAIFields customDimensionForIndex:1] value:uuidString]; // uuidString is the device identifier

在日志记录窗口中,我可以看到cd1的值是正确的值,但我们的自定义报告未显示该自定义维度的数据。

我们正在使用Google Analytics 3.02。

有谁知道我们要去哪里错了?

您要发送跟踪器吗?

这是来自iOS SDK自定义维度和指标的示例

// May return nil if a tracker has not yet been initialized with a property ID.
id tracker = [[GAI sharedInstance] defaultTracker];

// Set the custom dimension value on the tracker using its index.
[tracker set:[GAIFields customDimensionForIndex:1]
       value:@"Premium user"]

[tracker set:kGAIScreenName
       value:@"Home screen"];

// Send the custom dimension value with a screen view.
// Note that the value only needs to be sent once, so it is set on the Map,
// not the tracker.
[tracker send:[[[GAIDictionaryBuilder createAppView] set:@"premium"
                                                  forKey:[GAIFields customDimensionForIndex:1]] build]];

首先,您需要创建所需的词典构建器,然后在该构建器上设置自定义维度,最后从构建器进行构建,并调用tracker的send方法发送构建


    //MARK:- CUSTOM EXCEPTION TRACKING
    func doTrackCustomExceptionWithGA(message:String, customDimensionValue:String, isFatal:Bool = false) {

        guard let tracker = GAI.sharedInstance()?.defaultTracker else { return }

        guard let exceptionBuilder = GAIDictionaryBuilder.createException(withDescription: message, withFatal: NSNumber(value: isFatal)) else { return }
        if !customDimensionValue.isEmpty {
            exceptionBuilder.set(customDimensionValue, forKey: GAIFields.customDimension(for: 15))
        }

        guard let build = exceptionBuilder.build() as? [AnyHashable : Any] else { return }
        tracker.send(build)

        // ADDING DUMMY EVENT TO TRACK PREVIOUS EVENT QUICKLY, AS GA EVENTS ARE TRACKED ON NEXT EVENT CALLS ONLY
        let event = GAIDictionaryBuilder.createScreenView()
        tracker.send(event?.build() as! [NSObject: Any])
    }

希望这对一些人有所帮助。

暂无
暂无

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

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