@firebase/analytics 0.10.5-canary.9cd3c1eca → 0.10.5-canary.f58d48cd4

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.
package/dist/index.cjs.js CHANGED
@@ -5,6 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var app = require('@firebase/app');
6
6
  var tslib = require('tslib');
7
7
  var logger$1 = require('@firebase/logger');
8
+ var safevalues = require('safevalues');
9
+ var dom = require('safevalues/dom');
8
10
  var util = require('@firebase/util');
9
11
  var component = require('@firebase/component');
10
12
  require('@firebase/installations');
@@ -70,66 +72,6 @@ var logger = new logger$1.Logger('@firebase/analytics');
70
72
  * See the License for the specific language governing permissions and
71
73
  * limitations under the License.
72
74
  */
73
- var _a;
74
- var ERRORS = (_a = {},
75
- _a["already-exists" /* AnalyticsError.ALREADY_EXISTS */] = 'A Firebase Analytics instance with the appId {$id} ' +
76
- ' already exists. ' +
77
- 'Only one Firebase Analytics instance can be created for each appId.',
78
- _a["already-initialized" /* AnalyticsError.ALREADY_INITIALIZED */] = 'initializeAnalytics() cannot be called again with different options than those ' +
79
- 'it was initially called with. It can be called again with the same options to ' +
80
- 'return the existing instance, or getAnalytics() can be used ' +
81
- 'to get a reference to the already-intialized instance.',
82
- _a["already-initialized-settings" /* AnalyticsError.ALREADY_INITIALIZED_SETTINGS */] = 'Firebase Analytics has already been initialized.' +
83
- 'settings() must be called before initializing any Analytics instance' +
84
- 'or it will have no effect.',
85
- _a["interop-component-reg-failed" /* AnalyticsError.INTEROP_COMPONENT_REG_FAILED */] = 'Firebase Analytics Interop Component failed to instantiate: {$reason}',
86
- _a["invalid-analytics-context" /* AnalyticsError.INVALID_ANALYTICS_CONTEXT */] = 'Firebase Analytics is not supported in this environment. ' +
87
- 'Wrap initialization of analytics in analytics.isSupported() ' +
88
- 'to prevent initialization in unsupported environments. Details: {$errorInfo}',
89
- _a["indexeddb-unavailable" /* AnalyticsError.INDEXEDDB_UNAVAILABLE */] = 'IndexedDB unavailable or restricted in this environment. ' +
90
- 'Wrap initialization of analytics in analytics.isSupported() ' +
91
- 'to prevent initialization in unsupported environments. Details: {$errorInfo}',
92
- _a["fetch-throttle" /* AnalyticsError.FETCH_THROTTLE */] = 'The config fetch request timed out while in an exponential backoff state.' +
93
- ' Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.',
94
- _a["config-fetch-failed" /* AnalyticsError.CONFIG_FETCH_FAILED */] = 'Dynamic config fetch failed: [{$httpStatus}] {$responseMessage}',
95
- _a["no-api-key" /* AnalyticsError.NO_API_KEY */] = 'The "apiKey" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
96
- 'contain a valid API key.',
97
- _a["no-app-id" /* AnalyticsError.NO_APP_ID */] = 'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
98
- 'contain a valid app ID.',
99
- _a["no-client-id" /* AnalyticsError.NO_CLIENT_ID */] = 'The "client_id" field is empty.',
100
- _a["invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */] = 'Trusted Types detected an invalid gtag resource: {$gtagURL}.',
101
- _a);
102
- var ERROR_FACTORY = new util.ErrorFactory('analytics', 'Analytics', ERRORS);
103
-
104
- /**
105
- * @license
106
- * Copyright 2019 Google LLC
107
- *
108
- * Licensed under the Apache License, Version 2.0 (the "License");
109
- * you may not use this file except in compliance with the License.
110
- * You may obtain a copy of the License at
111
- *
112
- * http://www.apache.org/licenses/LICENSE-2.0
113
- *
114
- * Unless required by applicable law or agreed to in writing, software
115
- * distributed under the License is distributed on an "AS IS" BASIS,
116
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
117
- * See the License for the specific language governing permissions and
118
- * limitations under the License.
119
- */
120
- /**
121
- * Verifies and creates a TrustedScriptURL.
122
- */
123
- function createGtagTrustedTypesScriptURL(url) {
124
- if (!url.startsWith(GTAG_URL)) {
125
- var err = ERROR_FACTORY.create("invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */, {
126
- gtagURL: url
127
- });
128
- logger.warn(err.message);
129
- return '';
130
- }
131
- return url;
132
- }
133
75
  /**
134
76
  * Makeshift polyfill for Promise.allSettled(). Resolves when all promises
135
77
  * have either resolved or rejected.
@@ -139,37 +81,21 @@ function createGtagTrustedTypesScriptURL(url) {
139
81
  function promiseAllSettled(promises) {
140
82
  return Promise.all(promises.map(function (promise) { return promise.catch(function (e) { return e; }); }));
141
83
  }
142
- /**
143
- * Creates a TrustedTypePolicy object that implements the rules passed as policyOptions.
144
- *
145
- * @param policyName A string containing the name of the policy
146
- * @param policyOptions Object containing implementations of instance methods for TrustedTypesPolicy, see {@link https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicy#instance_methods
147
- * | the TrustedTypePolicy reference documentation}.
148
- */
149
- function createTrustedTypesPolicy(policyName, policyOptions) {
150
- // Create a TrustedTypes policy that we can use for updating src
151
- // properties
152
- var trustedTypesPolicy;
153
- if (window.trustedTypes) {
154
- trustedTypesPolicy = window.trustedTypes.createPolicy(policyName, policyOptions);
155
- }
156
- return trustedTypesPolicy;
157
- }
158
84
  /**
159
85
  * Inserts gtag script tag into the page to asynchronously download gtag.
160
86
  * @param dataLayerName Name of datalayer (most often the default, "_dataLayer").
161
87
  */
162
88
  function insertScriptTag(dataLayerName, measurementId) {
163
- var trustedTypesPolicy = createTrustedTypesPolicy('firebase-js-sdk-policy', {
164
- createScriptURL: createGtagTrustedTypesScriptURL
165
- });
166
89
  var script = document.createElement('script');
167
90
  // We are not providing an analyticsId in the URL because it would trigger a `page_view`
168
91
  // without fid. We will initialize ga-id using gtag (config) command together with fid.
169
- var gtagScriptURL = "".concat(GTAG_URL, "?l=").concat(dataLayerName, "&id=").concat(measurementId);
170
- script.src = trustedTypesPolicy
171
- ? trustedTypesPolicy === null || trustedTypesPolicy === void 0 ? void 0 : trustedTypesPolicy.createScriptURL(gtagScriptURL)
172
- : gtagScriptURL;
92
+ //
93
+ // We also have to ensure the template string before the first expression constitutes a valid URL
94
+ // start, as this is what the initial validation focuses on. If the template literal begins
95
+ // directly with an expression (e.g. `${GTAG_SCRIPT_URL}`), the validation fails due to an
96
+ // empty initial string.
97
+ var url = safevalues.trustedResourceUrl(templateObject_1 || (templateObject_1 = tslib.__makeTemplateObject(["https://www.googletagmanager.com/gtag/js?l=", "&id=", ""], ["https://www.googletagmanager.com/gtag/js?l=", "&id=", ""])), dataLayerName, measurementId);
98
+ dom.safeScriptEl.setSrc(script, url);
173
99
  script.async = true;
174
100
  document.head.appendChild(script);
175
101
  }
@@ -443,7 +369,55 @@ function findGtagScriptOnPage(dataLayerName) {
443
369
  }
444
370
  }
445
371
  return null;
446
- }
372
+ }
373
+ var templateObject_1;
374
+
375
+ /**
376
+ * @license
377
+ * Copyright 2019 Google LLC
378
+ *
379
+ * Licensed under the Apache License, Version 2.0 (the "License");
380
+ * you may not use this file except in compliance with the License.
381
+ * You may obtain a copy of the License at
382
+ *
383
+ * http://www.apache.org/licenses/LICENSE-2.0
384
+ *
385
+ * Unless required by applicable law or agreed to in writing, software
386
+ * distributed under the License is distributed on an "AS IS" BASIS,
387
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
388
+ * See the License for the specific language governing permissions and
389
+ * limitations under the License.
390
+ */
391
+ var _a;
392
+ var ERRORS = (_a = {},
393
+ _a["already-exists" /* AnalyticsError.ALREADY_EXISTS */] = 'A Firebase Analytics instance with the appId {$id} ' +
394
+ ' already exists. ' +
395
+ 'Only one Firebase Analytics instance can be created for each appId.',
396
+ _a["already-initialized" /* AnalyticsError.ALREADY_INITIALIZED */] = 'initializeAnalytics() cannot be called again with different options than those ' +
397
+ 'it was initially called with. It can be called again with the same options to ' +
398
+ 'return the existing instance, or getAnalytics() can be used ' +
399
+ 'to get a reference to the already-intialized instance.',
400
+ _a["already-initialized-settings" /* AnalyticsError.ALREADY_INITIALIZED_SETTINGS */] = 'Firebase Analytics has already been initialized.' +
401
+ 'settings() must be called before initializing any Analytics instance' +
402
+ 'or it will have no effect.',
403
+ _a["interop-component-reg-failed" /* AnalyticsError.INTEROP_COMPONENT_REG_FAILED */] = 'Firebase Analytics Interop Component failed to instantiate: {$reason}',
404
+ _a["invalid-analytics-context" /* AnalyticsError.INVALID_ANALYTICS_CONTEXT */] = 'Firebase Analytics is not supported in this environment. ' +
405
+ 'Wrap initialization of analytics in analytics.isSupported() ' +
406
+ 'to prevent initialization in unsupported environments. Details: {$errorInfo}',
407
+ _a["indexeddb-unavailable" /* AnalyticsError.INDEXEDDB_UNAVAILABLE */] = 'IndexedDB unavailable or restricted in this environment. ' +
408
+ 'Wrap initialization of analytics in analytics.isSupported() ' +
409
+ 'to prevent initialization in unsupported environments. Details: {$errorInfo}',
410
+ _a["fetch-throttle" /* AnalyticsError.FETCH_THROTTLE */] = 'The config fetch request timed out while in an exponential backoff state.' +
411
+ ' Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.',
412
+ _a["config-fetch-failed" /* AnalyticsError.CONFIG_FETCH_FAILED */] = 'Dynamic config fetch failed: [{$httpStatus}] {$responseMessage}',
413
+ _a["no-api-key" /* AnalyticsError.NO_API_KEY */] = 'The "apiKey" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
414
+ 'contain a valid API key.',
415
+ _a["no-app-id" /* AnalyticsError.NO_APP_ID */] = 'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
416
+ 'contain a valid app ID.',
417
+ _a["no-client-id" /* AnalyticsError.NO_CLIENT_ID */] = 'The "client_id" field is empty.',
418
+ _a["invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */] = 'Trusted Types detected an invalid gtag resource: {$gtagURL}.',
419
+ _a);
420
+ var ERROR_FACTORY = new util.ErrorFactory('analytics', 'Analytics', ERRORS);
447
421
 
448
422
  /**
449
423
  * @license
@@ -1420,7 +1394,7 @@ function setConsent(consentSettings) {
1420
1394
  }
1421
1395
 
1422
1396
  var name = "@firebase/analytics";
1423
- var version = "0.10.5-canary.9cd3c1eca";
1397
+ var version = "0.10.5-canary.f58d48cd4";
1424
1398
 
1425
1399
  /**
1426
1400
  * The Firebase Analytics Web SDK.