BadCodeDeveloper
BadCodeDeveloper

Reputation: 475

iOS Firebase CrashlyticsKit not setting user ID

I am trying to set a user ID for Firebase Crashlytics reports.

Currently I send a user ID only if it's not sent or is changed (very rare event). And there is no user ID in crash reports.

My code:

 + (void)setCrashlyticsUserData:(User *)user
{
    if (user == nil) { return; }
    NSString *userIdKey = @"CRASHLYTICS_SENT_USER_ID";
    NSUserDefaults *userDefaults = NSUserDefaults.standardUserDefaults;
    NSInteger sentUserId = [userDefaults integerForKey:userIdKey];
    if (sentUserId == user.userId) { return; }

    [CrashlyticsKit setUserIdentifier:[NSString stringWithFormat:@"%i", user.userId]];
    [userDefaults setInteger:user.userId forKey:userIdKey];
}

If this line is commented if (sentUserId == user.userId) { return; } I receive a user ID in crash reports.

Should I call [CrashlyticsKit setUserIdentifier:] every app launch? I can't find any information about it in the documentation.

Upvotes: 1

Views: 1117

Answers (2)

SergeyIL
SergeyIL

Reputation: 595

Custom attributes of Crashlytics (like custom keys or user identifier) works in log-style in per-session basis. So, you should call setUserIdentifier in each app session as early as possible. See this link for code example:

https://fabric.io/kits/ios/crashlytics/features

Upvotes: 1

AtulParmar
AtulParmar

Reputation: 4570

You can use [Crashlytics setUserIdentifier:] to provide an id number, token, or hashed value that uniquely identifies the end-user of your application without disclosing or transmitting any of their personal information. You can also clear the value by setting it to a blank string. This value is displayed right in the Crashlytics dashboard.

[CrashlyticsKit setUserIdentifier:@"123456789"]; //User ID

Or another option is setthe custom key using [CrashlyticsKit setObjectValue:forKey:], See the following example.

[CrashlyticsKit setIntValue:3 forKey:@"userid"];
[CrashlyticsKit setObjectValue:@"logged_in" forKey:@"last_UI_action"];

See this document for more information.

https://docs.fabric.io/apple/crashlytics/enhanced-reports.html

Upvotes: 0

Related Questions