Skip to content

Commit 08c8863

Browse files
author
Athira M
committed
feat: Integrate firebase internal analytics with ABT
1 parent 5eb6b8d commit 08c8863

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

packages/remote-config/src/abt/experiment.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@
1616
*/
1717
import { Storage } from '../storage/storage';
1818
import { FirebaseExperimentDescription } from '../public_types';
19+
import { Provider } from '@firebase/component';
20+
import { FirebaseAnalyticsInternalName } from '@firebase/analytics-interop-types';
1921

2022
export class Experiment {
21-
constructor(private readonly storage: Storage) {}
23+
constructor(
24+
private readonly storage: Storage,
25+
private readonly analytics: Provider<FirebaseAnalyticsInternalName>
26+
) {}
2227

2328
async updateActiveExperiments(
2429
latestExperiments: FirebaseExperimentDescription[]

packages/remote-config/src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export async function activate(remoteConfig: RemoteConfig): Promise<boolean> {
106106
// config.
107107
return false;
108108
}
109-
const experiment = new Experiment(rc._storage);
109+
const experiment = new Experiment(rc._storage, rc._analytics);
110110
await Promise.all([
111111
rc._storageCache.setActiveConfig(lastSuccessfulFetchResponse.config),
112112
experiment.updateActiveExperiments(lastSuccessfulFetchResponse.experiments),

packages/remote-config/src/register.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export function registerRemoteConfig(): void {
6565
const installations = container
6666
.getProvider('installations-internal')
6767
.getImmediate();
68+
const analytics = container.getProvider('analytics-internal');
6869

6970
// Normalizes optional inputs.
7071
const { projectId, apiKey, appId } = app.options;
@@ -112,7 +113,8 @@ export function registerRemoteConfig(): void {
112113
cachingClient,
113114
storageCache,
114115
storage,
115-
logger
116+
logger,
117+
analytics
116118
);
117119

118120
// Starts warming cache.

packages/remote-config/src/remote_config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { StorageCache } from './storage/storage_cache';
2525
import { RemoteConfigFetchClient } from './client/remote_config_fetch_client';
2626
import { Storage } from './storage/storage';
2727
import { Logger } from '@firebase/logger';
28+
import { FirebaseAnalyticsInternalName } from '@firebase/analytics-interop-types';
29+
import { Provider } from '@firebase/component';
2830

2931
const DEFAULT_FETCH_TIMEOUT_MILLIS = 60 * 1000; // One minute
3032
const DEFAULT_CACHE_MAX_AGE_MILLIS = 12 * 60 * 60 * 1000; // Twelve hours.
@@ -83,6 +85,10 @@ export class RemoteConfig implements RemoteConfigType {
8385
/**
8486
* @internal
8587
*/
86-
readonly _logger: Logger
88+
readonly _logger: Logger,
89+
/**
90+
* @internal
91+
*/
92+
readonly _analytics: Provider<FirebaseAnalyticsInternalName>
8793
) {}
8894
}

packages/remote-config/test/abt/experiment.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ import * as sinon from 'sinon';
2020
import { Experiment } from '../../src/abt/experiment';
2121
import { FirebaseExperimentDescription } from '../../src/public_types';
2222
import { Storage } from '../../src/storage/storage';
23+
import { Provider } from '@firebase/component';
24+
import { FirebaseAnalyticsInternalName } from '@firebase/analytics-interop-types';
2325

2426
describe('Experiment', () => {
2527
const storage = {} as Storage;
26-
const experiment = new Experiment(storage);
28+
const analytics = {} as Provider<FirebaseAnalyticsInternalName>;
29+
const experiment = new Experiment(storage, analytics);
2730

2831
describe('updateActiveExperiments', () => {
2932
beforeEach(() => {

packages/remote-config/test/remote_config.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import * as api from '../src/api';
4747
import { fetchAndActivate } from '../src';
4848
import { restore } from 'sinon';
4949
import { Experiment } from '../src/abt/experiment';
50+
import { Provider } from '@firebase/component';
51+
import { FirebaseAnalyticsInternalName } from '@firebase/analytics-interop-types';
5052

5153
describe('RemoteConfig', () => {
5254
const ACTIVE_CONFIG = {
@@ -69,6 +71,8 @@ describe('RemoteConfig', () => {
6971
let storage: Storage;
7072
let logger: Logger;
7173
let rc: RemoteConfigType;
74+
let analytics: Provider<FirebaseAnalyticsInternalName>;
75+
7276

7377
let getActiveConfigStub: sinon.SinonStub;
7478
let loggerDebugSpy: sinon.SinonSpy;
@@ -80,12 +84,13 @@ describe('RemoteConfig', () => {
8084
client = {} as RemoteConfigFetchClient;
8185
storageCache = {} as StorageCache;
8286
storage = {} as Storage;
87+
analytics = {} as Provider<FirebaseAnalyticsInternalName>;
8388
logger = new Logger('package-name');
8489
getActiveConfigStub = sinon.stub().returns(undefined);
8590
storageCache.getActiveConfig = getActiveConfigStub;
8691
loggerDebugSpy = sinon.spy(logger, 'debug');
8792
loggerLogLevelSpy = sinon.spy(logger, 'logLevel', ['set']);
88-
rc = new RemoteConfig(app, client, storageCache, storage, logger);
93+
rc = new RemoteConfig(app, client, storageCache, storage, logger, analytics);
8994
});
9095

9196
afterEach(() => {

0 commit comments

Comments
 (0)