Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setUserId accept null too #49 #50

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface FirebaseAnalyticsPlugin {
initializeFirebase(options: FirebaseInitOptions): Promise<any>;
setUserId(options: { userId: string }): Promise<void>;
setUserId(options: { userId: string | null }): Promise<void>;
setUserProperty(options: { name: string; value: string }): Promise<void>;
getAppInstanceId(): Promise<{ instanceId: string }>;
setScreenName(options: {
Expand Down
18 changes: 10 additions & 8 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
setUserId(options: { userId: string | null }): Promise<void> {
return new Promise(async (resolve, reject) => {
await this.ready;

Expand All @@ -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();
Expand All @@ -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");
Expand Down Expand Up @@ -295,7 +298,6 @@ export class FirebaseAnalyticsWeb
firebaseAnalyticsScript.src
);
resolve(null);
});
}

/**
Expand Down