@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/esm/index.esm.js +86 -60
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/index.esm2017.js +83 -56
- package/dist/esm/index.esm2017.js.map +1 -1
- package/dist/esm/src/helpers.d.ts +13 -0
- package/dist/index.cjs.js +85 -59
- package/dist/index.cjs.js.map +1 -1
- package/dist/src/helpers.d.ts +13 -0
- package/package.json +9 -10
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { _getProvider, getApp, _registerComponent, registerVersion } from '@firebase/app';
|
|
2
2
|
import { Logger } from '@firebase/logger';
|
|
3
|
-
import { trustedResourceUrl } from 'safevalues';
|
|
4
|
-
import { safeScriptEl } from 'safevalues/dom';
|
|
5
3
|
import { ErrorFactory, calculateBackoffMillis, FirebaseError, isIndexedDBAvailable, validateIndexedDBOpenable, isBrowserExtension, areCookiesEnabled, getModularInstance, deepEqual } from '@firebase/util';
|
|
6
4
|
import { Component } from '@firebase/component';
|
|
7
5
|
import '@firebase/installations';
|
|
@@ -67,6 +65,65 @@ const logger = new Logger('@firebase/analytics');
|
|
|
67
65
|
* See the License for the specific language governing permissions and
|
|
68
66
|
* limitations under the License.
|
|
69
67
|
*/
|
|
68
|
+
const ERRORS = {
|
|
69
|
+
["already-exists" /* AnalyticsError.ALREADY_EXISTS */]: 'A Firebase Analytics instance with the appId {$id} ' +
|
|
70
|
+
' already exists. ' +
|
|
71
|
+
'Only one Firebase Analytics instance can be created for each appId.',
|
|
72
|
+
["already-initialized" /* AnalyticsError.ALREADY_INITIALIZED */]: 'initializeAnalytics() cannot be called again with different options than those ' +
|
|
73
|
+
'it was initially called with. It can be called again with the same options to ' +
|
|
74
|
+
'return the existing instance, or getAnalytics() can be used ' +
|
|
75
|
+
'to get a reference to the already-initialized instance.',
|
|
76
|
+
["already-initialized-settings" /* AnalyticsError.ALREADY_INITIALIZED_SETTINGS */]: 'Firebase Analytics has already been initialized.' +
|
|
77
|
+
'settings() must be called before initializing any Analytics instance' +
|
|
78
|
+
'or it will have no effect.',
|
|
79
|
+
["interop-component-reg-failed" /* AnalyticsError.INTEROP_COMPONENT_REG_FAILED */]: 'Firebase Analytics Interop Component failed to instantiate: {$reason}',
|
|
80
|
+
["invalid-analytics-context" /* AnalyticsError.INVALID_ANALYTICS_CONTEXT */]: 'Firebase Analytics is not supported in this environment. ' +
|
|
81
|
+
'Wrap initialization of analytics in analytics.isSupported() ' +
|
|
82
|
+
'to prevent initialization in unsupported environments. Details: {$errorInfo}',
|
|
83
|
+
["indexeddb-unavailable" /* AnalyticsError.INDEXEDDB_UNAVAILABLE */]: 'IndexedDB unavailable or restricted in this environment. ' +
|
|
84
|
+
'Wrap initialization of analytics in analytics.isSupported() ' +
|
|
85
|
+
'to prevent initialization in unsupported environments. Details: {$errorInfo}',
|
|
86
|
+
["fetch-throttle" /* AnalyticsError.FETCH_THROTTLE */]: 'The config fetch request timed out while in an exponential backoff state.' +
|
|
87
|
+
' Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.',
|
|
88
|
+
["config-fetch-failed" /* AnalyticsError.CONFIG_FETCH_FAILED */]: 'Dynamic config fetch failed: [{$httpStatus}] {$responseMessage}',
|
|
89
|
+
["no-api-key" /* AnalyticsError.NO_API_KEY */]: 'The "apiKey" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
|
|
90
|
+
'contain a valid API key.',
|
|
91
|
+
["no-app-id" /* AnalyticsError.NO_APP_ID */]: 'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
|
|
92
|
+
'contain a valid app ID.',
|
|
93
|
+
["no-client-id" /* AnalyticsError.NO_CLIENT_ID */]: 'The "client_id" field is empty.',
|
|
94
|
+
["invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */]: 'Trusted Types detected an invalid gtag resource: {$gtagURL}.'
|
|
95
|
+
};
|
|
96
|
+
const ERROR_FACTORY = new ErrorFactory('analytics', 'Analytics', ERRORS);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @license
|
|
100
|
+
* Copyright 2019 Google LLC
|
|
101
|
+
*
|
|
102
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
103
|
+
* you may not use this file except in compliance with the License.
|
|
104
|
+
* You may obtain a copy of the License at
|
|
105
|
+
*
|
|
106
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
107
|
+
*
|
|
108
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
109
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
110
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
111
|
+
* See the License for the specific language governing permissions and
|
|
112
|
+
* limitations under the License.
|
|
113
|
+
*/
|
|
114
|
+
/**
|
|
115
|
+
* Verifies and creates a TrustedScriptURL.
|
|
116
|
+
*/
|
|
117
|
+
function createGtagTrustedTypesScriptURL(url) {
|
|
118
|
+
if (!url.startsWith(GTAG_URL)) {
|
|
119
|
+
const err = ERROR_FACTORY.create("invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */, {
|
|
120
|
+
gtagURL: url
|
|
121
|
+
});
|
|
122
|
+
logger.warn(err.message);
|
|
123
|
+
return '';
|
|
124
|
+
}
|
|
125
|
+
return url;
|
|
126
|
+
}
|
|
70
127
|
/**
|
|
71
128
|
* Makeshift polyfill for Promise.allSettled(). Resolves when all promises
|
|
72
129
|
* have either resolved or rejected.
|
|
@@ -76,21 +133,37 @@ const logger = new Logger('@firebase/analytics');
|
|
|
76
133
|
function promiseAllSettled(promises) {
|
|
77
134
|
return Promise.all(promises.map(promise => promise.catch(e => e)));
|
|
78
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Creates a TrustedTypePolicy object that implements the rules passed as policyOptions.
|
|
138
|
+
*
|
|
139
|
+
* @param policyName A string containing the name of the policy
|
|
140
|
+
* @param policyOptions Object containing implementations of instance methods for TrustedTypesPolicy, see {@link https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicy#instance_methods
|
|
141
|
+
* | the TrustedTypePolicy reference documentation}.
|
|
142
|
+
*/
|
|
143
|
+
function createTrustedTypesPolicy(policyName, policyOptions) {
|
|
144
|
+
// Create a TrustedTypes policy that we can use for updating src
|
|
145
|
+
// properties
|
|
146
|
+
let trustedTypesPolicy;
|
|
147
|
+
if (window.trustedTypes) {
|
|
148
|
+
trustedTypesPolicy = window.trustedTypes.createPolicy(policyName, policyOptions);
|
|
149
|
+
}
|
|
150
|
+
return trustedTypesPolicy;
|
|
151
|
+
}
|
|
79
152
|
/**
|
|
80
153
|
* Inserts gtag script tag into the page to asynchronously download gtag.
|
|
81
154
|
* @param dataLayerName Name of datalayer (most often the default, "_dataLayer").
|
|
82
155
|
*/
|
|
83
156
|
function insertScriptTag(dataLayerName, measurementId) {
|
|
157
|
+
const trustedTypesPolicy = createTrustedTypesPolicy('firebase-js-sdk-policy', {
|
|
158
|
+
createScriptURL: createGtagTrustedTypesScriptURL
|
|
159
|
+
});
|
|
84
160
|
const script = document.createElement('script');
|
|
85
161
|
// We are not providing an analyticsId in the URL because it would trigger a `page_view`
|
|
86
162
|
// without fid. We will initialize ga-id using gtag (config) command together with fid.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// empty initial string.
|
|
92
|
-
const url = trustedResourceUrl `https://www.googletagmanager.com/gtag/js?l=${dataLayerName}&id=${measurementId}`;
|
|
93
|
-
safeScriptEl.setSrc(script, url);
|
|
163
|
+
const gtagScriptURL = `${GTAG_URL}?l=${dataLayerName}&id=${measurementId}`;
|
|
164
|
+
script.src = trustedTypesPolicy
|
|
165
|
+
? trustedTypesPolicy === null || trustedTypesPolicy === void 0 ? void 0 : trustedTypesPolicy.createScriptURL(gtagScriptURL)
|
|
166
|
+
: gtagScriptURL;
|
|
94
167
|
script.async = true;
|
|
95
168
|
document.head.appendChild(script);
|
|
96
169
|
}
|
|
@@ -314,52 +387,6 @@ function findGtagScriptOnPage(dataLayerName) {
|
|
|
314
387
|
return null;
|
|
315
388
|
}
|
|
316
389
|
|
|
317
|
-
/**
|
|
318
|
-
* @license
|
|
319
|
-
* Copyright 2019 Google LLC
|
|
320
|
-
*
|
|
321
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
322
|
-
* you may not use this file except in compliance with the License.
|
|
323
|
-
* You may obtain a copy of the License at
|
|
324
|
-
*
|
|
325
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
326
|
-
*
|
|
327
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
328
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
329
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
330
|
-
* See the License for the specific language governing permissions and
|
|
331
|
-
* limitations under the License.
|
|
332
|
-
*/
|
|
333
|
-
const ERRORS = {
|
|
334
|
-
["already-exists" /* AnalyticsError.ALREADY_EXISTS */]: 'A Firebase Analytics instance with the appId {$id} ' +
|
|
335
|
-
' already exists. ' +
|
|
336
|
-
'Only one Firebase Analytics instance can be created for each appId.',
|
|
337
|
-
["already-initialized" /* AnalyticsError.ALREADY_INITIALIZED */]: 'initializeAnalytics() cannot be called again with different options than those ' +
|
|
338
|
-
'it was initially called with. It can be called again with the same options to ' +
|
|
339
|
-
'return the existing instance, or getAnalytics() can be used ' +
|
|
340
|
-
'to get a reference to the already-initialized instance.',
|
|
341
|
-
["already-initialized-settings" /* AnalyticsError.ALREADY_INITIALIZED_SETTINGS */]: 'Firebase Analytics has already been initialized.' +
|
|
342
|
-
'settings() must be called before initializing any Analytics instance' +
|
|
343
|
-
'or it will have no effect.',
|
|
344
|
-
["interop-component-reg-failed" /* AnalyticsError.INTEROP_COMPONENT_REG_FAILED */]: 'Firebase Analytics Interop Component failed to instantiate: {$reason}',
|
|
345
|
-
["invalid-analytics-context" /* AnalyticsError.INVALID_ANALYTICS_CONTEXT */]: 'Firebase Analytics is not supported in this environment. ' +
|
|
346
|
-
'Wrap initialization of analytics in analytics.isSupported() ' +
|
|
347
|
-
'to prevent initialization in unsupported environments. Details: {$errorInfo}',
|
|
348
|
-
["indexeddb-unavailable" /* AnalyticsError.INDEXEDDB_UNAVAILABLE */]: 'IndexedDB unavailable or restricted in this environment. ' +
|
|
349
|
-
'Wrap initialization of analytics in analytics.isSupported() ' +
|
|
350
|
-
'to prevent initialization in unsupported environments. Details: {$errorInfo}',
|
|
351
|
-
["fetch-throttle" /* AnalyticsError.FETCH_THROTTLE */]: 'The config fetch request timed out while in an exponential backoff state.' +
|
|
352
|
-
' Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.',
|
|
353
|
-
["config-fetch-failed" /* AnalyticsError.CONFIG_FETCH_FAILED */]: 'Dynamic config fetch failed: [{$httpStatus}] {$responseMessage}',
|
|
354
|
-
["no-api-key" /* AnalyticsError.NO_API_KEY */]: 'The "apiKey" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
|
|
355
|
-
'contain a valid API key.',
|
|
356
|
-
["no-app-id" /* AnalyticsError.NO_APP_ID */]: 'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
|
|
357
|
-
'contain a valid app ID.',
|
|
358
|
-
["no-client-id" /* AnalyticsError.NO_CLIENT_ID */]: 'The "client_id" field is empty.',
|
|
359
|
-
["invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */]: 'Trusted Types detected an invalid gtag resource: {$gtagURL}.'
|
|
360
|
-
};
|
|
361
|
-
const ERROR_FACTORY = new ErrorFactory('analytics', 'Analytics', ERRORS);
|
|
362
|
-
|
|
363
390
|
/**
|
|
364
391
|
* @license
|
|
365
392
|
* Copyright 2020 Google LLC
|
|
@@ -1203,7 +1230,7 @@ function setConsent(consentSettings) {
|
|
|
1203
1230
|
}
|
|
1204
1231
|
|
|
1205
1232
|
const name = "@firebase/analytics";
|
|
1206
|
-
const version = "0.10.6-
|
|
1233
|
+
const version = "0.10.6-dataconnect-preview.d986d4bf2";
|
|
1207
1234
|
|
|
1208
1235
|
/**
|
|
1209
1236
|
* The Firebase Analytics Web SDK.
|