适用于iOS和自定义维度的GA

时间:2013-11-06 17:16:40

标签: ios google-analytics analytics

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

在Google Analytics中,我们设置了自定义维度,如下所示:

名称:用户标识符 范围:用户 活跃:真实

在app中我们在AppDelegate中添加以下内容:

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

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

我们正在使用Google Analytics 3.02。

有没有人知道我们哪里出错了?

2 个答案:

答案 0 :(得分:3)

您是否正在发送跟踪器?

这是Custom Dimensions & Metrics for 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]];

答案 1 :(得分:0)

首先,您需要创建一个必需的Dictionary Builder,然后在该Builder上设置自定义维度,最后从builder构建一个构建,并调用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])
    }

希望对您有所帮助。