Skip to content

Commit 62c6657

Browse files
committed
Revert initializeAnalytics() addition
1 parent 9138ebf commit 62c6657

File tree

4 files changed

+23
-62
lines changed

4 files changed

+23
-62
lines changed

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

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import {
2424
AnalyticsCallOptions,
2525
CustomParams,
2626
EventNameString,
27-
EventParams,
28-
SettingsOptions
27+
EventParams
2928
} from '@firebase/analytics-types-exp';
3029
import { Provider } from '@firebase/component';
3130
import {
@@ -38,8 +37,7 @@ import { ANALYTICS_TYPE } from './constants';
3837
import {
3938
AnalyticsService,
4039
initializationPromisesMap,
41-
wrappedGtagFunction,
42-
settings
40+
wrappedGtagFunction
4341
} from './factory';
4442
import { logger } from './logger';
4543
import {
@@ -50,6 +48,7 @@ import {
5048
setAnalyticsCollectionEnabled as internalSetAnalyticsCollectionEnabled
5149
} from './functions';
5250

51+
export { analyticsSettings } from './factory';
5352
export { EventName } from './constants';
5453

5554
declare module '@firebase/component' {
@@ -58,38 +57,15 @@ declare module '@firebase/component' {
5857
}
5958
}
6059

61-
/**
62-
* Firebase Analytics initialization function that allows custom
63-
* settings. Can be called at most once. If no custom settings
64-
* are needed, `getAnalytics()` can be used to initialize instead.
65-
*
66-
* @public
67-
*
68-
* @param app - The FirebaseApp to use.
69-
* @param options - Custom gtag and dataLayer names.
70-
*/
71-
export function initializeAnalytics(
72-
app: FirebaseApp,
73-
options: SettingsOptions
74-
): Analytics {
75-
const analyticsProvider: Provider<'analytics-exp'> = _getProvider(
76-
app,
77-
ANALYTICS_TYPE
78-
);
79-
settings(options);
80-
const analyticsInstance = analyticsProvider.getImmediate();
81-
return analyticsInstance;
82-
}
83-
8460
/**
8561
* Returns a Firebase Analytics instance for the given app.
86-
* Initializes Firebase Analytics if not already initialized.
8762
*
8863
* @public
8964
*
9065
* @param app - The FirebaseApp to use.
9166
*/
9267
export function getAnalytics(app: FirebaseApp): Analytics {
68+
// Dependencies
9369
const analyticsProvider: Provider<'analytics-exp'> = _getProvider(
9470
app,
9571
ANALYTICS_TYPE

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export function getGlobalVars(): {
144144
*
145145
* @param options - Custom gtag and dataLayer names.
146146
*/
147-
export function settings(options: SettingsOptions): void {
147+
export function analyticsSettings(options: SettingsOptions): void {
148148
if (globalInitDone) {
149149
throw ERROR_FACTORY.create(AnalyticsError.ALREADY_INITIALIZED);
150150
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { expect } from 'chai';
1919
import { SinonStub, stub, useFakeTimers } from 'sinon';
2020
import '../testing/setup';
2121
import {
22+
analyticsSettings,
2223
factory as analyticsFactory,
2324
resetGlobalVars,
2425
getGlobalVars
@@ -34,7 +35,7 @@ import { removeGtagScript } from '../testing/gtag-script-util';
3435
import { Deferred } from '@firebase/util';
3536
import { AnalyticsError } from './errors';
3637
import { logEvent } from './api';
37-
import { AnalyticsService, settings } from './factory';
38+
import { AnalyticsService } from './factory';
3839
import { _FirebaseInstallationsInternal } from '@firebase/installations-types-exp';
3940

4041
let analyticsInstance: AnalyticsService = {} as AnalyticsService;
@@ -287,7 +288,7 @@ describe('FirebaseAnalytics instance tests', () => {
287288
);
288289
window[customGtagName] = gtagStub;
289290
window[customDataLayerName] = [];
290-
settings({
291+
analyticsSettings({
291292
dataLayerName: customDataLayerName,
292293
gtagName: customGtagName
293294
});

packages-exp/analytics-exp/testing/integration-tests/integration.ts

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717

1818
import { initializeApp, deleteApp } from '@firebase/app-exp';
1919
import '@firebase/installations-exp';
20-
import {
21-
getAnalytics,
22-
logEvent,
23-
EventName,
24-
initializeAnalytics
25-
} from '../../src/index';
20+
import { getAnalytics, logEvent, EventName } from '../../src/index';
2621
import '../setup';
2722
import { expect } from 'chai';
2823
import { stub } from 'sinon';
@@ -40,37 +35,26 @@ try {
4035

4136
const RETRY_INTERVAL = 1000;
4237

43-
async function checkForEventCalls(): Promise<number> {
44-
await new Promise(resolve => setTimeout(resolve, RETRY_INTERVAL));
45-
const resources = performance.getEntriesByType('resource');
46-
const callsWithEvent = resources.filter(
47-
resource =>
48-
resource.name.includes('google-analytics.com') &&
49-
resource.name.includes('en=login')
50-
);
51-
if (callsWithEvent.length === 0) {
52-
return checkForEventCalls();
53-
} else {
54-
return callsWithEvent.length;
55-
}
56-
}
57-
5838
describe('FirebaseAnalytics Integration Smoke Tests', () => {
5939
let app: FirebaseApp;
6040
afterEach(() => deleteApp(app));
61-
it('intializeAnalytics() sets options', async () => {
62-
app = initializeApp(config);
63-
const analyticsInstance = initializeAnalytics(app, {
64-
dataLayerName: 'testname'
65-
});
66-
expect(window['testname']).to.exist;
67-
logEvent(analyticsInstance, EventName.LOGIN, { method: 'email' });
68-
await checkForEventCalls();
69-
expect((window['testname'] as any[]).length).to.be.at.least(1);
70-
});
7141
it('logEvent() sends correct network request.', async () => {
7242
app = initializeApp(config);
7343
logEvent(getAnalytics(app), EventName.LOGIN, { method: 'email' });
44+
async function checkForEventCalls(): Promise<number> {
45+
await new Promise(resolve => setTimeout(resolve, RETRY_INTERVAL));
46+
const resources = performance.getEntriesByType('resource');
47+
const callsWithEvent = resources.filter(
48+
resource =>
49+
resource.name.includes('google-analytics.com') &&
50+
resource.name.includes('en=login')
51+
);
52+
if (callsWithEvent.length === 0) {
53+
return checkForEventCalls();
54+
} else {
55+
return callsWithEvent.length;
56+
}
57+
}
7458
const eventCallCount = await checkForEventCalls();
7559
expect(eventCallCount).to.equal(1);
7660
});

0 commit comments

Comments
 (0)