Skip to content

Commit fd35262

Browse files
authored
Add Firebase Analytics package and integrate with FCM (#2192)
1 parent 806aabb commit fd35262

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3543
-850
lines changed

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
singleQuote: true,
3-
printWidth: 80
3+
printWidth: 80,
4+
quoteProps: preserve
45
}

packages/analytics-types/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @firebase/analytics-types
2+
3+
**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.**

packages/analytics-types/index.d.ts

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { FirebaseApp } from '@firebase/app-types';
19+
20+
export type GtagCommand = 'event' | 'set' | 'config';
21+
22+
export type DataLayer = Array<IArguments>;
23+
24+
/**
25+
* Additional options that can be passed to Firebase Analytics method
26+
* calls such as `logEvent`, `setCurrentScreen`, etc.
27+
*/
28+
export interface AnalyticsCallOptions {
29+
/**
30+
* If true, this config or event call applies globally to all
31+
* analytics properties on the page.
32+
*/
33+
global: boolean;
34+
}
35+
36+
export interface FirebaseAnalytics {
37+
app: FirebaseApp;
38+
39+
/**
40+
* Sends analytics event with given `eventParams`. This method
41+
* automatically associates this logged event with this Firebase web
42+
* app instance on this device.
43+
* List of official event parameters can be found in
44+
* {@link https://developers.google.com/gtagjs/reference/event
45+
* the gtag.js reference documentation}.
46+
*/
47+
logEvent(
48+
eventName: EventNameString,
49+
eventParams: EventParams,
50+
options?: AnalyticsCallOptions
51+
): void;
52+
53+
/**
54+
* Use gtag 'config' command to set 'screen_name'.
55+
*/
56+
setCurrentScreen(screenName: string, options?: AnalyticsCallOptions): void;
57+
58+
/**
59+
* Use gtag 'config' command to set 'user_id'.
60+
*/
61+
setUserId(id: string, options?: AnalyticsCallOptions): void;
62+
63+
/**
64+
* Use gtag 'config' command to set all params specified.
65+
*/
66+
setUserProperties(
67+
properties: { [key: string]: any },
68+
options?: AnalyticsCallOptions
69+
): void;
70+
71+
/**
72+
* Sets whether analytics collection is enabled for this app on this device.
73+
* window['ga-disable-analyticsId'] = true;
74+
*/
75+
setAnalyticsCollectionEnabled(enabled: boolean): void;
76+
}
77+
78+
/**
79+
* Specifies custom options for your Firebase Analytics instance.
80+
* You must set these before initializing `firebase.analytics()`.
81+
*/
82+
export interface SettingsOptions {
83+
/** Sets custom name for `gtag` function. */
84+
gtagName?: string;
85+
/** Sets custom name for `dataLayer` array used by gtag. */
86+
dataLayerName?: string;
87+
}
88+
89+
/**
90+
* Standard `gtag` function provided by gtag.js.
91+
*/
92+
export interface Gtag {
93+
(
94+
command: 'config',
95+
targetId: string,
96+
config?: ControlParams | EventParams | CustomParams
97+
): void;
98+
(command: 'set', config: CustomParams): void;
99+
(
100+
command: 'event',
101+
eventName: string,
102+
eventParams?: ControlParams | EventParams | CustomParams
103+
): void;
104+
}
105+
106+
/**
107+
* Standard gtag.js control parameters.
108+
* For more information, see
109+
* {@link https://developers.google.com/gtagjs/reference/parameter
110+
* the gtag.js documentation on parameters}.
111+
*/
112+
export interface ControlParams {
113+
groups?: string | string[];
114+
send_to?: string | string[];
115+
event_callback?: () => void;
116+
event_timeout?: number;
117+
}
118+
119+
/**
120+
* Standard gtag.js event parameters.
121+
* For more information, see
122+
* {@link https://developers.google.com/gtagjs/reference/parameter
123+
* the gtag.js documentation on parameters}.
124+
*/
125+
export interface EventParams {
126+
checkout_option?: string;
127+
checkout_step?: number;
128+
content_id?: string;
129+
content_type?: string;
130+
coupon?: string;
131+
currency?: string;
132+
description?: string;
133+
fatal?: boolean;
134+
items?: Item[];
135+
method?: string;
136+
number?: string;
137+
promotions?: Promotion[];
138+
screen_name?: string;
139+
search_term?: string;
140+
shipping?: Currency;
141+
tax?: Currency;
142+
transaction_id?: string;
143+
value?: number;
144+
event_label?: string;
145+
event_category?: string;
146+
}
147+
148+
/**
149+
* Any custom params the user may pass to gtag.js.
150+
*/
151+
export interface CustomParams {
152+
[key: string]: any;
153+
}
154+
155+
/**
156+
* Type for standard gtag.js event names. `logEvent` also accepts any
157+
* custom string and interprets it as a custom event name.
158+
*/
159+
export type EventNameString =
160+
| 'add_payment_info'
161+
| 'add_to_cart'
162+
| 'add_to_wishlist'
163+
| 'begin_checkout'
164+
| 'checkout_progress'
165+
| 'exception'
166+
| 'generate_lead'
167+
| 'login'
168+
| 'page_view'
169+
| 'purchase'
170+
| 'refund'
171+
| 'remove_from_cart'
172+
| 'screen_view'
173+
| 'search'
174+
| 'select_content'
175+
| 'set_checkout_option'
176+
| 'share'
177+
| 'sign_up'
178+
| 'timing_complete'
179+
| 'view_item'
180+
| 'view_item_list'
181+
| 'view_promotion'
182+
| 'view_search_results';
183+
184+
export type Currency = string | number;
185+
186+
export interface Item {
187+
brand?: string;
188+
category?: string;
189+
creative_name?: string;
190+
creative_slot?: string;
191+
id?: string;
192+
location_id?: string;
193+
name?: string;
194+
price?: Currency;
195+
quantity?: number;
196+
}
197+
198+
export interface Promotion {
199+
creative_name?: string;
200+
creative_slot?: string;
201+
id?: string;
202+
name?: string;
203+
}

packages/analytics-types/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "@firebase/analytics-types",
3+
"version": "0.1.0",
4+
"description": "@firebase/analytics Types",
5+
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
6+
"license": "Apache-2.0",
7+
"scripts": {
8+
"test": "tsc"
9+
},
10+
"files": [
11+
"index.d.ts"
12+
],
13+
"repository": {
14+
"directory": "packages/analytics-types",
15+
"type": "git",
16+
"url": "https://github.com/firebase/firebase-js-sdk.git"
17+
},
18+
"bugs": {
19+
"url": "https://github.com/firebase/firebase-js-sdk/issues"
20+
},
21+
"devDependencies": {
22+
"typescript": "3.5.3"
23+
}
24+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../config/tsconfig.base.json",
3+
"compilerOptions": {
4+
"noEmit": true
5+
},
6+
"exclude": [
7+
"dist/**/*"
8+
]
9+
}

packages/analytics/.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
'extends': '../../config/.eslintrc.json',
3+
'parserOptions': {
4+
'project': 'tsconfig.json',
5+
'tsconfigRootDir': __dirname
6+
}
7+
};

packages/analytics/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @firebase/analytics
2+
3+
This is the Firebase Analytics component of the Firebase JS SDK.
4+
5+
**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.**

0 commit comments

Comments
 (0)