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 | */
|
17 | import { FirebaseApp } from '@firebase/app';
|
18 | /**
|
19 | * A set of common Google Analytics config settings recognized by
|
20 | * `gtag.js`.
|
21 | * @public
|
22 | */
|
23 | export interface GtagConfigParams {
|
24 | /**
|
25 | * Whether or not a page view should be sent.
|
26 | * If set to true (default), a page view is automatically sent upon initialization
|
27 | * of analytics.
|
28 | * See {@link https://developers.google.com/analytics/devguides/collection/ga4/page-view | Page views }
|
29 | */
|
30 | 'send_page_view'?: boolean;
|
31 | /**
|
32 | * The title of the page.
|
33 | * See {@link https://developers.google.com/analytics/devguides/collection/ga4/page-view | Page views }
|
34 | */
|
35 | 'page_title'?: string;
|
36 | /**
|
37 | * The URL of the page.
|
38 | * See {@link https://developers.google.com/analytics/devguides/collection/ga4/page-view | Page views }
|
39 | */
|
40 | 'page_location'?: string;
|
41 | /**
|
42 | * Defaults to `auto`.
|
43 | * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification }
|
44 | */
|
45 | 'cookie_domain'?: string;
|
46 | /**
|
47 | * Defaults to 63072000 (two years, in seconds).
|
48 | * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification }
|
49 | */
|
50 | 'cookie_expires'?: number;
|
51 | /**
|
52 | * Defaults to `_ga`.
|
53 | * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification }
|
54 | */
|
55 | 'cookie_prefix'?: string;
|
56 | /**
|
57 | * If set to true, will update cookies on each page load.
|
58 | * Defaults to true.
|
59 | * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification }
|
60 | */
|
61 | 'cookie_update'?: boolean;
|
62 | /**
|
63 | * Appends additional flags to the cookie when set.
|
64 | * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification }
|
65 | */
|
66 | 'cookie_flags'?: string;
|
67 | /**
|
68 | * If set to false, disables all advertising features with `gtag.js`.
|
69 | * See {@link https://developers.google.com/analytics/devguides/collection/ga4/display-features | Disable advertising features }
|
70 | */
|
71 | 'allow_google_signals'?: boolean;
|
72 | /**
|
73 | * If set to false, disables all advertising personalization with `gtag.js`.
|
74 | * See {@link https://developers.google.com/analytics/devguides/collection/ga4/display-features | Disable advertising features }
|
75 | */
|
76 | 'allow_ad_personalization_signals'?: boolean;
|
77 | [key: string]: unknown;
|
78 | }
|
79 | /**
|
80 | * {@link Analytics} instance initialization options.
|
81 | * @public
|
82 | */
|
83 | export interface AnalyticsSettings {
|
84 | /**
|
85 | * Params to be passed in the initial `gtag` config call during Firebase
|
86 | * Analytics initialization.
|
87 | */
|
88 | config?: GtagConfigParams | EventParams;
|
89 | }
|
90 | /**
|
91 | * Additional options that can be passed to Analytics method
|
92 | * calls such as `logEvent`, etc.
|
93 | * @public
|
94 | */
|
95 | export interface AnalyticsCallOptions {
|
96 | /**
|
97 | * If true, this config or event call applies globally to all
|
98 | * Google Analytics properties on the page.
|
99 | */
|
100 | global: boolean;
|
101 | }
|
102 | /**
|
103 | * An instance of Firebase Analytics.
|
104 | * @public
|
105 | */
|
106 | export interface Analytics {
|
107 | /**
|
108 | * The {@link @firebase/app#FirebaseApp} this {@link Analytics} instance is associated with.
|
109 | */
|
110 | app: FirebaseApp;
|
111 | }
|
112 | /**
|
113 | * Specifies custom options for your Firebase Analytics instance.
|
114 | * You must set these before initializing `firebase.analytics()`.
|
115 | * @public
|
116 | */
|
117 | export interface SettingsOptions {
|
118 | /** Sets custom name for `gtag` function. */
|
119 | gtagName?: string;
|
120 | /** Sets custom name for `dataLayer` array used by `gtag.js`. */
|
121 | dataLayerName?: string;
|
122 | }
|
123 | /**
|
124 | * Any custom params the user may pass to `gtag`.
|
125 | * @public
|
126 | */
|
127 | export interface CustomParams {
|
128 | [key: string]: unknown;
|
129 | }
|
130 | /**
|
131 | * Type for standard Google Analytics event names. `logEvent` also accepts any
|
132 | * custom string and interprets it as a custom event name.
|
133 | * @public
|
134 | */
|
135 | export declare type EventNameString = 'add_payment_info' | 'add_shipping_info' | 'add_to_cart' | 'add_to_wishlist' | 'begin_checkout' | 'checkout_progress' | 'exception' | 'generate_lead' | 'login' | 'page_view' | 'purchase' | 'refund' | 'remove_from_cart' | 'screen_view' | 'search' | 'select_content' | 'select_item' | 'select_promotion' | 'set_checkout_option' | 'share' | 'sign_up' | 'timing_complete' | 'view_cart' | 'view_item' | 'view_item_list' | 'view_promotion' | 'view_search_results';
|
136 | /**
|
137 | * Standard Google Analytics currency type.
|
138 | * @public
|
139 | */
|
140 | export declare type Currency = string | number;
|
141 | /**
|
142 | * Standard Google Analytics `Item` type.
|
143 | * @public
|
144 | */
|
145 | export interface Item {
|
146 | item_id?: string;
|
147 | item_name?: string;
|
148 | item_brand?: string;
|
149 | item_category?: string;
|
150 | item_category2?: string;
|
151 | item_category3?: string;
|
152 | item_category4?: string;
|
153 | item_category5?: string;
|
154 | item_variant?: string;
|
155 | price?: Currency;
|
156 | quantity?: number;
|
157 | index?: number;
|
158 | coupon?: string;
|
159 | item_list_name?: string;
|
160 | item_list_id?: string;
|
161 | discount?: Currency;
|
162 | affiliation?: string;
|
163 | creative_name?: string;
|
164 | creative_slot?: string;
|
165 | promotion_id?: string;
|
166 | promotion_name?: string;
|
167 | location_id?: string;
|
168 | /** @deprecated Use item_brand instead. */
|
169 | brand?: string;
|
170 | /** @deprecated Use item_category instead. */
|
171 | category?: string;
|
172 | /** @deprecated Use item_id instead. */
|
173 | id?: string;
|
174 | /** @deprecated Use item_name instead. */
|
175 | name?: string;
|
176 | }
|
177 | /**
|
178 | * Field previously used by some Google Analytics events.
|
179 | * @deprecated Use `Item` instead.
|
180 | * @public
|
181 | */
|
182 | export interface Promotion {
|
183 | creative_name?: string;
|
184 | creative_slot?: string;
|
185 | id?: string;
|
186 | name?: string;
|
187 | }
|
188 | /**
|
189 | * Standard `gtag.js` control parameters.
|
190 | * For more information, see
|
191 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
192 | * | the GA4 reference documentation}.
|
193 | * @public
|
194 | */
|
195 | export interface ControlParams {
|
196 | groups?: string | string[];
|
197 | send_to?: string | string[];
|
198 | event_callback?: () => void;
|
199 | event_timeout?: number;
|
200 | }
|
201 | /**
|
202 | * Standard `gtag.js` event parameters.
|
203 | * For more information, see
|
204 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
205 | * | the GA4 reference documentation}.
|
206 | * @public
|
207 | */
|
208 | export interface EventParams {
|
209 | checkout_option?: string;
|
210 | checkout_step?: number;
|
211 | item_id?: string;
|
212 | content_type?: string;
|
213 | coupon?: string;
|
214 | currency?: string;
|
215 | description?: string;
|
216 | fatal?: boolean;
|
217 | items?: Item[];
|
218 | method?: string;
|
219 | number?: string;
|
220 | promotions?: Promotion[];
|
221 | screen_name?: string;
|
222 | /**
|
223 | * Firebase-specific. Use to log a `screen_name` to Firebase Analytics.
|
224 | */
|
225 | firebase_screen?: string;
|
226 | /**
|
227 | * Firebase-specific. Use to log a `screen_class` to Firebase Analytics.
|
228 | */
|
229 | firebase_screen_class?: string;
|
230 | search_term?: string;
|
231 | shipping?: Currency;
|
232 | tax?: Currency;
|
233 | transaction_id?: string;
|
234 | value?: number;
|
235 | event_label?: string;
|
236 | event_category?: string;
|
237 | shipping_tier?: string;
|
238 | item_list_id?: string;
|
239 | item_list_name?: string;
|
240 | promotion_id?: string;
|
241 | promotion_name?: string;
|
242 | payment_type?: string;
|
243 | affiliation?: string;
|
244 | page_title?: string;
|
245 | page_location?: string;
|
246 | page_path?: string;
|
247 | [key: string]: unknown;
|
248 | }
|
249 | /**
|
250 | * Consent status settings for each consent type.
|
251 | * For more information, see
|
252 | * {@link https://developers.google.com/tag-platform/tag-manager/templates/consent-apis
|
253 | * | the GA4 reference documentation for consent state and consent types}.
|
254 | * @public
|
255 | */
|
256 | export interface ConsentSettings {
|
257 | /** Enables storage, such as cookies, related to advertising */
|
258 | ad_storage?: ConsentStatusString;
|
259 | /** Enables storage, such as cookies, related to analytics (for example, visit duration) */
|
260 | analytics_storage?: ConsentStatusString;
|
261 | /**
|
262 | * Enables storage that supports the functionality of the website or app such as language settings
|
263 | */
|
264 | functionality_storage?: ConsentStatusString;
|
265 | /** Enables storage related to personalization such as video recommendations */
|
266 | personalization_storage?: ConsentStatusString;
|
267 | /**
|
268 | * Enables storage related to security such as authentication functionality, fraud prevention,
|
269 | * and other user protection.
|
270 | */
|
271 | security_storage?: ConsentStatusString;
|
272 | [key: string]: unknown;
|
273 | }
|
274 | /**
|
275 | * Whether a particular consent type has been granted or denied.
|
276 | * @public
|
277 | */
|
278 | export declare type ConsentStatusString = 'granted' | 'denied';
|