@firebase/analytics 0.8.4 → 0.9.0-canary.06dc1364d

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.
@@ -134,7 +134,7 @@ async function gtagOnConfig(gtagCore, initializationPromisesMap, dynamicConfigPr
134
134
  catch (e) {
135
135
  logger.error(e);
136
136
  }
137
- gtagCore("config" /* CONFIG */, measurementId, gtagParams);
137
+ gtagCore("config" /* GtagCommand.CONFIG */, measurementId, gtagParams);
138
138
  }
139
139
  /**
140
140
  * Wrapped gtag logic when gtag is called with 'event' command.
@@ -185,7 +185,7 @@ async function gtagOnEvent(gtagCore, initializationPromisesMap, dynamicConfigPro
185
185
  // promises have been resolved.
186
186
  await Promise.all(initializationPromisesToWaitFor);
187
187
  // Workaround for http://b/141370449 - third argument cannot be undefined.
188
- gtagCore("event" /* EVENT */, measurementId, gtagParams || {});
188
+ gtagCore("event" /* GtagCommand.EVENT */, measurementId, gtagParams || {});
189
189
  }
190
190
  catch (e) {
191
191
  logger.error(e);
@@ -226,21 +226,21 @@ measurementIdToAppId) {
226
226
  async function gtagWrapper(command, idOrNameOrParams, gtagParams) {
227
227
  try {
228
228
  // If event, check that relevant initialization promises have completed.
229
- if (command === "event" /* EVENT */) {
229
+ if (command === "event" /* GtagCommand.EVENT */) {
230
230
  // If EVENT, second arg must be measurementId.
231
231
  await gtagOnEvent(gtagCore, initializationPromisesMap, dynamicConfigPromisesList, idOrNameOrParams, gtagParams);
232
232
  }
233
- else if (command === "config" /* CONFIG */) {
233
+ else if (command === "config" /* GtagCommand.CONFIG */) {
234
234
  // If CONFIG, second arg must be measurementId.
235
235
  await gtagOnConfig(gtagCore, initializationPromisesMap, dynamicConfigPromisesList, measurementIdToAppId, idOrNameOrParams, gtagParams);
236
236
  }
237
- else if (command === "consent" /* CONSENT */) {
237
+ else if (command === "consent" /* GtagCommand.CONSENT */) {
238
238
  // If CONFIG, second arg must be measurementId.
239
- gtagCore("consent" /* CONSENT */, 'update', gtagParams);
239
+ gtagCore("consent" /* GtagCommand.CONSENT */, 'update', gtagParams);
240
240
  }
241
241
  else {
242
242
  // If SET, second arg must be params.
243
- gtagCore("set" /* SET */, idOrNameOrParams);
243
+ gtagCore("set" /* GtagCommand.SET */, idOrNameOrParams);
244
244
  }
245
245
  }
246
246
  catch (e) {
@@ -311,29 +311,29 @@ function findGtagScriptOnPage(dataLayerName) {
311
311
  * limitations under the License.
312
312
  */
313
313
  const ERRORS = {
314
- ["already-exists" /* ALREADY_EXISTS */]: 'A Firebase Analytics instance with the appId {$id} ' +
314
+ ["already-exists" /* AnalyticsError.ALREADY_EXISTS */]: 'A Firebase Analytics instance with the appId {$id} ' +
315
315
  ' already exists. ' +
316
316
  'Only one Firebase Analytics instance can be created for each appId.',
317
- ["already-initialized" /* ALREADY_INITIALIZED */]: 'initializeAnalytics() cannot be called again with different options than those ' +
317
+ ["already-initialized" /* AnalyticsError.ALREADY_INITIALIZED */]: 'initializeAnalytics() cannot be called again with different options than those ' +
318
318
  'it was initially called with. It can be called again with the same options to ' +
319
319
  'return the existing instance, or getAnalytics() can be used ' +
320
320
  'to get a reference to the already-intialized instance.',
321
- ["already-initialized-settings" /* ALREADY_INITIALIZED_SETTINGS */]: 'Firebase Analytics has already been initialized.' +
321
+ ["already-initialized-settings" /* AnalyticsError.ALREADY_INITIALIZED_SETTINGS */]: 'Firebase Analytics has already been initialized.' +
322
322
  'settings() must be called before initializing any Analytics instance' +
323
323
  'or it will have no effect.',
324
- ["interop-component-reg-failed" /* INTEROP_COMPONENT_REG_FAILED */]: 'Firebase Analytics Interop Component failed to instantiate: {$reason}',
325
- ["invalid-analytics-context" /* INVALID_ANALYTICS_CONTEXT */]: 'Firebase Analytics is not supported in this environment. ' +
324
+ ["interop-component-reg-failed" /* AnalyticsError.INTEROP_COMPONENT_REG_FAILED */]: 'Firebase Analytics Interop Component failed to instantiate: {$reason}',
325
+ ["invalid-analytics-context" /* AnalyticsError.INVALID_ANALYTICS_CONTEXT */]: 'Firebase Analytics is not supported in this environment. ' +
326
326
  'Wrap initialization of analytics in analytics.isSupported() ' +
327
327
  'to prevent initialization in unsupported environments. Details: {$errorInfo}',
328
- ["indexeddb-unavailable" /* INDEXEDDB_UNAVAILABLE */]: 'IndexedDB unavailable or restricted in this environment. ' +
328
+ ["indexeddb-unavailable" /* AnalyticsError.INDEXEDDB_UNAVAILABLE */]: 'IndexedDB unavailable or restricted in this environment. ' +
329
329
  'Wrap initialization of analytics in analytics.isSupported() ' +
330
330
  'to prevent initialization in unsupported environments. Details: {$errorInfo}',
331
- ["fetch-throttle" /* FETCH_THROTTLE */]: 'The config fetch request timed out while in an exponential backoff state.' +
331
+ ["fetch-throttle" /* AnalyticsError.FETCH_THROTTLE */]: 'The config fetch request timed out while in an exponential backoff state.' +
332
332
  ' Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.',
333
- ["config-fetch-failed" /* CONFIG_FETCH_FAILED */]: 'Dynamic config fetch failed: [{$httpStatus}] {$responseMessage}',
334
- ["no-api-key" /* NO_API_KEY */]: 'The "apiKey" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
333
+ ["config-fetch-failed" /* AnalyticsError.CONFIG_FETCH_FAILED */]: 'Dynamic config fetch failed: [{$httpStatus}] {$responseMessage}',
334
+ ["no-api-key" /* AnalyticsError.NO_API_KEY */]: 'The "apiKey" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
335
335
  'contain a valid API key.',
336
- ["no-app-id" /* NO_APP_ID */]: 'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
336
+ ["no-app-id" /* AnalyticsError.NO_APP_ID */]: 'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
337
337
  'contain a valid app ID.'
338
338
  };
339
339
  const ERROR_FACTORY = new ErrorFactory('analytics', 'Analytics', ERRORS);
@@ -417,7 +417,7 @@ async function fetchDynamicConfig(appFields) {
417
417
  }
418
418
  }
419
419
  catch (_ignored) { }
420
- throw ERROR_FACTORY.create("config-fetch-failed" /* CONFIG_FETCH_FAILED */, {
420
+ throw ERROR_FACTORY.create("config-fetch-failed" /* AnalyticsError.CONFIG_FETCH_FAILED */, {
421
421
  httpStatus: response.status,
422
422
  responseMessage: errorMessage
423
423
  });
@@ -433,7 +433,7 @@ async function fetchDynamicConfigWithRetry(app,
433
433
  retryData = defaultRetryData, timeoutMillis) {
434
434
  const { appId, apiKey, measurementId } = app.options;
435
435
  if (!appId) {
436
- throw ERROR_FACTORY.create("no-app-id" /* NO_APP_ID */);
436
+ throw ERROR_FACTORY.create("no-app-id" /* AnalyticsError.NO_APP_ID */);
437
437
  }
438
438
  if (!apiKey) {
439
439
  if (measurementId) {
@@ -442,7 +442,7 @@ retryData = defaultRetryData, timeoutMillis) {
442
442
  appId
443
443
  };
444
444
  }
445
- throw ERROR_FACTORY.create("no-api-key" /* NO_API_KEY */);
445
+ throw ERROR_FACTORY.create("no-api-key" /* AnalyticsError.NO_API_KEY */);
446
446
  }
447
447
  const throttleMetadata = retryData.getThrottleMetadata(appId) || {
448
448
  backoffCount: 0,
@@ -463,7 +463,7 @@ retryData = defaultRetryData, timeoutMillis) {
463
463
  */
464
464
  async function attemptFetchDynamicConfigWithRetry(appFields, { throttleEndTimeMillis, backoffCount }, signal, retryData = defaultRetryData // for testing
465
465
  ) {
466
- var _a, _b;
466
+ var _a;
467
467
  const { appId, measurementId } = appFields;
468
468
  // Starts with a (potentially zero) timeout to support resumption from stored state.
469
469
  // Ensures the throttle end time is honored if the last attempt timed out.
@@ -475,7 +475,7 @@ async function attemptFetchDynamicConfigWithRetry(appFields, { throttleEndTimeMi
475
475
  if (measurementId) {
476
476
  logger.warn(`Timed out fetching this Firebase app's measurement ID from the server.` +
477
477
  ` Falling back to the measurement ID ${measurementId}` +
478
- ` provided in the "measurementId" field in the local Firebase config. [${(_a = e) === null || _a === void 0 ? void 0 : _a.message}]`);
478
+ ` provided in the "measurementId" field in the local Firebase config. [${e === null || e === void 0 ? void 0 : e.message}]`);
479
479
  return { appId, measurementId };
480
480
  }
481
481
  throw e;
@@ -500,7 +500,7 @@ async function attemptFetchDynamicConfigWithRetry(appFields, { throttleEndTimeMi
500
500
  throw e;
501
501
  }
502
502
  }
503
- const backoffMillis = Number((_b = error === null || error === void 0 ? void 0 : error.customData) === null || _b === void 0 ? void 0 : _b.httpStatus) === 503
503
+ const backoffMillis = Number((_a = error === null || error === void 0 ? void 0 : error.customData) === null || _a === void 0 ? void 0 : _a.httpStatus) === 503
504
504
  ? calculateBackoffMillis(backoffCount, retryData.intervalMillis, LONG_RETRY_FACTOR)
505
505
  : calculateBackoffMillis(backoffCount, retryData.intervalMillis);
506
506
  // Increments backoff state.
@@ -535,7 +535,7 @@ function setAbortableTimeout(signal, throttleEndTimeMillis) {
535
535
  signal.addEventListener(() => {
536
536
  clearTimeout(timeout);
537
537
  // If the request completes before this timeout, the rejection has no effect.
538
- reject(ERROR_FACTORY.create("fetch-throttle" /* FETCH_THROTTLE */, {
538
+ reject(ERROR_FACTORY.create("fetch-throttle" /* AnalyticsError.FETCH_THROTTLE */, {
539
539
  throttleEndTimeMillis
540
540
  }));
541
541
  });
@@ -604,13 +604,13 @@ let defaultEventParametersForInit;
604
604
  */
605
605
  async function logEvent$1(gtagFunction, initializationPromise, eventName, eventParams, options) {
606
606
  if (options && options.global) {
607
- gtagFunction("event" /* EVENT */, eventName, eventParams);
607
+ gtagFunction("event" /* GtagCommand.EVENT */, eventName, eventParams);
608
608
  return;
609
609
  }
610
610
  else {
611
611
  const measurementId = await initializationPromise;
612
612
  const params = Object.assign(Object.assign({}, eventParams), { 'send_to': measurementId });
613
- gtagFunction("event" /* EVENT */, eventName, params);
613
+ gtagFunction("event" /* GtagCommand.EVENT */, eventName, params);
614
614
  }
615
615
  }
616
616
  /**
@@ -624,12 +624,12 @@ async function logEvent$1(gtagFunction, initializationPromise, eventName, eventP
624
624
  */
625
625
  async function setCurrentScreen$1(gtagFunction, initializationPromise, screenName, options) {
626
626
  if (options && options.global) {
627
- gtagFunction("set" /* SET */, { 'screen_name': screenName });
627
+ gtagFunction("set" /* GtagCommand.SET */, { 'screen_name': screenName });
628
628
  return Promise.resolve();
629
629
  }
630
630
  else {
631
631
  const measurementId = await initializationPromise;
632
- gtagFunction("config" /* CONFIG */, measurementId, {
632
+ gtagFunction("config" /* GtagCommand.CONFIG */, measurementId, {
633
633
  update: true,
634
634
  'screen_name': screenName
635
635
  });
@@ -643,12 +643,12 @@ async function setCurrentScreen$1(gtagFunction, initializationPromise, screenNam
643
643
  */
644
644
  async function setUserId$1(gtagFunction, initializationPromise, id, options) {
645
645
  if (options && options.global) {
646
- gtagFunction("set" /* SET */, { 'user_id': id });
646
+ gtagFunction("set" /* GtagCommand.SET */, { 'user_id': id });
647
647
  return Promise.resolve();
648
648
  }
649
649
  else {
650
650
  const measurementId = await initializationPromise;
651
- gtagFunction("config" /* CONFIG */, measurementId, {
651
+ gtagFunction("config" /* GtagCommand.CONFIG */, measurementId, {
652
652
  update: true,
653
653
  'user_id': id
654
654
  });
@@ -667,12 +667,12 @@ async function setUserProperties$1(gtagFunction, initializationPromise, properti
667
667
  // use dot notation for merge behavior in gtag.js
668
668
  flatProperties[`user_properties.${key}`] = properties[key];
669
669
  }
670
- gtagFunction("set" /* SET */, flatProperties);
670
+ gtagFunction("set" /* GtagCommand.SET */, flatProperties);
671
671
  return Promise.resolve();
672
672
  }
673
673
  else {
674
674
  const measurementId = await initializationPromise;
675
- gtagFunction("config" /* CONFIG */, measurementId, {
675
+ gtagFunction("config" /* GtagCommand.CONFIG */, measurementId, {
676
676
  update: true,
677
677
  'user_properties': properties
678
678
  });
@@ -727,9 +727,8 @@ function _setDefaultEventParametersForInit(customParams) {
727
727
  * limitations under the License.
728
728
  */
729
729
  async function validateIndexedDB() {
730
- var _a;
731
730
  if (!isIndexedDBAvailable()) {
732
- logger.warn(ERROR_FACTORY.create("indexeddb-unavailable" /* INDEXEDDB_UNAVAILABLE */, {
731
+ logger.warn(ERROR_FACTORY.create("indexeddb-unavailable" /* AnalyticsError.INDEXEDDB_UNAVAILABLE */, {
733
732
  errorInfo: 'IndexedDB is not available in this environment.'
734
733
  }).message);
735
734
  return false;
@@ -739,8 +738,8 @@ async function validateIndexedDB() {
739
738
  await validateIndexedDBOpenable();
740
739
  }
741
740
  catch (e) {
742
- logger.warn(ERROR_FACTORY.create("indexeddb-unavailable" /* INDEXEDDB_UNAVAILABLE */, {
743
- errorInfo: (_a = e) === null || _a === void 0 ? void 0 : _a.toString()
741
+ logger.warn(ERROR_FACTORY.create("indexeddb-unavailable" /* AnalyticsError.INDEXEDDB_UNAVAILABLE */, {
742
+ errorInfo: e === null || e === void 0 ? void 0 : e.toString()
744
743
  }).message);
745
744
  return false;
746
745
  }
@@ -798,7 +797,7 @@ async function _initializeAnalytics(app, dynamicConfigPromisesList, measurementI
798
797
  }
799
798
  // Detects if there are consent settings that need to be configured.
800
799
  if (defaultConsentSettingsForInit) {
801
- gtagCore("consent" /* CONSENT */, 'default', defaultConsentSettingsForInit);
800
+ gtagCore("consent" /* GtagCommand.CONSENT */, 'default', defaultConsentSettingsForInit);
802
801
  _setConsentDefaultForInit(undefined);
803
802
  }
804
803
  // This command initializes gtag.js and only needs to be called once for the entire web app,
@@ -819,10 +818,10 @@ async function _initializeAnalytics(app, dynamicConfigPromisesList, measurementI
819
818
  // Initialize this GA-ID and set FID on it using the gtag config API.
820
819
  // Note: This will trigger a page_view event unless 'send_page_view' is set to false in
821
820
  // `configProperties`.
822
- gtagCore("config" /* CONFIG */, dynamicConfig.measurementId, configProperties);
821
+ gtagCore("config" /* GtagCommand.CONFIG */, dynamicConfig.measurementId, configProperties);
823
822
  // Detects if there is data that will be set on every event logged from the SDK.
824
823
  if (defaultEventParametersForInit) {
825
- gtagCore("set" /* SET */, defaultEventParametersForInit);
824
+ gtagCore("set" /* GtagCommand.SET */, defaultEventParametersForInit);
826
825
  _setDefaultEventParametersForInit(undefined);
827
826
  }
828
827
  return dynamicConfig.measurementId;
@@ -912,7 +911,7 @@ let globalInitDone = false;
912
911
  */
913
912
  function settings(options) {
914
913
  if (globalInitDone) {
915
- throw ERROR_FACTORY.create("already-initialized" /* ALREADY_INITIALIZED */);
914
+ throw ERROR_FACTORY.create("already-initialized" /* AnalyticsError.ALREADY_INITIALIZED */);
916
915
  }
917
916
  if (options.dataLayerName) {
918
917
  dataLayerName = options.dataLayerName;
@@ -938,7 +937,7 @@ function warnOnBrowserContextMismatch() {
938
937
  const details = mismatchedEnvMessages
939
938
  .map((message, index) => `(${index + 1}) ${message}`)
940
939
  .join(' ');
941
- const err = ERROR_FACTORY.create("invalid-analytics-context" /* INVALID_ANALYTICS_CONTEXT */, {
940
+ const err = ERROR_FACTORY.create("invalid-analytics-context" /* AnalyticsError.INVALID_ANALYTICS_CONTEXT */, {
942
941
  errorInfo: details
943
942
  });
944
943
  logger.warn(err.message);
@@ -952,7 +951,7 @@ function factory(app, installations, options) {
952
951
  warnOnBrowserContextMismatch();
953
952
  const appId = app.options.appId;
954
953
  if (!appId) {
955
- throw ERROR_FACTORY.create("no-app-id" /* NO_APP_ID */);
954
+ throw ERROR_FACTORY.create("no-app-id" /* AnalyticsError.NO_APP_ID */);
956
955
  }
957
956
  if (!app.options.apiKey) {
958
957
  if (app.options.measurementId) {
@@ -961,11 +960,11 @@ function factory(app, installations, options) {
961
960
  ` provided in the "measurementId" field in the local Firebase config.`);
962
961
  }
963
962
  else {
964
- throw ERROR_FACTORY.create("no-api-key" /* NO_API_KEY */);
963
+ throw ERROR_FACTORY.create("no-api-key" /* AnalyticsError.NO_API_KEY */);
965
964
  }
966
965
  }
967
966
  if (initializationPromisesMap[appId] != null) {
968
- throw ERROR_FACTORY.create("already-exists" /* ALREADY_EXISTS */, {
967
+ throw ERROR_FACTORY.create("already-exists" /* AnalyticsError.ALREADY_EXISTS */, {
969
968
  id: appId
970
969
  });
971
970
  }
@@ -1018,7 +1017,7 @@ function initializeAnalytics(app, options = {}) {
1018
1017
  return existingInstance;
1019
1018
  }
1020
1019
  else {
1021
- throw ERROR_FACTORY.create("already-initialized" /* ALREADY_INITIALIZED */);
1020
+ throw ERROR_FACTORY.create("already-initialized" /* AnalyticsError.ALREADY_INITIALIZED */);
1022
1021
  }
1023
1022
  }
1024
1023
  const analyticsInstance = analyticsProvider.initialize({ options });
@@ -1112,7 +1111,7 @@ function setAnalyticsCollectionEnabled(analyticsInstance, enabled) {
1112
1111
  function setDefaultEventParameters(customParams) {
1113
1112
  // Check if reference to existing gtag function on window object exists
1114
1113
  if (wrappedGtagFunction) {
1115
- wrappedGtagFunction("set" /* SET */, customParams);
1114
+ wrappedGtagFunction("set" /* GtagCommand.SET */, customParams);
1116
1115
  }
1117
1116
  else {
1118
1117
  _setDefaultEventParametersForInit(customParams);
@@ -1145,7 +1144,7 @@ function logEvent(analyticsInstance, eventName, eventParams, options) {
1145
1144
  function setConsent(consentSettings) {
1146
1145
  // Check if reference to existing gtag function on window object exists
1147
1146
  if (wrappedGtagFunction) {
1148
- wrappedGtagFunction("consent" /* CONSENT */, 'update', consentSettings);
1147
+ wrappedGtagFunction("consent" /* GtagCommand.CONSENT */, 'update', consentSettings);
1149
1148
  }
1150
1149
  else {
1151
1150
  _setConsentDefaultForInit(consentSettings);
@@ -1153,7 +1152,7 @@ function setConsent(consentSettings) {
1153
1152
  }
1154
1153
 
1155
1154
  const name = "@firebase/analytics";
1156
- const version = "0.8.4";
1155
+ const version = "0.9.0-canary.06dc1364d";
1157
1156
 
1158
1157
  /**
1159
1158
  * Firebase Analytics
@@ -1168,8 +1167,8 @@ function registerAnalytics() {
1168
1167
  .getProvider('installations-internal')
1169
1168
  .getImmediate();
1170
1169
  return factory(app, installations, analyticsOptions);
1171
- }, "PUBLIC" /* PUBLIC */));
1172
- _registerComponent(new Component('analytics-internal', internalFactory, "PRIVATE" /* PRIVATE */));
1170
+ }, "PUBLIC" /* ComponentType.PUBLIC */));
1171
+ _registerComponent(new Component('analytics-internal', internalFactory, "PRIVATE" /* ComponentType.PRIVATE */));
1173
1172
  registerVersion(name, version);
1174
1173
  // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
1175
1174
  registerVersion(name, version, 'esm2017');
@@ -1181,7 +1180,7 @@ function registerAnalytics() {
1181
1180
  };
1182
1181
  }
1183
1182
  catch (e) {
1184
- throw ERROR_FACTORY.create("interop-component-reg-failed" /* INTEROP_COMPONENT_REG_FAILED */, {
1183
+ throw ERROR_FACTORY.create("interop-component-reg-failed" /* AnalyticsError.INTEROP_COMPONENT_REG_FAILED */, {
1185
1184
  reason: e
1186
1185
  });
1187
1186
  }