UNPKG

2.37 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2019 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 { DynamicConfig, DataLayer, Gtag, MinimalDynamicConfig } from '@firebase/analytics-types';
18/**
19 * Inserts gtag script tag into the page to asynchronously download gtag.
20 * @param dataLayerName Name of datalayer (most often the default, "_dataLayer").
21 */
22export declare function insertScriptTag(dataLayerName: string, measurementId: string): void;
23/**
24 * Get reference to, or create, global datalayer.
25 * @param dataLayerName Name of datalayer (most often the default, "_dataLayer").
26 */
27export declare function getOrCreateDataLayer(dataLayerName: string): DataLayer;
28/**
29 * Creates global gtag function or wraps existing one if found.
30 * This wrapped function attaches Firebase instance ID (FID) to gtag 'config' and
31 * 'event' calls that belong to the GAID associated with this Firebase instance.
32 *
33 * @param initializationPromisesMap Map of appIds to their initialization promises.
34 * @param dynamicConfigPromisesList Array of dynamic config fetch promises.
35 * @param measurementIdToAppId Map of GA measurementIDs to corresponding Firebase appId.
36 * @param dataLayerName Name of global GA datalayer array.
37 * @param gtagFunctionName Name of global gtag function ("gtag" if not user-specified).
38 */
39export declare function wrapOrCreateGtag(initializationPromisesMap: {
40 [appId: string]: Promise<string>;
41}, dynamicConfigPromisesList: Array<Promise<DynamicConfig | MinimalDynamicConfig>>, measurementIdToAppId: {
42 [measurementId: string]: string;
43}, dataLayerName: string, gtagFunctionName: string): {
44 gtagCore: Gtag;
45 wrappedGtag: Gtag;
46};
47/**
48 * Returns first script tag in DOM matching our gtag url pattern.
49 */
50export declare function findGtagScriptOnPage(): HTMLScriptElement | null;