@firebase/analytics 0.10.6-canary.e542f1dbd → 0.10.6-dataconnect-preview.d986d4bf2

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,8 +5,6 @@ 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');
10
8
  var util = require('@firebase/util');
11
9
  var component = require('@firebase/component');
12
10
  require('@firebase/installations');
@@ -72,6 +70,66 @@ var logger = new logger$1.Logger('@firebase/analytics');
72
70
  * See the License for the specific language governing permissions and
73
71
  * limitations under the License.
74
72
  */
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-initialized 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
+ }
75
133
  /**
76
134
  * Makeshift polyfill for Promise.allSettled(). Resolves when all promises
77
135
  * have either resolved or rejected.
@@ -81,21 +139,37 @@ var logger = new logger$1.Logger('@firebase/analytics');
81
139
  function promiseAllSettled(promises) {
82
140
  return Promise.all(promises.map(function (promise) { return promise.catch(function (e) { return e; }); }));
83
141
  }
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
+ }
84
158
  /**
85
159
  * Inserts gtag script tag into the page to asynchronously download gtag.
86
160
  * @param dataLayerName Name of datalayer (most often the default, "_dataLayer").
87
161
  */
88
162
  function insertScriptTag(dataLayerName, measurementId) {
163
+ var trustedTypesPolicy = createTrustedTypesPolicy('firebase-js-sdk-policy', {
164
+ createScriptURL: createGtagTrustedTypesScriptURL
165
+ });
89
166
  var script = document.createElement('script');
90
167
  // We are not providing an analyticsId in the URL because it would trigger a `page_view`
91
168
  // without fid. We will initialize ga-id using gtag (config) command together with fid.
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);
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;
99
173
  script.async = true;
100
174
  document.head.appendChild(script);
101
175
  }
@@ -370,55 +444,7 @@ function findGtagScriptOnPage(dataLayerName) {
370
444
  }
371
445
  }
372
446
  return null;
373
- }
374
- var templateObject_1;
375
-
376
- /**
377
- * @license
378
- * Copyright 2019 Google LLC
379
- *
380
- * Licensed under the Apache License, Version 2.0 (the "License");
381
- * you may not use this file except in compliance with the License.
382
- * You may obtain a copy of the License at
383
- *
384
- * http://www.apache.org/licenses/LICENSE-2.0
385
- *
386
- * Unless required by applicable law or agreed to in writing, software
387
- * distributed under the License is distributed on an "AS IS" BASIS,
388
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
389
- * See the License for the specific language governing permissions and
390
- * limitations under the License.
391
- */
392
- var _a;
393
- var ERRORS = (_a = {},
394
- _a["already-exists" /* AnalyticsError.ALREADY_EXISTS */] = 'A Firebase Analytics instance with the appId {$id} ' +
395
- ' already exists. ' +
396
- 'Only one Firebase Analytics instance can be created for each appId.',
397
- _a["already-initialized" /* AnalyticsError.ALREADY_INITIALIZED */] = 'initializeAnalytics() cannot be called again with different options than those ' +
398
- 'it was initially called with. It can be called again with the same options to ' +
399
- 'return the existing instance, or getAnalytics() can be used ' +
400
- 'to get a reference to the already-initialized instance.',
401
- _a["already-initialized-settings" /* AnalyticsError.ALREADY_INITIALIZED_SETTINGS */] = 'Firebase Analytics has already been initialized.' +
402
- 'settings() must be called before initializing any Analytics instance' +
403
- 'or it will have no effect.',
404
- _a["interop-component-reg-failed" /* AnalyticsError.INTEROP_COMPONENT_REG_FAILED */] = 'Firebase Analytics Interop Component failed to instantiate: {$reason}',
405
- _a["invalid-analytics-context" /* AnalyticsError.INVALID_ANALYTICS_CONTEXT */] = 'Firebase Analytics is not supported in this environment. ' +
406
- 'Wrap initialization of analytics in analytics.isSupported() ' +
407
- 'to prevent initialization in unsupported environments. Details: {$errorInfo}',
408
- _a["indexeddb-unavailable" /* AnalyticsError.INDEXEDDB_UNAVAILABLE */] = 'IndexedDB unavailable or restricted in this environment. ' +
409
- 'Wrap initialization of analytics in analytics.isSupported() ' +
410
- 'to prevent initialization in unsupported environments. Details: {$errorInfo}',
411
- _a["fetch-throttle" /* AnalyticsError.FETCH_THROTTLE */] = 'The config fetch request timed out while in an exponential backoff state.' +
412
- ' Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.',
413
- _a["config-fetch-failed" /* AnalyticsError.CONFIG_FETCH_FAILED */] = 'Dynamic config fetch failed: [{$httpStatus}] {$responseMessage}',
414
- _a["no-api-key" /* AnalyticsError.NO_API_KEY */] = 'The "apiKey" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
415
- 'contain a valid API key.',
416
- _a["no-app-id" /* AnalyticsError.NO_APP_ID */] = 'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
417
- 'contain a valid app ID.',
418
- _a["no-client-id" /* AnalyticsError.NO_CLIENT_ID */] = 'The "client_id" field is empty.',
419
- _a["invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */] = 'Trusted Types detected an invalid gtag resource: {$gtagURL}.',
420
- _a);
421
- var ERROR_FACTORY = new util.ErrorFactory('analytics', 'Analytics', ERRORS);
447
+ }
422
448
 
423
449
  /**
424
450
  * @license
@@ -1395,7 +1421,7 @@ function setConsent(consentSettings) {
1395
1421
  }
1396
1422
 
1397
1423
  var name = "@firebase/analytics";
1398
- var version = "0.10.6-canary.e542f1dbd";
1424
+ var version = "0.10.6-dataconnect-preview.d986d4bf2";
1399
1425
 
1400
1426
  /**
1401
1427
  * The Firebase Analytics Web SDK.