@firebase/analytics 0.10.6-canary.46da0930c → 0.10.6-canary.6bb2e8931

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,6 @@
1
1
  import { getApp, _getProvider, _registerComponent, registerVersion } from '@firebase/app';
2
- import { __makeTemplateObject, __awaiter, __generator, __spreadArray, __assign } from 'tslib';
2
+ import { __awaiter, __generator, __spreadArray, __assign } from 'tslib';
3
3
  import { Logger } from '@firebase/logger';
4
- import { trustedResourceUrl } from 'safevalues';
5
- import { safeScriptEl } from 'safevalues/dom';
6
4
  import { ErrorFactory, calculateBackoffMillis, FirebaseError, validateIndexedDBOpenable, isIndexedDBAvailable, isBrowserExtension, areCookiesEnabled, getModularInstance, deepEqual } from '@firebase/util';
7
5
  import { Component } from '@firebase/component';
8
6
  import '@firebase/installations';
@@ -68,6 +66,66 @@ var logger = new Logger('@firebase/analytics');
68
66
  * See the License for the specific language governing permissions and
69
67
  * limitations under the License.
70
68
  */
69
+ var _a;
70
+ var ERRORS = (_a = {},
71
+ _a["already-exists" /* AnalyticsError.ALREADY_EXISTS */] = 'A Firebase Analytics instance with the appId {$id} ' +
72
+ ' already exists. ' +
73
+ 'Only one Firebase Analytics instance can be created for each appId.',
74
+ _a["already-initialized" /* AnalyticsError.ALREADY_INITIALIZED */] = 'initializeAnalytics() cannot be called again with different options than those ' +
75
+ 'it was initially called with. It can be called again with the same options to ' +
76
+ 'return the existing instance, or getAnalytics() can be used ' +
77
+ 'to get a reference to the already-initialized instance.',
78
+ _a["already-initialized-settings" /* AnalyticsError.ALREADY_INITIALIZED_SETTINGS */] = 'Firebase Analytics has already been initialized.' +
79
+ 'settings() must be called before initializing any Analytics instance' +
80
+ 'or it will have no effect.',
81
+ _a["interop-component-reg-failed" /* AnalyticsError.INTEROP_COMPONENT_REG_FAILED */] = 'Firebase Analytics Interop Component failed to instantiate: {$reason}',
82
+ _a["invalid-analytics-context" /* AnalyticsError.INVALID_ANALYTICS_CONTEXT */] = 'Firebase Analytics is not supported in this environment. ' +
83
+ 'Wrap initialization of analytics in analytics.isSupported() ' +
84
+ 'to prevent initialization in unsupported environments. Details: {$errorInfo}',
85
+ _a["indexeddb-unavailable" /* AnalyticsError.INDEXEDDB_UNAVAILABLE */] = 'IndexedDB unavailable or restricted in this environment. ' +
86
+ 'Wrap initialization of analytics in analytics.isSupported() ' +
87
+ 'to prevent initialization in unsupported environments. Details: {$errorInfo}',
88
+ _a["fetch-throttle" /* AnalyticsError.FETCH_THROTTLE */] = 'The config fetch request timed out while in an exponential backoff state.' +
89
+ ' Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.',
90
+ _a["config-fetch-failed" /* AnalyticsError.CONFIG_FETCH_FAILED */] = 'Dynamic config fetch failed: [{$httpStatus}] {$responseMessage}',
91
+ _a["no-api-key" /* AnalyticsError.NO_API_KEY */] = 'The "apiKey" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
92
+ 'contain a valid API key.',
93
+ _a["no-app-id" /* AnalyticsError.NO_APP_ID */] = 'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
94
+ 'contain a valid app ID.',
95
+ _a["no-client-id" /* AnalyticsError.NO_CLIENT_ID */] = 'The "client_id" field is empty.',
96
+ _a["invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */] = 'Trusted Types detected an invalid gtag resource: {$gtagURL}.',
97
+ _a);
98
+ var ERROR_FACTORY = new ErrorFactory('analytics', 'Analytics', ERRORS);
99
+
100
+ /**
101
+ * @license
102
+ * Copyright 2019 Google LLC
103
+ *
104
+ * Licensed under the Apache License, Version 2.0 (the "License");
105
+ * you may not use this file except in compliance with the License.
106
+ * You may obtain a copy of the License at
107
+ *
108
+ * http://www.apache.org/licenses/LICENSE-2.0
109
+ *
110
+ * Unless required by applicable law or agreed to in writing, software
111
+ * distributed under the License is distributed on an "AS IS" BASIS,
112
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
113
+ * See the License for the specific language governing permissions and
114
+ * limitations under the License.
115
+ */
116
+ /**
117
+ * Verifies and creates a TrustedScriptURL.
118
+ */
119
+ function createGtagTrustedTypesScriptURL(url) {
120
+ if (!url.startsWith(GTAG_URL)) {
121
+ var err = ERROR_FACTORY.create("invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */, {
122
+ gtagURL: url
123
+ });
124
+ logger.warn(err.message);
125
+ return '';
126
+ }
127
+ return url;
128
+ }
71
129
  /**
72
130
  * Makeshift polyfill for Promise.allSettled(). Resolves when all promises
73
131
  * have either resolved or rejected.
@@ -77,21 +135,37 @@ var logger = new Logger('@firebase/analytics');
77
135
  function promiseAllSettled(promises) {
78
136
  return Promise.all(promises.map(function (promise) { return promise.catch(function (e) { return e; }); }));
79
137
  }
138
+ /**
139
+ * Creates a TrustedTypePolicy object that implements the rules passed as policyOptions.
140
+ *
141
+ * @param policyName A string containing the name of the policy
142
+ * @param policyOptions Object containing implementations of instance methods for TrustedTypesPolicy, see {@link https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicy#instance_methods
143
+ * | the TrustedTypePolicy reference documentation}.
144
+ */
145
+ function createTrustedTypesPolicy(policyName, policyOptions) {
146
+ // Create a TrustedTypes policy that we can use for updating src
147
+ // properties
148
+ var trustedTypesPolicy;
149
+ if (window.trustedTypes) {
150
+ trustedTypesPolicy = window.trustedTypes.createPolicy(policyName, policyOptions);
151
+ }
152
+ return trustedTypesPolicy;
153
+ }
80
154
  /**
81
155
  * Inserts gtag script tag into the page to asynchronously download gtag.
82
156
  * @param dataLayerName Name of datalayer (most often the default, "_dataLayer").
83
157
  */
84
158
  function insertScriptTag(dataLayerName, measurementId) {
159
+ var trustedTypesPolicy = createTrustedTypesPolicy('firebase-js-sdk-policy', {
160
+ createScriptURL: createGtagTrustedTypesScriptURL
161
+ });
85
162
  var script = document.createElement('script');
86
163
  // We are not providing an analyticsId in the URL because it would trigger a `page_view`
87
164
  // without fid. We will initialize ga-id using gtag (config) command together with fid.
88
- //
89
- // We also have to ensure the template string before the first expression constitutes a valid URL
90
- // start, as this is what the initial validation focuses on. If the template literal begins
91
- // directly with an expression (e.g. `${GTAG_SCRIPT_URL}`), the validation fails due to an
92
- // empty initial string.
93
- var url = trustedResourceUrl(templateObject_1 || (templateObject_1 = __makeTemplateObject(["https://www.googletagmanager.com/gtag/js?l=", "&id=", ""], ["https://www.googletagmanager.com/gtag/js?l=", "&id=", ""])), dataLayerName, measurementId);
94
- safeScriptEl.setSrc(script, url);
165
+ var gtagScriptURL = "".concat(GTAG_URL, "?l=").concat(dataLayerName, "&id=").concat(measurementId);
166
+ script.src = trustedTypesPolicy
167
+ ? trustedTypesPolicy === null || trustedTypesPolicy === void 0 ? void 0 : trustedTypesPolicy.createScriptURL(gtagScriptURL)
168
+ : gtagScriptURL;
95
169
  script.async = true;
96
170
  document.head.appendChild(script);
97
171
  }
@@ -209,6 +283,7 @@ function gtagOnEvent(gtagCore, initializationPromisesMap, dynamicConfigPromisesL
209
283
  // if not all entries in the 'send_to' field could be mapped to
210
284
  // a FID. In these cases, wait on all pending initialization promises.
211
285
  if (initializationPromisesToWaitFor.length === 0) {
286
+ /* eslint-disable-next-line @typescript-eslint/no-floating-promises */
212
287
  initializationPromisesToWaitFor = Object.values(initializationPromisesMap);
213
288
  }
214
289
  // Run core gtag function with args after all relevant initialization
@@ -365,55 +440,7 @@ function findGtagScriptOnPage(dataLayerName) {
365
440
  }
366
441
  }
367
442
  return null;
368
- }
369
- var templateObject_1;
370
-
371
- /**
372
- * @license
373
- * Copyright 2019 Google LLC
374
- *
375
- * Licensed under the Apache License, Version 2.0 (the "License");
376
- * you may not use this file except in compliance with the License.
377
- * You may obtain a copy of the License at
378
- *
379
- * http://www.apache.org/licenses/LICENSE-2.0
380
- *
381
- * Unless required by applicable law or agreed to in writing, software
382
- * distributed under the License is distributed on an "AS IS" BASIS,
383
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
384
- * See the License for the specific language governing permissions and
385
- * limitations under the License.
386
- */
387
- var _a;
388
- var ERRORS = (_a = {},
389
- _a["already-exists" /* AnalyticsError.ALREADY_EXISTS */] = 'A Firebase Analytics instance with the appId {$id} ' +
390
- ' already exists. ' +
391
- 'Only one Firebase Analytics instance can be created for each appId.',
392
- _a["already-initialized" /* AnalyticsError.ALREADY_INITIALIZED */] = 'initializeAnalytics() cannot be called again with different options than those ' +
393
- 'it was initially called with. It can be called again with the same options to ' +
394
- 'return the existing instance, or getAnalytics() can be used ' +
395
- 'to get a reference to the already-initialized instance.',
396
- _a["already-initialized-settings" /* AnalyticsError.ALREADY_INITIALIZED_SETTINGS */] = 'Firebase Analytics has already been initialized.' +
397
- 'settings() must be called before initializing any Analytics instance' +
398
- 'or it will have no effect.',
399
- _a["interop-component-reg-failed" /* AnalyticsError.INTEROP_COMPONENT_REG_FAILED */] = 'Firebase Analytics Interop Component failed to instantiate: {$reason}',
400
- _a["invalid-analytics-context" /* AnalyticsError.INVALID_ANALYTICS_CONTEXT */] = 'Firebase Analytics is not supported in this environment. ' +
401
- 'Wrap initialization of analytics in analytics.isSupported() ' +
402
- 'to prevent initialization in unsupported environments. Details: {$errorInfo}',
403
- _a["indexeddb-unavailable" /* AnalyticsError.INDEXEDDB_UNAVAILABLE */] = 'IndexedDB unavailable or restricted in this environment. ' +
404
- 'Wrap initialization of analytics in analytics.isSupported() ' +
405
- 'to prevent initialization in unsupported environments. Details: {$errorInfo}',
406
- _a["fetch-throttle" /* AnalyticsError.FETCH_THROTTLE */] = 'The config fetch request timed out while in an exponential backoff state.' +
407
- ' Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.',
408
- _a["config-fetch-failed" /* AnalyticsError.CONFIG_FETCH_FAILED */] = 'Dynamic config fetch failed: [{$httpStatus}] {$responseMessage}',
409
- _a["no-api-key" /* AnalyticsError.NO_API_KEY */] = 'The "apiKey" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
410
- 'contain a valid API key.',
411
- _a["no-app-id" /* AnalyticsError.NO_APP_ID */] = 'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
412
- 'contain a valid app ID.',
413
- _a["no-client-id" /* AnalyticsError.NO_CLIENT_ID */] = 'The "client_id" field is empty.',
414
- _a["invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */] = 'Trusted Types detected an invalid gtag resource: {$gtagURL}.',
415
- _a);
416
- var ERROR_FACTORY = new ErrorFactory('analytics', 'Analytics', ERRORS);
443
+ }
417
444
 
418
445
  /**
419
446
  * @license
@@ -1390,7 +1417,7 @@ function setConsent(consentSettings) {
1390
1417
  }
1391
1418
 
1392
1419
  var name = "@firebase/analytics";
1393
- var version = "0.10.6-canary.46da0930c";
1420
+ var version = "0.10.6-canary.6bb2e8931";
1394
1421
 
1395
1422
  /**
1396
1423
  * The Firebase Analytics Web SDK.