@firebase/analytics 0.10.5-canary.d752e8096 → 0.10.5-canary.fd8bd4b02

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,6 +1,8 @@
1
1
  import { getApp, _getProvider, _registerComponent, registerVersion } from '@firebase/app';
2
- import { __awaiter, __generator, __spreadArray, __assign } from 'tslib';
2
+ import { __makeTemplateObject, __awaiter, __generator, __spreadArray, __assign } from 'tslib';
3
3
  import { Logger } from '@firebase/logger';
4
+ import { trustedResourceUrl } from 'safevalues';
5
+ import { safeScriptEl } from 'safevalues/dom';
4
6
  import { ErrorFactory, calculateBackoffMillis, FirebaseError, validateIndexedDBOpenable, isIndexedDBAvailable, isBrowserExtension, areCookiesEnabled, getModularInstance, deepEqual } from '@firebase/util';
5
7
  import { Component } from '@firebase/component';
6
8
  import '@firebase/installations';
@@ -66,66 +68,6 @@ var logger = new Logger('@firebase/analytics');
66
68
  * See the License for the specific language governing permissions and
67
69
  * limitations under the License.
68
70
  */
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-intialized 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
- }
129
71
  /**
130
72
  * Makeshift polyfill for Promise.allSettled(). Resolves when all promises
131
73
  * have either resolved or rejected.
@@ -135,37 +77,21 @@ function createGtagTrustedTypesScriptURL(url) {
135
77
  function promiseAllSettled(promises) {
136
78
  return Promise.all(promises.map(function (promise) { return promise.catch(function (e) { return e; }); }));
137
79
  }
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
- }
154
80
  /**
155
81
  * Inserts gtag script tag into the page to asynchronously download gtag.
156
82
  * @param dataLayerName Name of datalayer (most often the default, "_dataLayer").
157
83
  */
158
84
  function insertScriptTag(dataLayerName, measurementId) {
159
- var trustedTypesPolicy = createTrustedTypesPolicy('firebase-js-sdk-policy', {
160
- createScriptURL: createGtagTrustedTypesScriptURL
161
- });
162
85
  var script = document.createElement('script');
163
86
  // We are not providing an analyticsId in the URL because it would trigger a `page_view`
164
87
  // without fid. We will initialize ga-id using gtag (config) command together with fid.
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;
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);
169
95
  script.async = true;
170
96
  document.head.appendChild(script);
171
97
  }
@@ -439,7 +365,55 @@ function findGtagScriptOnPage(dataLayerName) {
439
365
  }
440
366
  }
441
367
  return null;
442
- }
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-intialized 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
  * @license
@@ -1416,7 +1390,7 @@ function setConsent(consentSettings) {
1416
1390
  }
1417
1391
 
1418
1392
  var name = "@firebase/analytics";
1419
- var version = "0.10.5-canary.d752e8096";
1393
+ var version = "0.10.5-canary.fd8bd4b02";
1420
1394
 
1421
1395
  /**
1422
1396
  * The Firebase Analytics Web SDK.