Skip to content

Commit 03d1fab

Browse files
authored
Update public api signature for setUserId to reflect internal functions (#6671)
* Update public api signature for setUserId * Update API reports * Add changeset
1 parent 171b78b commit 03d1fab

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

.changeset/moody-icons-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/analytics': patch
3+
---
4+
5+
Correct `id` type in `setUserId`

common/api-review/analytics.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ export interface SettingsOptions {
421421
}
422422

423423
// @public
424-
export function setUserId(analyticsInstance: Analytics, id: string, options?: AnalyticsCallOptions): void;
424+
export function setUserId(analyticsInstance: Analytics, id: string | null, options?: AnalyticsCallOptions): void;
425425

426426
// @public
427427
export function setUserProperties(analyticsInstance: Analytics, properties: CustomParams, options?: AnalyticsCallOptions): void;

packages/analytics/src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export function setCurrentScreen(
177177
*/
178178
export function setUserId(
179179
analyticsInstance: Analytics,
180-
id: string,
180+
id: string | null,
181181
options?: AnalyticsCallOptions
182182
): void {
183183
analyticsInstance = getModularInstance(analyticsInstance);

packages/analytics/src/functions.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ describe('FirebaseAnalytics methods', () => {
116116
});
117117
});
118118

119+
it('setUserId() with null (user) id calls gtag correctly (instance)', async () => {
120+
await setUserId(gtagStub, fakeInitializationPromise, null);
121+
expect(gtagStub).to.have.been.calledWith(
122+
GtagCommand.CONFIG,
123+
fakeMeasurementId,
124+
{
125+
'user_id': null,
126+
update: true
127+
}
128+
);
129+
});
130+
119131
it('setUserId() calls gtag correctly (instance)', async () => {
120132
await setUserId(gtagStub, fakeInitializationPromise, 'user123');
121133
expect(gtagStub).to.have.been.calledWith(
@@ -137,6 +149,15 @@ describe('FirebaseAnalytics methods', () => {
137149
});
138150
});
139151

152+
it('setUserId() with null (user) id calls gtag correctly (global)', async () => {
153+
await setUserId(gtagStub, fakeInitializationPromise, null, {
154+
global: true
155+
});
156+
expect(gtagStub).to.be.calledWith(GtagCommand.SET, {
157+
'user_id': null
158+
});
159+
});
160+
140161
it('setUserProperties() calls gtag correctly (instance)', async () => {
141162
await setUserProperties(gtagStub, fakeInitializationPromise, {
142163
'currency': 'USD',

0 commit comments

Comments
 (0)