简体   繁体   English

GA for iOS和自定义尺寸

[英]GA for iOS and custom dimensions

We've setup Google Analytics in an iOS app which is sending the vendor identifier to distinguish between users on the reports. 我们已经在iOS应用中设置了Google Analytics(分析),该应用会发送供应商标识符以区分报告中的用户。 Here's what we've done: 这是我们所做的:

In Google Analytics we've setup a Custom Dimension as follows: 在Google Analytics(分析)中,我们设置了“自定义维度”,如下所示:

Name: User identifier Scope: User Active: True 名称:用户标识符范围:用户有效:True

In the app we add the following in the AppDelegate: 在应用程序中,我们在AppDelegate中添加以下内容:

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

In the logging window I can see that the value of cd1 is the correct value yet our custom report shows no data for the custom dimension. 在日志记录窗口中,我可以看到cd1的值是正确的值,但我们的自定义报告未显示该自定义维度的数据。

We are using Google Analytics 3.02. 我们正在使用Google Analytics 3.02。

Does anyone have any idea where we are going wrong? 有谁知道我们要去哪里错了?

Are you sending the tracker? 您要发送跟踪器吗?

This is an example from the Custom Dimensions & Metrics for iOS SDK 这是来自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]];

First of all you need to create a required Dictionary Builder then set custom dimension on that builder, finally make a build from builder and call send method of tracker to send the 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])
    }

Hope this helps some one.. 希望这对一些人有所帮助。

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

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