Skip to content

Commit 917f6ab

Browse files
committed
move defaultEventParametersForInit and funcs to functions file
1 parent 24af319 commit 917f6ab

File tree

6 files changed

+35
-42
lines changed

6 files changed

+35
-42
lines changed

packages/analytics/src/api.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { AnalyticsError } from './errors';
2929
import * as init from './initialize-analytics';
3030
const fakeAppParams = { appId: 'abcdefgh12345:23405', apiKey: 'AAbbCCdd12345' };
3131
import * as factory from './factory';
32+
import { defaultEventParametersForInit } from './functions';
3233

3334
describe('FirebaseAnalytics API tests', () => {
3435
let initStub: SinonStub = stub();
@@ -107,9 +108,7 @@ describe('FirebaseAnalytics API tests', () => {
107108
};
108109
app = getFullApp(fakeAppParams);
109110
setDefaultEventParameters(eventParametersForInit);
110-
expect(factory.defaultEventParametersForInit).to.deep.equal(
111-
eventParametersForInit
112-
);
111+
expect(defaultEventParametersForInit).to.deep.equal(eventParametersForInit);
113112
});
114113
it('setDefaultEventParameters() calls gtag set if wrappedGtagFunction exists', () => {
115114
const eventParametersForInit = {

packages/analytics/src/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ import { ANALYTICS_TYPE, GtagCommand } from './constants';
3939
import {
4040
AnalyticsService,
4141
initializationPromisesMap,
42-
wrappedGtagFunction,
43-
_setDefaultEventParametersForInit
42+
wrappedGtagFunction
4443
} from './factory';
4544
import { logger } from './logger';
4645
import {
4746
logEvent as internalLogEvent,
4847
setCurrentScreen as internalSetCurrentScreen,
4948
setUserId as internalSetUserId,
5049
setUserProperties as internalSetUserProperties,
51-
setAnalyticsCollectionEnabled as internalSetAnalyticsCollectionEnabled
50+
setAnalyticsCollectionEnabled as internalSetAnalyticsCollectionEnabled,
51+
_setDefaultEventParametersForInit
5252
} from './functions';
5353
import { ERROR_FACTORY, AnalyticsError } from './errors';
5454

packages/analytics/src/factory.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import {
19-
SettingsOptions,
20-
Analytics,
21-
AnalyticsSettings,
22-
CustomParams
23-
} from './public-types';
18+
import { SettingsOptions, Analytics, AnalyticsSettings } from './public-types';
2419
import { Gtag, DynamicConfig, MinimalDynamicConfig } from './types';
2520
import { getOrCreateDataLayer, wrapOrCreateGtag } from './helpers';
2621
import { AnalyticsError, ERROR_FACTORY } from './errors';
@@ -89,11 +84,6 @@ let gtagCoreFunction: Gtag;
8984
*/
9085
export let wrappedGtagFunction: Gtag;
9186

92-
/**
93-
* Event parameters to set on 'gtag' during initialization.
94-
*/
95-
export let defaultEventParametersForInit: CustomParams | undefined;
96-
9787
/**
9888
* Flag to ensure page initialization steps (creation or wrapping of
9989
* dataLayer and gtag script) are only run once per page load.
@@ -245,22 +235,3 @@ export function factory(
245235

246236
return analyticsInstance;
247237
}
248-
249-
/**
250-
* Sets the variable {@link defaultEventParametersForInit} for use in the initialization of
251-
* analytics.
252-
*
253-
* @param customParams Any custom params the user may pass to gtag.js.
254-
*/
255-
export function _setDefaultEventParametersForInit(
256-
customParams: CustomParams
257-
): void {
258-
if (defaultEventParametersForInit) {
259-
defaultEventParametersForInit = {
260-
...defaultEventParametersForInit,
261-
...customParams
262-
};
263-
} else {
264-
defaultEventParametersForInit = customParams;
265-
}
266-
}

packages/analytics/src/functions.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ import {
2323
logEvent,
2424
setUserId,
2525
setUserProperties,
26-
setAnalyticsCollectionEnabled
27-
} from './functions';
28-
import { GtagCommand } from './constants';
29-
import {
26+
setAnalyticsCollectionEnabled,
3027
defaultEventParametersForInit,
3128
_setDefaultEventParametersForInit
32-
} from './factory';
29+
} from './functions';
30+
import { GtagCommand } from './constants';
3331

3432
const fakeMeasurementId = 'abcd-efgh-ijkl';
3533
const fakeInitializationPromise = Promise.resolve(fakeMeasurementId);

packages/analytics/src/functions.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ import {
2323
} from './public-types';
2424
import { Gtag } from './types';
2525
import { GtagCommand } from './constants';
26+
27+
/**
28+
* Event parameters to set on 'gtag' during initialization.
29+
*/
30+
export let defaultEventParametersForInit: CustomParams | undefined;
31+
2632
/**
2733
* Logs an analytics event through the Firebase SDK.
2834
*
@@ -142,3 +148,22 @@ export async function setAnalyticsCollectionEnabled(
142148
const measurementId = await initializationPromise;
143149
window[`ga-disable-${measurementId}`] = !enabled;
144150
}
151+
152+
/**
153+
* Sets the variable {@link defaultEventParametersForInit} for use in the initialization of
154+
* analytics.
155+
*
156+
* @param customParams Any custom params the user may pass to gtag.js.
157+
*/
158+
export function _setDefaultEventParametersForInit(
159+
customParams: CustomParams
160+
): void {
161+
if (defaultEventParametersForInit) {
162+
defaultEventParametersForInit = {
163+
...defaultEventParametersForInit,
164+
...customParams
165+
};
166+
} else {
167+
defaultEventParametersForInit = customParams;
168+
}
169+
}

packages/analytics/src/initialize-analytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
import { ERROR_FACTORY, AnalyticsError } from './errors';
2929
import { findGtagScriptOnPage, insertScriptTag } from './helpers';
3030
import { AnalyticsSettings } from './public-types';
31-
import { defaultEventParametersForInit } from './factory';
31+
import { defaultEventParametersForInit } from './functions';
3232

3333
async function validateIndexedDB(): Promise<boolean> {
3434
if (!isIndexedDBAvailable()) {

0 commit comments

Comments
 (0)