UNPKG

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