Skip to content

Commit 4ab7032

Browse files
authored
Package analytics-exp (#4310)
1 parent 941467e commit 4ab7032

File tree

11 files changed

+97
-179
lines changed

11 files changed

+97
-179
lines changed

common/api-review/analytics-exp.api.md

Lines changed: 19 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -6,96 +6,36 @@
66

77
import { Analytics } from '@firebase/analytics-types-exp';
88
import { AnalyticsCallOptions } from '@firebase/analytics-types-exp';
9+
import { ControlParams } from '@firebase/analytics-types-exp';
910
import { CustomParams } from '@firebase/analytics-types-exp';
10-
import { DynamicConfig } from '@firebase/analytics-types-exp';
1111
import { EventNameString } from '@firebase/analytics-types-exp';
1212
import { EventParams } from '@firebase/analytics-types-exp';
1313
import { FirebaseApp } from '@firebase/app-types-exp';
14-
import { _FirebaseInstallationsInternal } from '@firebase/installations-types-exp';
15-
import { _FirebaseService } from '@firebase/app-types-exp';
16-
import { MinimalDynamicConfig } from '@firebase/analytics-types-exp';
14+
import { Item } from '@firebase/analytics-types-exp';
15+
import { Promotion } from '@firebase/analytics-types-exp';
1716
import { SettingsOptions } from '@firebase/analytics-types-exp';
1817

18+
export { Analytics }
19+
20+
export { AnalyticsCallOptions }
21+
22+
export { ControlParams }
23+
1924
// @public
20-
export const enum EventName {
21-
// (undocumented)
22-
ADD_PAYMENT_INFO = "add_payment_info",
23-
// (undocumented)
24-
ADD_SHIPPING_INFO = "add_shipping_info",
25-
// (undocumented)
26-
ADD_TO_CART = "add_to_cart",
27-
// (undocumented)
28-
ADD_TO_WISHLIST = "add_to_wishlist",
29-
// (undocumented)
30-
BEGIN_CHECKOUT = "begin_checkout",
31-
// @deprecated (undocumented)
32-
CHECKOUT_PROGRESS = "checkout_progress",
33-
// (undocumented)
34-
EXCEPTION = "exception",
35-
// (undocumented)
36-
GENERATE_LEAD = "generate_lead",
37-
// (undocumented)
38-
LOGIN = "login",
39-
// (undocumented)
40-
PAGE_VIEW = "page_view",
41-
// (undocumented)
42-
PURCHASE = "purchase",
43-
// (undocumented)
44-
REFUND = "refund",
45-
// (undocumented)
46-
REMOVE_FROM_CART = "remove_from_cart",
47-
// (undocumented)
48-
SCREEN_VIEW = "screen_view",
49-
// (undocumented)
50-
SEARCH = "search",
51-
// (undocumented)
52-
SELECT_CONTENT = "select_content",
53-
// (undocumented)
54-
SELECT_ITEM = "select_item",
55-
// (undocumented)
56-
SELECT_PROMOTION = "select_promotion",
57-
// @deprecated (undocumented)
58-
SET_CHECKOUT_OPTION = "set_checkout_option",
59-
// (undocumented)
60-
SHARE = "share",
61-
// (undocumented)
62-
SIGN_UP = "sign_up",
63-
// (undocumented)
64-
TIMING_COMPLETE = "timing_complete",
65-
// (undocumented)
66-
VIEW_CART = "view_cart",
67-
// (undocumented)
68-
VIEW_ITEM = "view_item",
69-
// (undocumented)
70-
VIEW_ITEM_LIST = "view_item_list",
71-
// (undocumented)
72-
VIEW_PROMOTION = "view_promotion",
73-
// (undocumented)
74-
VIEW_SEARCH_RESULTS = "view_search_results"
75-
}
76-
77-
// Warning: (ae-forgotten-export) The symbol "AnalyticsService" needs to be exported by the entry point index.d.ts
78-
// Warning: (ae-internal-missing-underscore) The name "factory" should be prefixed with an underscore because the declaration is marked as @internal
79-
//
80-
// @internal
81-
export function factory(app: FirebaseApp, installations: _FirebaseInstallationsInternal): AnalyticsService;
25+
export type CustomEventName<T> = T extends EventNameString ? never : T;
26+
27+
export { CustomParams }
28+
29+
export { EventParams }
8230

8331
// @public
8432
export function getAnalytics(app: FirebaseApp): Analytics;
8533

86-
// Warning: (ae-internal-missing-underscore) The name "getGlobalVars" should be prefixed with an underscore because the declaration is marked as @internal
87-
//
88-
// @internal
89-
export function getGlobalVars(): {
90-
initializationPromisesMap: {
91-
[appId: string]: Promise<string>;
92-
};
93-
dynamicConfigPromisesList: Array<Promise<DynamicConfig | MinimalDynamicConfig>>;
94-
};
95-
9634
// @public
9735
export function isSupported(): Promise<boolean>;
9836

37+
export { Item }
38+
9939
// @public
10040
export function logEvent(analyticsInstance: Analytics, eventName: 'add_payment_info', eventParams?: {
10141
coupon?: EventParams['coupon'];
@@ -273,17 +213,12 @@ export function logEvent(analyticsInstance: Analytics, eventName: 'view_item_lis
273213
[key: string]: any;
274214
}, options?: AnalyticsCallOptions): void;
275215

276-
// Warning: (ae-forgotten-export) The symbol "CustomEventName" needs to be exported by the entry point index.d.ts
277-
//
278216
// @public
279217
export function logEvent<T extends string>(analyticsInstance: Analytics, eventName: CustomEventName<T>, eventParams?: {
280218
[key: string]: any;
281219
}, options?: AnalyticsCallOptions): void;
282220

283-
// Warning: (ae-internal-missing-underscore) The name "resetGlobalVars" should be prefixed with an underscore because the declaration is marked as @internal
284-
//
285-
// @internal
286-
export function resetGlobalVars(newGlobalInitDone?: boolean, newInitializationPromisesMap?: {}, newDynamicPromises?: never[]): void;
221+
export { Promotion }
287222

288223
// @public
289224
export function setAnalyticsCollectionEnabled(analyticsInstance: Analytics, enabled: boolean): void;
@@ -294,6 +229,8 @@ export function setCurrentScreen(analyticsInstance: Analytics, screenName: strin
294229
// @public
295230
export function settings(options: SettingsOptions): void;
296231

232+
export { SettingsOptions }
233+
297234
// @public
298235
export function setUserId(analyticsInstance: Analytics, id: string, options?: AnalyticsCallOptions): void;
299236

packages-exp/analytics-exp/src/api.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import {
4949
} from './functions';
5050

5151
export { settings } from './factory';
52-
export { EventName } from './constants';
5352

5453
declare module '@firebase/component' {
5554
interface NameServiceMapping {
@@ -674,4 +673,9 @@ export function logEvent(
674673
).catch(e => logger.error(e));
675674
}
676675

677-
type CustomEventName<T> = T extends EventNameString ? never : T;
676+
/**
677+
* Any custom event name string not in the standard list of recommended
678+
* event names.
679+
* @public
680+
*/
681+
export type CustomEventName<T> = T extends EventNameString ? never : T;

packages-exp/analytics-exp/src/constants.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,47 +36,3 @@ export const enum GtagCommand {
3636
SET = 'set',
3737
CONFIG = 'config'
3838
}
39-
40-
/**
41-
* Officially recommended event names for gtag.js
42-
* Any other string is also allowed.
43-
*
44-
* @public
45-
*/
46-
export const enum EventName {
47-
ADD_SHIPPING_INFO = 'add_shipping_info',
48-
ADD_PAYMENT_INFO = 'add_payment_info',
49-
ADD_TO_CART = 'add_to_cart',
50-
ADD_TO_WISHLIST = 'add_to_wishlist',
51-
BEGIN_CHECKOUT = 'begin_checkout',
52-
/**
53-
* @deprecated This event name is deprecated and is unsupported in updated
54-
* Enhanced Ecommerce reports.
55-
*/
56-
CHECKOUT_PROGRESS = 'checkout_progress',
57-
EXCEPTION = 'exception',
58-
GENERATE_LEAD = 'generate_lead',
59-
LOGIN = 'login',
60-
PAGE_VIEW = 'page_view',
61-
PURCHASE = 'purchase',
62-
REFUND = 'refund',
63-
REMOVE_FROM_CART = 'remove_from_cart',
64-
SCREEN_VIEW = 'screen_view',
65-
SEARCH = 'search',
66-
SELECT_CONTENT = 'select_content',
67-
SELECT_ITEM = 'select_item',
68-
SELECT_PROMOTION = 'select_promotion',
69-
/**
70-
* @deprecated This event name is deprecated and is unsupported in updated
71-
* Enhanced Ecommerce reports.
72-
*/
73-
SET_CHECKOUT_OPTION = 'set_checkout_option',
74-
SHARE = 'share',
75-
SIGN_UP = 'sign_up',
76-
TIMING_COMPLETE = 'timing_complete',
77-
VIEW_CART = 'view_cart',
78-
VIEW_ITEM = 'view_item',
79-
VIEW_ITEM_LIST = 'view_item_list',
80-
VIEW_PROMOTION = 'view_promotion',
81-
VIEW_SEARCH_RESULTS = 'view_search_results'
82-
}

packages-exp/analytics-exp/src/functions.test.ts

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
setUserProperties,
2626
setAnalyticsCollectionEnabled
2727
} from './functions';
28-
import { GtagCommand, EventName } from './constants';
28+
import { GtagCommand } from './constants';
2929

3030
const fakeMeasurementId = 'abcd-efgh-ijkl';
3131
const fakeInitializationPromise = Promise.resolve(fakeMeasurementId);
@@ -38,57 +38,45 @@ describe('FirebaseAnalytics methods', () => {
3838
});
3939

4040
it('logEvent() calls gtag function correctly', async () => {
41-
await logEvent(gtagStub, fakeInitializationPromise, EventName.ADD_TO_CART, {
41+
await logEvent(gtagStub, fakeInitializationPromise, 'add_to_cart', {
4242
currency: 'USD'
4343
});
4444

45-
expect(gtagStub).to.have.been.calledWith(
46-
GtagCommand.EVENT,
47-
EventName.ADD_TO_CART,
48-
{
49-
'send_to': fakeMeasurementId,
50-
currency: 'USD'
51-
}
52-
);
45+
expect(gtagStub).to.have.been.calledWith(GtagCommand.EVENT, 'add_to_cart', {
46+
'send_to': fakeMeasurementId,
47+
currency: 'USD'
48+
});
5349
});
5450

5551
it('logEvent() with no event params calls gtag function correctly', async () => {
56-
await logEvent(gtagStub, fakeInitializationPromise, EventName.VIEW_ITEM);
52+
await logEvent(gtagStub, fakeInitializationPromise, 'view_item');
5753

58-
expect(gtagStub).to.have.been.calledWith(
59-
GtagCommand.EVENT,
60-
EventName.VIEW_ITEM,
61-
{
62-
'send_to': fakeMeasurementId
63-
}
64-
);
54+
expect(gtagStub).to.have.been.calledWith(GtagCommand.EVENT, 'view_item', {
55+
'send_to': fakeMeasurementId
56+
});
6557
});
6658

6759
it('logEvent() globally calls gtag function correctly', async () => {
6860
await logEvent(
6961
gtagStub,
7062
fakeInitializationPromise,
71-
EventName.ADD_TO_CART,
63+
'add_to_cart',
7264
{
7365
currency: 'USD'
7466
},
7567
{ global: true }
7668
);
7769

78-
expect(gtagStub).to.have.been.calledWith(
79-
GtagCommand.EVENT,
80-
EventName.ADD_TO_CART,
81-
{
82-
currency: 'USD'
83-
}
84-
);
70+
expect(gtagStub).to.have.been.calledWith(GtagCommand.EVENT, 'add_to_cart', {
71+
currency: 'USD'
72+
});
8573
});
8674

8775
it('logEvent() with no event params globally calls gtag function correctly', async () => {
8876
await logEvent(
8977
gtagStub,
9078
fakeInitializationPromise,
91-
EventName.ADD_TO_CART,
79+
'add_to_cart',
9280
undefined,
9381
{
9482
global: true
@@ -97,7 +85,7 @@ describe('FirebaseAnalytics methods', () => {
9785

9886
expect(gtagStub).to.have.been.calledWith(
9987
GtagCommand.EVENT,
100-
EventName.ADD_TO_CART,
88+
'add_to_cart',
10189
undefined
10290
);
10391
});

packages-exp/analytics-exp/src/index.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@
1818
import { expect } from 'chai';
1919
import { SinonStub, stub, useFakeTimers } from 'sinon';
2020
import '../testing/setup';
21-
import {
22-
settings,
23-
factory as analyticsFactory,
24-
resetGlobalVars,
25-
getGlobalVars
26-
} from './index';
21+
import { settings } from './index';
2722
import {
2823
getFakeApp,
2924
getFakeInstallations
3025
} from '../testing/get-fake-firebase-services';
3126
import { FirebaseApp } from '@firebase/app-types-exp';
32-
import { GtagCommand, EventName } from './constants';
27+
import { GtagCommand } from './constants';
3328
import { findGtagScriptOnPage } from './helpers';
3429
import { removeGtagScript } from '../testing/gtag-script-util';
3530
import { Deferred } from '@firebase/util';
3631
import { AnalyticsError } from './errors';
3732
import { logEvent } from './api';
38-
import { AnalyticsService } from './factory';
33+
import {
34+
AnalyticsService,
35+
getGlobalVars,
36+
resetGlobalVars,
37+
factory as analyticsFactory
38+
} from './factory';
3939
import { _FirebaseInstallationsInternal } from '@firebase/installations-types-exp';
4040

4141
let analyticsInstance: AnalyticsService = {} as AnalyticsService;
@@ -157,7 +157,7 @@ describe('FirebaseAnalytics instance tests', () => {
157157
expect(analyticsInstance.app).to.equal(app);
158158
});
159159
it('Calls gtag correctly on logEvent (instance)', async () => {
160-
logEvent(analyticsInstance, EventName.ADD_PAYMENT_INFO, {
160+
logEvent(analyticsInstance, 'add_payment_info', {
161161
currency: 'USD'
162162
});
163163
// Clear promise chain started by logEvent.
@@ -174,7 +174,7 @@ describe('FirebaseAnalytics instance tests', () => {
174174
);
175175
expect(gtagStub).to.have.been.calledWith(
176176
GtagCommand.EVENT,
177-
EventName.ADD_PAYMENT_INFO,
177+
'add_payment_info',
178178
{
179179
'send_to': 'abcd-efgh',
180180
currency: 'USD'
@@ -237,7 +237,7 @@ describe('FirebaseAnalytics instance tests', () => {
237237
it('Warns on logEvent if indexedDB API not available', async () => {
238238
const idbStub = stub(window, 'indexedDB').value(undefined);
239239
analyticsInstance = analyticsFactory(app, fakeInstallations);
240-
logEvent(analyticsInstance, EventName.ADD_PAYMENT_INFO, {
240+
logEvent(analyticsInstance, 'add_payment_info', {
241241
currency: 'USD'
242242
});
243243
// Clear promise chain started by logEvent.
@@ -257,7 +257,7 @@ describe('FirebaseAnalytics instance tests', () => {
257257
idbOpenStub.restore();
258258
idbOpenStub = stub(indexedDB, 'open').throws('idb open error test');
259259
analyticsInstance = analyticsFactory(app, fakeInstallations);
260-
logEvent(analyticsInstance, EventName.ADD_PAYMENT_INFO, {
260+
logEvent(analyticsInstance, 'add_payment_info', {
261261
currency: 'USD'
262262
});
263263
// Clear promise chain started by logEvent.
@@ -307,7 +307,7 @@ describe('FirebaseAnalytics instance tests', () => {
307307
idbOpenStub.restore();
308308
});
309309
it('Calls gtag correctly on logEvent (instance)', async () => {
310-
logEvent(analyticsInstance, EventName.ADD_PAYMENT_INFO, {
310+
logEvent(analyticsInstance, 'add_payment_info', {
311311
currency: 'USD'
312312
});
313313
// Clear promise chain started by logEvent.
@@ -324,7 +324,7 @@ describe('FirebaseAnalytics instance tests', () => {
324324
);
325325
expect(gtagStub).to.have.been.calledWith(
326326
GtagCommand.EVENT,
327-
EventName.ADD_PAYMENT_INFO,
327+
'add_payment_info',
328328
{
329329
'send_to': 'abcd-efgh',
330330
currency: 'USD'

0 commit comments

Comments
 (0)