diff --git a/src/definitions.ts b/src/definitions.ts index fab7af4..fb1f854 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -1,6 +1,6 @@ export interface FirebaseAnalyticsPlugin { initializeFirebase(options: FirebaseInitOptions): Promise; - setUserId(options: { userId: string }): Promise; + setUserId(options: { userId: string | null }): Promise; setUserProperty(options: { name: string; value: string }): Promise; getAppInstanceId(): Promise<{ instanceId: string }>; setScreenName(options: { diff --git a/src/web.ts b/src/web.ts index 724b0d7..cc21fb8 100644 --- a/src/web.ts +++ b/src/web.ts @@ -65,7 +65,7 @@ export class FirebaseAnalyticsWeb * @param options - userId: unique identifier of the user to log * Platform: Web/Android/iOS */ - setUserId(options: { userId: string }): Promise { + setUserId(options: { userId: string | null }): Promise { return new Promise(async (resolve, reject) => { await this.ready; @@ -74,12 +74,12 @@ export class FirebaseAnalyticsWeb return; } - const { userId } = options || { userId: undefined }; + let { userId } = options || { userId: "" }; - if (!userId) { - reject("userId property is missing"); - return; - } + if (userId == undefined) + reject("userId property should be string or null"); + + if (userId == null) userId = ""; this.analyticsRef.setUserId(userId); resolve(); @@ -101,7 +101,10 @@ export class FirebaseAnalyticsWeb return; } - const { name, value } = options || { name: undefined, value: undefined }; + const { name, value } = options || { + name: undefined, + value: undefined, + }; if (!name) { reject("name property is missing"); @@ -295,7 +298,6 @@ export class FirebaseAnalyticsWeb firebaseAnalyticsScript.src ); resolve(null); - }); } /**