@firebase/analytics 0.9.4 → 0.9.5-canary.a8d6499b1
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/CHANGELOG.md +6 -0
- package/dist/esm/index.esm.js +83 -47
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/index.esm2017.js +82 -46
- package/dist/esm/index.esm2017.js.map +1 -1
- package/dist/esm/src/errors.d.ts +5 -1
- package/dist/esm/src/helpers.d.ts +13 -0
- package/dist/index.cjs.js +83 -47
- package/dist/index.cjs.js.map +1 -1
- package/dist/src/errors.d.ts +5 -1
- package/dist/src/helpers.d.ts +13 -0
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @firebase/analytics
|
|
2
2
|
|
|
3
|
+
## 0.9.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`3435ba945`](https://github.com/firebase/firebase-js-sdk/commit/3435ba945a9febf5a0aece05517a5656f58b246f) [#7155](https://github.com/firebase/firebase-js-sdk/pull/7155) (fixes [#7048](https://github.com/firebase/firebase-js-sdk/issues/7048)) - Use the Trusted Types API when composing the gtag URL.
|
|
8
|
+
|
|
3
9
|
## 0.9.4
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/esm/index.esm.js
CHANGED
|
@@ -66,6 +66,65 @@ var logger = new Logger('@firebase/analytics');
|
|
|
66
66
|
* See the License for the specific language governing permissions and
|
|
67
67
|
* limitations under the License.
|
|
68
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-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["invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */] = 'Trusted Types detected an invalid gtag resource: {$gtagURL}.',
|
|
96
|
+
_a);
|
|
97
|
+
var ERROR_FACTORY = new ErrorFactory('analytics', 'Analytics', ERRORS);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @license
|
|
101
|
+
* Copyright 2019 Google LLC
|
|
102
|
+
*
|
|
103
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
104
|
+
* you may not use this file except in compliance with the License.
|
|
105
|
+
* You may obtain a copy of the License at
|
|
106
|
+
*
|
|
107
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
108
|
+
*
|
|
109
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
110
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
111
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
112
|
+
* See the License for the specific language governing permissions and
|
|
113
|
+
* limitations under the License.
|
|
114
|
+
*/
|
|
115
|
+
/**
|
|
116
|
+
* Verifies and creates a TrustedScriptURL.
|
|
117
|
+
*/
|
|
118
|
+
function createGtagTrustedTypesScriptURL(url) {
|
|
119
|
+
if (!url.startsWith(GTAG_URL)) {
|
|
120
|
+
var err = ERROR_FACTORY.create("invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */, {
|
|
121
|
+
gtagURL: url
|
|
122
|
+
});
|
|
123
|
+
logger.warn(err.message);
|
|
124
|
+
return '';
|
|
125
|
+
}
|
|
126
|
+
return url;
|
|
127
|
+
}
|
|
69
128
|
/**
|
|
70
129
|
* Makeshift polyfill for Promise.allSettled(). Resolves when all promises
|
|
71
130
|
* have either resolved or rejected.
|
|
@@ -75,15 +134,37 @@ var logger = new Logger('@firebase/analytics');
|
|
|
75
134
|
function promiseAllSettled(promises) {
|
|
76
135
|
return Promise.all(promises.map(function (promise) { return promise.catch(function (e) { return e; }); }));
|
|
77
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Creates a TrustedTypePolicy object that implements the rules passed as policyOptions.
|
|
139
|
+
*
|
|
140
|
+
* @param policyName A string containing the name of the policy
|
|
141
|
+
* @param policyOptions Object containing implementations of instance methods for TrustedTypesPolicy, see {@link https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicy#instance_methods
|
|
142
|
+
* | the TrustedTypePolicy reference documentation}.
|
|
143
|
+
*/
|
|
144
|
+
function createTrustedTypesPolicy(policyName, policyOptions) {
|
|
145
|
+
// Create a TrustedTypes policy that we can use for updating src
|
|
146
|
+
// properties
|
|
147
|
+
var trustedTypesPolicy;
|
|
148
|
+
if (window.trustedTypes) {
|
|
149
|
+
trustedTypesPolicy = window.trustedTypes.createPolicy(policyName, policyOptions);
|
|
150
|
+
}
|
|
151
|
+
return trustedTypesPolicy;
|
|
152
|
+
}
|
|
78
153
|
/**
|
|
79
154
|
* Inserts gtag script tag into the page to asynchronously download gtag.
|
|
80
155
|
* @param dataLayerName Name of datalayer (most often the default, "_dataLayer").
|
|
81
156
|
*/
|
|
82
157
|
function insertScriptTag(dataLayerName, measurementId) {
|
|
158
|
+
var trustedTypesPolicy = createTrustedTypesPolicy('firebase-js-sdk-policy', {
|
|
159
|
+
createScriptURL: createGtagTrustedTypesScriptURL
|
|
160
|
+
});
|
|
83
161
|
var script = document.createElement('script');
|
|
84
162
|
// We are not providing an analyticsId in the URL because it would trigger a `page_view`
|
|
85
163
|
// without fid. We will initialize ga-id using gtag (config) command together with fid.
|
|
86
|
-
|
|
164
|
+
var gtagScriptURL = "".concat(GTAG_URL, "?l=").concat(dataLayerName, "&id=").concat(measurementId);
|
|
165
|
+
script.src = trustedTypesPolicy
|
|
166
|
+
? trustedTypesPolicy === null || trustedTypesPolicy === void 0 ? void 0 : trustedTypesPolicy.createScriptURL(gtagScriptURL)
|
|
167
|
+
: gtagScriptURL;
|
|
87
168
|
script.async = true;
|
|
88
169
|
document.head.appendChild(script);
|
|
89
170
|
}
|
|
@@ -344,51 +425,6 @@ function findGtagScriptOnPage(dataLayerName) {
|
|
|
344
425
|
return null;
|
|
345
426
|
}
|
|
346
427
|
|
|
347
|
-
/**
|
|
348
|
-
* @license
|
|
349
|
-
* Copyright 2019 Google LLC
|
|
350
|
-
*
|
|
351
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
352
|
-
* you may not use this file except in compliance with the License.
|
|
353
|
-
* You may obtain a copy of the License at
|
|
354
|
-
*
|
|
355
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
356
|
-
*
|
|
357
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
358
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
359
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
360
|
-
* See the License for the specific language governing permissions and
|
|
361
|
-
* limitations under the License.
|
|
362
|
-
*/
|
|
363
|
-
var _a;
|
|
364
|
-
var ERRORS = (_a = {},
|
|
365
|
-
_a["already-exists" /* AnalyticsError.ALREADY_EXISTS */] = 'A Firebase Analytics instance with the appId {$id} ' +
|
|
366
|
-
' already exists. ' +
|
|
367
|
-
'Only one Firebase Analytics instance can be created for each appId.',
|
|
368
|
-
_a["already-initialized" /* AnalyticsError.ALREADY_INITIALIZED */] = 'initializeAnalytics() cannot be called again with different options than those ' +
|
|
369
|
-
'it was initially called with. It can be called again with the same options to ' +
|
|
370
|
-
'return the existing instance, or getAnalytics() can be used ' +
|
|
371
|
-
'to get a reference to the already-intialized instance.',
|
|
372
|
-
_a["already-initialized-settings" /* AnalyticsError.ALREADY_INITIALIZED_SETTINGS */] = 'Firebase Analytics has already been initialized.' +
|
|
373
|
-
'settings() must be called before initializing any Analytics instance' +
|
|
374
|
-
'or it will have no effect.',
|
|
375
|
-
_a["interop-component-reg-failed" /* AnalyticsError.INTEROP_COMPONENT_REG_FAILED */] = 'Firebase Analytics Interop Component failed to instantiate: {$reason}',
|
|
376
|
-
_a["invalid-analytics-context" /* AnalyticsError.INVALID_ANALYTICS_CONTEXT */] = 'Firebase Analytics is not supported in this environment. ' +
|
|
377
|
-
'Wrap initialization of analytics in analytics.isSupported() ' +
|
|
378
|
-
'to prevent initialization in unsupported environments. Details: {$errorInfo}',
|
|
379
|
-
_a["indexeddb-unavailable" /* AnalyticsError.INDEXEDDB_UNAVAILABLE */] = 'IndexedDB unavailable or restricted in this environment. ' +
|
|
380
|
-
'Wrap initialization of analytics in analytics.isSupported() ' +
|
|
381
|
-
'to prevent initialization in unsupported environments. Details: {$errorInfo}',
|
|
382
|
-
_a["fetch-throttle" /* AnalyticsError.FETCH_THROTTLE */] = 'The config fetch request timed out while in an exponential backoff state.' +
|
|
383
|
-
' Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.',
|
|
384
|
-
_a["config-fetch-failed" /* AnalyticsError.CONFIG_FETCH_FAILED */] = 'Dynamic config fetch failed: [{$httpStatus}] {$responseMessage}',
|
|
385
|
-
_a["no-api-key" /* AnalyticsError.NO_API_KEY */] = 'The "apiKey" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
|
|
386
|
-
'contain a valid API key.',
|
|
387
|
-
_a["no-app-id" /* AnalyticsError.NO_APP_ID */] = 'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
|
|
388
|
-
'contain a valid app ID.',
|
|
389
|
-
_a);
|
|
390
|
-
var ERROR_FACTORY = new ErrorFactory('analytics', 'Analytics', ERRORS);
|
|
391
|
-
|
|
392
428
|
/**
|
|
393
429
|
* @license
|
|
394
430
|
* Copyright 2020 Google LLC
|
|
@@ -1322,7 +1358,7 @@ function setConsent(consentSettings) {
|
|
|
1322
1358
|
}
|
|
1323
1359
|
|
|
1324
1360
|
var name = "@firebase/analytics";
|
|
1325
|
-
var version = "0.9.
|
|
1361
|
+
var version = "0.9.5-canary.a8d6499b1";
|
|
1326
1362
|
|
|
1327
1363
|
/**
|
|
1328
1364
|
* Firebase Analytics
|