Skip to content

Package analytics-exp #4310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 24 additions & 26 deletions common/api-review/analytics-exp.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,31 @@

import { Analytics } from '@firebase/analytics-types-exp';
import { AnalyticsCallOptions } from '@firebase/analytics-types-exp';
import { ControlParams } from '@firebase/analytics-types-exp';
import { CustomParams } from '@firebase/analytics-types-exp';
import { DynamicConfig } from '@firebase/analytics-types-exp';
import { DataLayer } from '@firebase/analytics-types-exp';
import { EventNameString } from '@firebase/analytics-types-exp';
import { EventParams } from '@firebase/analytics-types-exp';
import { FirebaseApp } from '@firebase/app-types-exp';
import { _FirebaseInstallationsInternal } from '@firebase/installations-types-exp';
import { _FirebaseService } from '@firebase/app-types-exp';
import { MinimalDynamicConfig } from '@firebase/analytics-types-exp';
import { Item } from '@firebase/analytics-types-exp';
import { Promotion } from '@firebase/analytics-types-exp';
import { SettingsOptions } from '@firebase/analytics-types-exp';

export { Analytics }

export { AnalyticsCallOptions }

export { ControlParams }

// @public
export type CustomEventName<T> = T extends EventNameString ? never : T;

export { CustomParams }

export { DataLayer }

// @public
export const enum EventName {
export enum EventName {
// (undocumented)
ADD_PAYMENT_INFO = "add_payment_info",
// (undocumented)
Expand Down Expand Up @@ -74,28 +87,16 @@ export const enum EventName {
VIEW_SEARCH_RESULTS = "view_search_results"
}

// Warning: (ae-forgotten-export) The symbol "AnalyticsService" needs to be exported by the entry point index.d.ts
// Warning: (ae-internal-missing-underscore) The name "factory" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal
export function factory(app: FirebaseApp, installations: _FirebaseInstallationsInternal): AnalyticsService;
export { EventParams }

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

// Warning: (ae-internal-missing-underscore) The name "getGlobalVars" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal
export function getGlobalVars(): {
initializationPromisesMap: {
[appId: string]: Promise<string>;
};
dynamicConfigPromisesList: Array<Promise<DynamicConfig | MinimalDynamicConfig>>;
};

// @public
export function isSupported(): Promise<boolean>;

export { Item }

// @public
export function logEvent(analyticsInstance: Analytics, eventName: 'add_payment_info', eventParams?: {
coupon?: EventParams['coupon'];
Expand Down Expand Up @@ -273,17 +274,12 @@ export function logEvent(analyticsInstance: Analytics, eventName: 'view_item_lis
[key: string]: any;
}, options?: AnalyticsCallOptions): void;

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

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

// @public
export function setAnalyticsCollectionEnabled(analyticsInstance: Analytics, enabled: boolean): void;
Expand All @@ -294,6 +290,8 @@ export function setCurrentScreen(analyticsInstance: Analytics, screenName: strin
// @public
export function settings(options: SettingsOptions): void;

export { SettingsOptions }

// @public
export function setUserId(analyticsInstance: Analytics, id: string, options?: AnalyticsCallOptions): void;

Expand Down
7 changes: 6 additions & 1 deletion packages-exp/analytics-exp/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,4 +674,9 @@ export function logEvent(
).catch(e => logger.error(e));
}

type CustomEventName<T> = T extends EventNameString ? never : T;
/**
* Any custom event name string not in the standard list of recommended
* event names.
* @public
*/
export type CustomEventName<T> = T extends EventNameString ? never : T;
2 changes: 1 addition & 1 deletion packages-exp/analytics-exp/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const enum GtagCommand {
*
* @public
*/
export const enum EventName {
export enum EventName {
ADD_SHIPPING_INFO = 'add_shipping_info',
ADD_PAYMENT_INFO = 'add_payment_info',
ADD_TO_CART = 'add_to_cart',
Expand Down
14 changes: 7 additions & 7 deletions packages-exp/analytics-exp/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
import { expect } from 'chai';
import { SinonStub, stub, useFakeTimers } from 'sinon';
import '../testing/setup';
import {
settings,
factory as analyticsFactory,
resetGlobalVars,
getGlobalVars
} from './index';
import { settings } from './index';
import {
getFakeApp,
getFakeInstallations
Expand All @@ -35,7 +30,12 @@ import { removeGtagScript } from '../testing/gtag-script-util';
import { Deferred } from '@firebase/util';
import { AnalyticsError } from './errors';
import { logEvent } from './api';
import { AnalyticsService } from './factory';
import {
AnalyticsService,
getGlobalVars,
resetGlobalVars,
factory as analyticsFactory
} from './factory';
import { _FirebaseInstallationsInternal } from '@firebase/installations-types-exp';

let analyticsInstance: AnalyticsService = {} as AnalyticsService;
Expand Down
20 changes: 15 additions & 5 deletions packages-exp/analytics-exp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { registerVersion, _registerComponent } from '@firebase/app-exp';
import { FirebaseAnalyticsInternal } from '@firebase/analytics-interop-types';
import { factory, resetGlobalVars, getGlobalVars } from './factory';
import { factory } from './factory';
import { ANALYTICS_TYPE } from './constants';
import {
Component,
Expand All @@ -35,8 +35,6 @@ declare global {
}
}

export * from './api';

function registerAnalytics(): void {
_registerComponent(
new Component(
Expand Down Expand Up @@ -80,6 +78,18 @@ function registerAnalytics(): void {
}
}

export { factory, resetGlobalVars, getGlobalVars };

registerAnalytics();

export * from './api';

export {
DataLayer,
Analytics,
AnalyticsCallOptions,
SettingsOptions,
ControlParams,
EventParams,
CustomParams,
Item,
Promotion
} from '@firebase/analytics-types-exp';
2 changes: 0 additions & 2 deletions packages-exp/analytics-types-exp/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

import { FirebaseApp } from '@firebase/app-types-exp';

export type GtagCommand = 'event' | 'set' | 'config';

export type DataLayer = Array<IArguments>;

/**
Expand Down
18 changes: 18 additions & 0 deletions packages-exp/firebase-exp/analytics/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from '@firebase/analytics-exp';
7 changes: 7 additions & 0 deletions packages-exp/firebase-exp/analytics/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "firebase-exp/analytics",
"main": "dist/index.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"typings": "dist/analytics/index.d.ts"
}
1 change: 1 addition & 0 deletions packages-exp/firebase-exp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"typescript": "4.0.5"
},
"components": [
"analytics",
"app",
"auth",
"functions",
Expand Down