Skip to content

Commit

Permalink
feat: add clearUserID to AppEventsLogger (setUserId(null) throws ex…
Browse files Browse the repository at this point in the history
…ception from SDK) (#185)
  • Loading branch information
sichan75 authored Jan 17, 2022
1 parent dd6aaf8 commit b3cd260
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ public void setUserID(final String userID) {
mAppEventLogger.setUserID(userID);
}

/**
* Clears the currently set user id.
*/
@ReactMethod
public void clearUserID() {
mAppEventLogger.clearUserID();
}

/**
* Returns the set user id or null if not set
*
Expand Down
5 changes: 5 additions & 0 deletions ios/RCTFBSDK/core/RCTFBSDKAppEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ - (dispatch_queue_t)methodQueue
[FBSDKAppEvents.shared setUserID:userID];
}

RCT_EXPORT_METHOD(clearUserID)
{
[FBSDKAppEvents clearUserID];
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getUserID)
{
return [FBSDKAppEvents.shared userID];
Expand Down
1 change: 1 addition & 0 deletions jest/mocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default {
logEvent: jest.fn(),
logPurchase: jest.fn(),
setUserID: jest.fn(),
clearUserID: jest.fn(),
AppEventParams: mockAppEventParams,
AppEvents: mockAppEvents,
},
Expand Down
11 changes: 9 additions & 2 deletions src/FBAppEventsLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,19 @@ export default {

/**
* Sets a custom user ID to associate with all app events.
* The userID is persisted until it is cleared by passing nil.
* The userID is persisted until it is cleared by clearUserID method.
*/
setUserID(userID: string | null) {
setUserID(userID: string) {
AppEventsLogger.setUserID(userID);
},

/**
* Clears the currently set user id.
*/
clearUserID() {
AppEventsLogger.clearUserID();
},

/**
* Returns user id or null if not set
*/
Expand Down

0 comments on commit b3cd260

Please sign in to comment.