UNPKG

19.4 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2020 Google LLC
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 */
17import { FirebaseApp } from '@firebase/app';
18import { Analytics, AnalyticsCallOptions, AnalyticsSettings, ConsentSettings, CustomParams, EventNameString, EventParams } from './public-types';
19import { ANALYTICS_TYPE } from './constants';
20import { AnalyticsService } from './factory';
21export { settings } from './factory';
22declare module '@firebase/component' {
23 interface NameServiceMapping {
24 [ANALYTICS_TYPE]: AnalyticsService;
25 }
26}
27/**
28 * Returns an {@link Analytics} instance for the given app.
29 *
30 * @public
31 *
32 * @param app - The {@link @firebase/app#FirebaseApp} to use.
33 */
34export declare function getAnalytics(app?: FirebaseApp): Analytics;
35/**
36 * Returns an {@link Analytics} instance for the given app.
37 *
38 * @public
39 *
40 * @param app - The {@link @firebase/app#FirebaseApp} to use.
41 */
42export declare function initializeAnalytics(app: FirebaseApp, options?: AnalyticsSettings): Analytics;
43/**
44 * This is a public static method provided to users that wraps four different checks:
45 *
46 * 1. Check if it's not a browser extension environment.
47 * 2. Check if cookies are enabled in current browser.
48 * 3. Check if IndexedDB is supported by the browser environment.
49 * 4. Check if the current browser context is valid for using `IndexedDB.open()`.
50 *
51 * @public
52 *
53 */
54export declare function isSupported(): Promise<boolean>;
55/**
56 * Use gtag `config` command to set `screen_name`.
57 *
58 * @public
59 *
60 * @deprecated Use {@link logEvent} with `eventName` as 'screen_view' and add relevant `eventParams`.
61 * See {@link https://firebase.google.com/docs/analytics/screenviews | Track Screenviews}.
62 *
63 * @param analyticsInstance - The {@link Analytics} instance.
64 * @param screenName - Screen name to set.
65 */
66export declare function setCurrentScreen(analyticsInstance: Analytics, screenName: string, options?: AnalyticsCallOptions): void;
67/**
68 * Retrieves a unique Google Analytics identifier for the web client.
69 * See {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/config#client_id | client_id}.
70 *
71 * @public
72 *
73 * @param app - The {@link @firebase/app#FirebaseApp} to use.
74 */
75export declare function getGoogleAnalyticsClientId(analyticsInstance: Analytics): Promise<string>;
76/**
77 * Use gtag `config` command to set `user_id`.
78 *
79 * @public
80 *
81 * @param analyticsInstance - The {@link Analytics} instance.
82 * @param id - User ID to set.
83 */
84export declare function setUserId(analyticsInstance: Analytics, id: string | null, options?: AnalyticsCallOptions): void;
85/**
86 * Use gtag `config` command to set all params specified.
87 *
88 * @public
89 */
90export declare function setUserProperties(analyticsInstance: Analytics, properties: CustomParams, options?: AnalyticsCallOptions): void;
91/**
92 * Sets whether Google Analytics collection is enabled for this app on this device.
93 * Sets global `window['ga-disable-analyticsId'] = true;`
94 *
95 * @public
96 *
97 * @param analyticsInstance - The {@link Analytics} instance.
98 * @param enabled - If true, enables collection, if false, disables it.
99 */
100export declare function setAnalyticsCollectionEnabled(analyticsInstance: Analytics, enabled: boolean): void;
101/**
102 * Adds data that will be set on every event logged from the SDK, including automatic ones.
103 * With gtag's "set" command, the values passed persist on the current page and are passed with
104 * all subsequent events.
105 * @public
106 * @param customParams - Any custom params the user may pass to gtag.js.
107 */
108export declare function setDefaultEventParameters(customParams: CustomParams): void;
109/**
110 * Sends a Google Analytics event with given `eventParams`. This method
111 * automatically associates this logged event with this Firebase web
112 * app instance on this device.
113 * @public
114 * List of recommended event parameters can be found in
115 * {@link https://developers.google.com/gtagjs/reference/ga4-events
116 * | the GA4 reference documentation}.
117 */
118export declare function logEvent(analyticsInstance: Analytics, eventName: 'add_payment_info', eventParams?: {
119 coupon?: EventParams['coupon'];
120 currency?: EventParams['currency'];
121 items?: EventParams['items'];
122 payment_type?: EventParams['payment_type'];
123 value?: EventParams['value'];
124 [key: string]: any;
125}, options?: AnalyticsCallOptions): void;
126/**
127 * Sends a Google Analytics event with given `eventParams`. This method
128 * automatically associates this logged event with this Firebase web
129 * app instance on this device.
130 * @public
131 * List of recommended event parameters can be found in
132 * {@link https://developers.google.com/gtagjs/reference/ga4-events
133 * | the GA4 reference documentation}.
134 */
135export declare function logEvent(analyticsInstance: Analytics, eventName: 'add_shipping_info', eventParams?: {
136 coupon?: EventParams['coupon'];
137 currency?: EventParams['currency'];
138 items?: EventParams['items'];
139 shipping_tier?: EventParams['shipping_tier'];
140 value?: EventParams['value'];
141 [key: string]: any;
142}, options?: AnalyticsCallOptions): void;
143/**
144 * Sends a Google Analytics event with given `eventParams`. This method
145 * automatically associates this logged event with this Firebase web
146 * app instance on this device.
147 * @public
148 * List of recommended event parameters can be found in
149 * {@link https://developers.google.com/gtagjs/reference/ga4-events
150 * | the GA4 reference documentation}.
151 */
152export declare function logEvent(analyticsInstance: Analytics, eventName: 'add_to_cart' | 'add_to_wishlist' | 'remove_from_cart', eventParams?: {
153 currency?: EventParams['currency'];
154 value?: EventParams['value'];
155 items?: EventParams['items'];
156 [key: string]: any;
157}, options?: AnalyticsCallOptions): void;
158/**
159 * Sends a Google Analytics event with given `eventParams`. This method
160 * automatically associates this logged event with this Firebase web
161 * app instance on this device.
162 * @public
163 * List of recommended event parameters can be found in
164 * {@link https://developers.google.com/gtagjs/reference/ga4-events
165 * | the GA4 reference documentation}.
166 */
167export declare function logEvent(analyticsInstance: Analytics, eventName: 'begin_checkout', eventParams?: {
168 currency?: EventParams['currency'];
169 coupon?: EventParams['coupon'];
170 value?: EventParams['value'];
171 items?: EventParams['items'];
172 [key: string]: any;
173}, options?: AnalyticsCallOptions): void;
174/**
175 * Sends a Google Analytics event with given `eventParams`. This method
176 * automatically associates this logged event with this Firebase web
177 * app instance on this device.
178 * @public
179 * List of recommended event parameters can be found in
180 * {@link https://developers.google.com/gtagjs/reference/ga4-events
181 * | the GA4 reference documentation}.
182 */
183export declare function logEvent(analyticsInstance: Analytics, eventName: 'checkout_progress', eventParams?: {
184 currency?: EventParams['currency'];
185 coupon?: EventParams['coupon'];
186 value?: EventParams['value'];
187 items?: EventParams['items'];
188 checkout_step?: EventParams['checkout_step'];
189 checkout_option?: EventParams['checkout_option'];
190 [key: string]: any;
191}, options?: AnalyticsCallOptions): void;
192/**
193 * Sends a Google Analytics event with given `eventParams`. This method
194 * automatically associates this logged event with this Firebase web
195 * app instance on this device.
196 * @public
197 * See
198 * {@link https://developers.google.com/analytics/devguides/collection/ga4/exceptions
199 * | Measure exceptions}.
200 */
201export declare function logEvent(analyticsInstance: Analytics, eventName: 'exception', eventParams?: {
202 description?: EventParams['description'];
203 fatal?: EventParams['fatal'];
204 [key: string]: any;
205}, options?: AnalyticsCallOptions): void;
206/**
207 * Sends a Google Analytics event with given `eventParams`. This method
208 * automatically associates this logged event with this Firebase web
209 * app instance on this device.
210 * @public
211 * List of recommended event parameters can be found in
212 * {@link https://developers.google.com/gtagjs/reference/ga4-events
213 * | the GA4 reference documentation}.
214 */
215export declare function logEvent(analyticsInstance: Analytics, eventName: 'generate_lead', eventParams?: {
216 value?: EventParams['value'];
217 currency?: EventParams['currency'];
218 [key: string]: any;
219}, options?: AnalyticsCallOptions): void;
220/**
221 * Sends a Google Analytics event with given `eventParams`. This method
222 * automatically associates this logged event with this Firebase web
223 * app instance on this device.
224 * @public
225 * List of recommended event parameters can be found in
226 * {@link https://developers.google.com/gtagjs/reference/ga4-events
227 * | the GA4 reference documentation}.
228 */
229export declare function logEvent(analyticsInstance: Analytics, eventName: 'login', eventParams?: {
230 method?: EventParams['method'];
231 [key: string]: any;
232}, options?: AnalyticsCallOptions): void;
233/**
234 * Sends a Google Analytics event with given `eventParams`. This method
235 * automatically associates this logged event with this Firebase web
236 * app instance on this device.
237 * @public
238 * See
239 * {@link https://developers.google.com/analytics/devguides/collection/ga4/page-view
240 * | Page views}.
241 */
242export declare function logEvent(analyticsInstance: Analytics, eventName: 'page_view', eventParams?: {
243 page_title?: string;
244 page_location?: string;
245 page_path?: string;
246 [key: string]: any;
247}, options?: AnalyticsCallOptions): void;
248/**
249 * Sends a Google Analytics event with given `eventParams`. This method
250 * automatically associates this logged event with this Firebase web
251 * app instance on this device.
252 * @public
253 * List of recommended event parameters can be found in
254 * {@link https://developers.google.com/gtagjs/reference/ga4-events
255 * | the GA4 reference documentation}.
256 */
257export declare function logEvent(analyticsInstance: Analytics, eventName: 'purchase' | 'refund', eventParams?: {
258 value?: EventParams['value'];
259 currency?: EventParams['currency'];
260 transaction_id: EventParams['transaction_id'];
261 tax?: EventParams['tax'];
262 shipping?: EventParams['shipping'];
263 items?: EventParams['items'];
264 coupon?: EventParams['coupon'];
265 affiliation?: EventParams['affiliation'];
266 [key: string]: any;
267}, options?: AnalyticsCallOptions): void;
268/**
269 * Sends a Google Analytics event with given `eventParams`. This method
270 * automatically associates this logged event with this Firebase web
271 * app instance on this device.
272 * @public
273 * See {@link https://firebase.google.com/docs/analytics/screenviews
274 * | Track Screenviews}.
275 */
276export declare function logEvent(analyticsInstance: Analytics, eventName: 'screen_view', eventParams?: {
277 firebase_screen: EventParams['firebase_screen'];
278 firebase_screen_class: EventParams['firebase_screen_class'];
279 [key: string]: any;
280}, options?: AnalyticsCallOptions): void;
281/**
282 * Sends a Google Analytics event with given `eventParams`. This method
283 * automatically associates this logged event with this Firebase web
284 * app instance on this device.
285 * @public
286 * List of recommended event parameters can be found in
287 * {@link https://developers.google.com/gtagjs/reference/ga4-events
288 * | the GA4 reference documentation}.
289 */
290export declare function logEvent(analyticsInstance: Analytics, eventName: 'search' | 'view_search_results', eventParams?: {
291 search_term?: EventParams['search_term'];
292 [key: string]: any;
293}, options?: AnalyticsCallOptions): void;
294/**
295 * Sends a Google Analytics event with given `eventParams`. This method
296 * automatically associates this logged event with this Firebase web
297 * app instance on this device.
298 * @public
299 * List of recommended event parameters can be found in
300 * {@link https://developers.google.com/gtagjs/reference/ga4-events
301 * | the GA4 reference documentation}.
302 */
303export declare function logEvent(analyticsInstance: Analytics, eventName: 'select_content', eventParams?: {
304 content_type?: EventParams['content_type'];
305 item_id?: EventParams['item_id'];
306 [key: string]: any;
307}, options?: AnalyticsCallOptions): void;
308/**
309 * Sends a Google Analytics event with given `eventParams`. This method
310 * automatically associates this logged event with this Firebase web
311 * app instance on this device.
312 * @public
313 * List of recommended event parameters can be found in
314 * {@link https://developers.google.com/gtagjs/reference/ga4-events
315 * | the GA4 reference documentation}.
316 */
317export declare function logEvent(analyticsInstance: Analytics, eventName: 'select_item', eventParams?: {
318 items?: EventParams['items'];
319 item_list_name?: EventParams['item_list_name'];
320 item_list_id?: EventParams['item_list_id'];
321 [key: string]: any;
322}, options?: AnalyticsCallOptions): void;
323/**
324 * Sends a Google Analytics event with given `eventParams`. This method
325 * automatically associates this logged event with this Firebase web
326 * app instance on this device.
327 * @public
328 * List of recommended event parameters can be found in
329 * {@link https://developers.google.com/gtagjs/reference/ga4-events
330 * | the GA4 reference documentation}.
331 */
332export declare function logEvent(analyticsInstance: Analytics, eventName: 'select_promotion' | 'view_promotion', eventParams?: {
333 items?: EventParams['items'];
334 promotion_id?: EventParams['promotion_id'];
335 promotion_name?: EventParams['promotion_name'];
336 [key: string]: any;
337}, options?: AnalyticsCallOptions): void;
338/**
339 * Sends a Google Analytics event with given `eventParams`. This method
340 * automatically associates this logged event with this Firebase web
341 * app instance on this device.
342 * @public
343 * List of recommended event parameters can be found in
344 * {@link https://developers.google.com/gtagjs/reference/ga4-events
345 * | the GA4 reference documentation}.
346 */
347export declare function logEvent(analyticsInstance: Analytics, eventName: 'set_checkout_option', eventParams?: {
348 checkout_step?: EventParams['checkout_step'];
349 checkout_option?: EventParams['checkout_option'];
350 [key: string]: any;
351}, options?: AnalyticsCallOptions): void;
352/**
353 * Sends a Google Analytics event with given `eventParams`. This method
354 * automatically associates this logged event with this Firebase web
355 * app instance on this device.
356 * @public
357 * List of recommended event parameters can be found in
358 * {@link https://developers.google.com/gtagjs/reference/ga4-events
359 * | the GA4 reference documentation}.
360 */
361export declare function logEvent(analyticsInstance: Analytics, eventName: 'share', eventParams?: {
362 method?: EventParams['method'];
363 content_type?: EventParams['content_type'];
364 item_id?: EventParams['item_id'];
365 [key: string]: any;
366}, options?: AnalyticsCallOptions): void;
367/**
368 * Sends a Google Analytics event with given `eventParams`. This method
369 * automatically associates this logged event with this Firebase web
370 * app instance on this device.
371 * @public
372 * List of recommended event parameters can be found in
373 * {@link https://developers.google.com/gtagjs/reference/ga4-events
374 * | the GA4 reference documentation}.
375 */
376export declare function logEvent(analyticsInstance: Analytics, eventName: 'sign_up', eventParams?: {
377 method?: EventParams['method'];
378 [key: string]: any;
379}, options?: AnalyticsCallOptions): void;
380/**
381 * Sends a Google Analytics event with given `eventParams`. This method
382 * automatically associates this logged event with this Firebase web
383 * app instance on this device.
384 * @public
385 * List of recommended event parameters can be found in
386 * {@link https://developers.google.com/gtagjs/reference/ga4-events
387 * | the GA4 reference documentation}.
388 */
389export declare function logEvent(analyticsInstance: Analytics, eventName: 'timing_complete', eventParams?: {
390 name: string;
391 value: number;
392 event_category?: string;
393 event_label?: string;
394 [key: string]: any;
395}, options?: AnalyticsCallOptions): void;
396/**
397 * Sends a Google Analytics event with given `eventParams`. This method
398 * automatically associates this logged event with this Firebase web
399 * app instance on this device.
400 * @public
401 * List of recommended event parameters can be found in
402 * {@link https://developers.google.com/gtagjs/reference/ga4-events
403 * | the GA4 reference documentation}.
404 */
405export declare function logEvent(analyticsInstance: Analytics, eventName: 'view_cart' | 'view_item', eventParams?: {
406 currency?: EventParams['currency'];
407 items?: EventParams['items'];
408 value?: EventParams['value'];
409 [key: string]: any;
410}, options?: AnalyticsCallOptions): void;
411/**
412 * Sends a Google Analytics event with given `eventParams`. This method
413 * automatically associates this logged event with this Firebase web
414 * app instance on this device.
415 * @public
416 * List of recommended event parameters can be found in
417 * {@link https://developers.google.com/gtagjs/reference/ga4-events
418 * | the GA4 reference documentation}.
419 */
420export declare function logEvent(analyticsInstance: Analytics, eventName: 'view_item_list', eventParams?: {
421 items?: EventParams['items'];
422 item_list_name?: EventParams['item_list_name'];
423 item_list_id?: EventParams['item_list_id'];
424 [key: string]: any;
425}, options?: AnalyticsCallOptions): void;
426/**
427 * Sends a Google Analytics event with given `eventParams`. This method
428 * automatically associates this logged event with this Firebase web
429 * app instance on this device.
430 * @public
431 * List of recommended event parameters can be found in
432 * {@link https://developers.google.com/gtagjs/reference/ga4-events
433 * | the GA4 reference documentation}.
434 */
435export declare function logEvent<T extends string>(analyticsInstance: Analytics, eventName: CustomEventName<T>, eventParams?: {
436 [key: string]: any;
437}, options?: AnalyticsCallOptions): void;
438/**
439 * Any custom event name string not in the standard list of recommended
440 * event names.
441 * @public
442 */
443export declare type CustomEventName<T> = T extends EventNameString ? never : T;
444/**
445 * Sets the applicable end user consent state for this web app across all gtag references once
446 * Firebase Analytics is initialized.
447 *
448 * Use the {@link ConsentSettings} to specify individual consent type values. By default consent
449 * types are set to "granted".
450 * @public
451 * @param consentSettings - Maps the applicable end user consent state for gtag.js.
452 */
453export declare function setConsent(consentSettings: ConsentSettings): void;