简体   繁体   中英

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

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]];

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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