GA for iOS and custom dimensions

筅森魡賤 提交于 2019-12-21 21:16:57

问题


We've setup Google Analytics in an iOS app which is sending the vendor identifier to distinguish between users on the reports. Here's what we've done:

In Google Analytics we've setup a Custom Dimension as follows:

Name: User identifier Scope: User Active: True

In the app we add the following in the 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.

We are using Google Analytics 3.02.

Does anyone have any idea where we are going wrong?


回答1:


Are you sending the tracker?

This is an example from the 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]];



回答2:


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


    //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..



来源:https://stackoverflow.com/questions/19818459/ga-for-ios-and-custom-dimensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!