4
votes

I was trying to create an audience in my Firebase Analytics to group users by major iOS version.

So I created a new audience filtered by stream as to project contains more than just production iOS app and then I've set another condition to filter by User Property -> OS version. For iOS 11.x I've set it to contain ios 11. or I've tried regular expression ios 11.*. None of which worked, I always get 0 users, even though that on unfiltered dashboard such users exists.

Does anynone know what will be the correct condition? Thanks

1
have you found a solution to this yet? - Koh
Well not really, it is a while since I've been dealing with this. - olejnjak

1 Answers

0
votes

Because there are two decimal points in the iOS version (major.minor.patch), the property is a string not a number. The easiest thing to do is to create a user property in the Firebase web console called "iOSMajorVersion". Go to Analytics: User Properties to do this. Then in your code, get the major version and report to Firebase. It helps to make sure that you only do this once per user session. In Objective-C, you can do it through a block or async GDC dispatch.

You didn't mention if you're using Objective-C or Swift, but here is how you can do it.

Objective-C

@import Foundation;
@import Firebase;
@import UIKit;


+ (void)sendMajorOSVersionToFirebase
{
    // This can only be executed once per app session.

    UIDevice *myDevice = [UIDevice currentDevice];
    NSString *iOSVersion = [myDevice systemVersion];
    NSString *majorVersionNum;

    // Two methods of getting the major version from the string
    // Method 1: componentsSeparatedByString
    NSArray *systemVersionArray = [iOSVersion componentsSeparatedByString:@"."];
    majorVersionNum = [systemVersionArray firstObject];

    // Method 2: range and substringToIndex
    NSRange range = [iOSVersion rangeOfString:@"." options: nil];
    majorVersion = [iOSVersion substringToIndex: range.location];

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{
        [FIRAnalytics setUserPropertyString:majorVersion forName:@"iOSMajorVersion"];
    });
}

Swift

import Firebase
import Foundation
import UIKit

class func sendMajorOSVersionToFirebase() {
    // This can only be executed once per app session.

    let myDevice = UIDevice.current
    let iOSVersion = myDevice.systemVersion
    var majorVersionNum: String

    // Two methods of getting the major version from the string
    // Method 1: componentsSeparatedByString
    let systemVersionArray = iOSVersion.components(separatedBy: ".")
    majorVersionNum = systemVersionArray.first ?? ""

    // Method 2: range and substringToIndex
    let range: NSRange = (iOSVersion as NSString).range(of: ".", options: nil)
    majorVersion = (iOSVersion as? NSString)?.substring(to: range.location)

    // TODO: ensure that the code below is executed only once.
    {
        FIRAnalytics.setUserPropertyString(majorVersion, forName: @"iOSMajorVersion")
    }
}