@firebase/analytics 0.7.10 → 0.7.11-canary.69e2ee064

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.
@@ -456,6 +456,7 @@ retryData = defaultRetryData, timeoutMillis) {
456
456
  */
457
457
  async function attemptFetchDynamicConfigWithRetry(appFields, { throttleEndTimeMillis, backoffCount }, signal, retryData = defaultRetryData // for testing
458
458
  ) {
459
+ var _a, _b;
459
460
  const { appId, measurementId } = appFields;
460
461
  // Starts with a (potentially zero) timeout to support resumption from stored state.
461
462
  // Ensures the throttle end time is honored if the last attempt timed out.
@@ -467,7 +468,7 @@ async function attemptFetchDynamicConfigWithRetry(appFields, { throttleEndTimeMi
467
468
  if (measurementId) {
468
469
  logger.warn(`Timed out fetching this Firebase app's measurement ID from the server.` +
469
470
  ` Falling back to the measurement ID ${measurementId}` +
470
- ` provided in the "measurementId" field in the local Firebase config. [${e.message}]`);
471
+ ` provided in the "measurementId" field in the local Firebase config. [${(_a = e) === null || _a === void 0 ? void 0 : _a.message}]`);
471
472
  return { appId, measurementId };
472
473
  }
473
474
  throw e;
@@ -479,19 +480,20 @@ async function attemptFetchDynamicConfigWithRetry(appFields, { throttleEndTimeMi
479
480
  return response;
480
481
  }
481
482
  catch (e) {
482
- if (!isRetriableError(e)) {
483
+ const error = e;
484
+ if (!isRetriableError(error)) {
483
485
  retryData.deleteThrottleMetadata(appId);
484
486
  if (measurementId) {
485
487
  logger.warn(`Failed to fetch this Firebase app's measurement ID from the server.` +
486
488
  ` Falling back to the measurement ID ${measurementId}` +
487
- ` provided in the "measurementId" field in the local Firebase config. [${e.message}]`);
489
+ ` provided in the "measurementId" field in the local Firebase config. [${error === null || error === void 0 ? void 0 : error.message}]`);
488
490
  return { appId, measurementId };
489
491
  }
490
492
  else {
491
493
  throw e;
492
494
  }
493
495
  }
494
- const backoffMillis = Number(e.customData.httpStatus) === 503
496
+ const backoffMillis = Number((_b = error === null || error === void 0 ? void 0 : error.customData) === null || _b === void 0 ? void 0 : _b.httpStatus) === 503
495
497
  ? calculateBackoffMillis(backoffCount, retryData.intervalMillis, LONG_RETRY_FACTOR)
496
498
  : calculateBackoffMillis(backoffCount, retryData.intervalMillis);
497
499
  // Increments backoff state.
@@ -566,6 +568,128 @@ class AnalyticsAbortSignal {
566
568
  }
567
569
  }
568
570
 
571
+ /**
572
+ * @license
573
+ * Copyright 2019 Google LLC
574
+ *
575
+ * Licensed under the Apache License, Version 2.0 (the "License");
576
+ * you may not use this file except in compliance with the License.
577
+ * You may obtain a copy of the License at
578
+ *
579
+ * http://www.apache.org/licenses/LICENSE-2.0
580
+ *
581
+ * Unless required by applicable law or agreed to in writing, software
582
+ * distributed under the License is distributed on an "AS IS" BASIS,
583
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
584
+ * See the License for the specific language governing permissions and
585
+ * limitations under the License.
586
+ */
587
+ /**
588
+ * Event parameters to set on 'gtag' during initialization.
589
+ */
590
+ let defaultEventParametersForInit;
591
+ /**
592
+ * Logs an analytics event through the Firebase SDK.
593
+ *
594
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
595
+ * @param eventName Google Analytics event name, choose from standard list or use a custom string.
596
+ * @param eventParams Analytics event parameters.
597
+ */
598
+ async function logEvent$1(gtagFunction, initializationPromise, eventName, eventParams, options) {
599
+ if (options && options.global) {
600
+ gtagFunction("event" /* EVENT */, eventName, eventParams);
601
+ return;
602
+ }
603
+ else {
604
+ const measurementId = await initializationPromise;
605
+ const params = Object.assign(Object.assign({}, eventParams), { 'send_to': measurementId });
606
+ gtagFunction("event" /* EVENT */, eventName, params);
607
+ }
608
+ }
609
+ /**
610
+ * Set screen_name parameter for this Google Analytics ID.
611
+ *
612
+ * @deprecated Use {@link logEvent} with `eventName` as 'screen_view' and add relevant `eventParams`.
613
+ * See {@link https://firebase.google.com/docs/analytics/screenviews | Track Screenviews}.
614
+ *
615
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
616
+ * @param screenName Screen name string to set.
617
+ */
618
+ async function setCurrentScreen$1(gtagFunction, initializationPromise, screenName, options) {
619
+ if (options && options.global) {
620
+ gtagFunction("set" /* SET */, { 'screen_name': screenName });
621
+ return Promise.resolve();
622
+ }
623
+ else {
624
+ const measurementId = await initializationPromise;
625
+ gtagFunction("config" /* CONFIG */, measurementId, {
626
+ update: true,
627
+ 'screen_name': screenName
628
+ });
629
+ }
630
+ }
631
+ /**
632
+ * Set user_id parameter for this Google Analytics ID.
633
+ *
634
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
635
+ * @param id User ID string to set
636
+ */
637
+ async function setUserId$1(gtagFunction, initializationPromise, id, options) {
638
+ if (options && options.global) {
639
+ gtagFunction("set" /* SET */, { 'user_id': id });
640
+ return Promise.resolve();
641
+ }
642
+ else {
643
+ const measurementId = await initializationPromise;
644
+ gtagFunction("config" /* CONFIG */, measurementId, {
645
+ update: true,
646
+ 'user_id': id
647
+ });
648
+ }
649
+ }
650
+ /**
651
+ * Set all other user properties other than user_id and screen_name.
652
+ *
653
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
654
+ * @param properties Map of user properties to set
655
+ */
656
+ async function setUserProperties$1(gtagFunction, initializationPromise, properties, options) {
657
+ if (options && options.global) {
658
+ const flatProperties = {};
659
+ for (const key of Object.keys(properties)) {
660
+ // use dot notation for merge behavior in gtag.js
661
+ flatProperties[`user_properties.${key}`] = properties[key];
662
+ }
663
+ gtagFunction("set" /* SET */, flatProperties);
664
+ return Promise.resolve();
665
+ }
666
+ else {
667
+ const measurementId = await initializationPromise;
668
+ gtagFunction("config" /* CONFIG */, measurementId, {
669
+ update: true,
670
+ 'user_properties': properties
671
+ });
672
+ }
673
+ }
674
+ /**
675
+ * Set whether collection is enabled for this ID.
676
+ *
677
+ * @param enabled If true, collection is enabled for this ID.
678
+ */
679
+ async function setAnalyticsCollectionEnabled$1(initializationPromise, enabled) {
680
+ const measurementId = await initializationPromise;
681
+ window[`ga-disable-${measurementId}`] = !enabled;
682
+ }
683
+ /**
684
+ * Sets the variable `defaultEventParametersForInit` for use in the initialization of
685
+ * analytics.
686
+ *
687
+ * @param customParams Any custom params the user may pass to gtag.js.
688
+ */
689
+ function _setDefaultEventParametersForInit(customParams) {
690
+ defaultEventParametersForInit = customParams;
691
+ }
692
+
569
693
  /**
570
694
  * @license
571
695
  * Copyright 2020 Google LLC
@@ -583,6 +707,7 @@ class AnalyticsAbortSignal {
583
707
  * limitations under the License.
584
708
  */
585
709
  async function validateIndexedDB() {
710
+ var _a;
586
711
  if (!isIndexedDBAvailable()) {
587
712
  logger.warn(ERROR_FACTORY.create("indexeddb-unavailable" /* INDEXEDDB_UNAVAILABLE */, {
588
713
  errorInfo: 'IndexedDB is not available in this environment.'
@@ -595,7 +720,7 @@ async function validateIndexedDB() {
595
720
  }
596
721
  catch (e) {
597
722
  logger.warn(ERROR_FACTORY.create("indexeddb-unavailable" /* INDEXEDDB_UNAVAILABLE */, {
598
- errorInfo: e
723
+ errorInfo: (_a = e) === null || _a === void 0 ? void 0 : _a.toString()
599
724
  }).message);
600
725
  return false;
601
726
  }
@@ -669,6 +794,11 @@ async function _initializeAnalytics(app, dynamicConfigPromisesList, measurementI
669
794
  // Note: This will trigger a page_view event unless 'send_page_view' is set to false in
670
795
  // `configProperties`.
671
796
  gtagCore("config" /* CONFIG */, dynamicConfig.measurementId, configProperties);
797
+ // Detects if there is data that will be set on every event logged from the SDK.
798
+ if (defaultEventParametersForInit) {
799
+ gtagCore("set" /* SET */, defaultEventParametersForInit);
800
+ _setDefaultEventParametersForInit(undefined);
801
+ }
672
802
  return dynamicConfig.measurementId;
673
803
  }
674
804
 
@@ -829,115 +959,6 @@ function factory(app, installations, options) {
829
959
  return analyticsInstance;
830
960
  }
831
961
 
832
- /**
833
- * @license
834
- * Copyright 2019 Google LLC
835
- *
836
- * Licensed under the Apache License, Version 2.0 (the "License");
837
- * you may not use this file except in compliance with the License.
838
- * You may obtain a copy of the License at
839
- *
840
- * http://www.apache.org/licenses/LICENSE-2.0
841
- *
842
- * Unless required by applicable law or agreed to in writing, software
843
- * distributed under the License is distributed on an "AS IS" BASIS,
844
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
845
- * See the License for the specific language governing permissions and
846
- * limitations under the License.
847
- */
848
- /**
849
- * Logs an analytics event through the Firebase SDK.
850
- *
851
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
852
- * @param eventName Google Analytics event name, choose from standard list or use a custom string.
853
- * @param eventParams Analytics event parameters.
854
- */
855
- async function logEvent$1(gtagFunction, initializationPromise, eventName, eventParams, options) {
856
- if (options && options.global) {
857
- gtagFunction("event" /* EVENT */, eventName, eventParams);
858
- return;
859
- }
860
- else {
861
- const measurementId = await initializationPromise;
862
- const params = Object.assign(Object.assign({}, eventParams), { 'send_to': measurementId });
863
- gtagFunction("event" /* EVENT */, eventName, params);
864
- }
865
- }
866
- /**
867
- * Set screen_name parameter for this Google Analytics ID.
868
- *
869
- * @deprecated Use {@link logEvent} with `eventName` as 'screen_view' and add relevant `eventParams`.
870
- * See {@link https://firebase.google.com/docs/analytics/screenviews | Track Screenviews}.
871
- *
872
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
873
- * @param screenName Screen name string to set.
874
- */
875
- async function setCurrentScreen$1(gtagFunction, initializationPromise, screenName, options) {
876
- if (options && options.global) {
877
- gtagFunction("set" /* SET */, { 'screen_name': screenName });
878
- return Promise.resolve();
879
- }
880
- else {
881
- const measurementId = await initializationPromise;
882
- gtagFunction("config" /* CONFIG */, measurementId, {
883
- update: true,
884
- 'screen_name': screenName
885
- });
886
- }
887
- }
888
- /**
889
- * Set user_id parameter for this Google Analytics ID.
890
- *
891
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
892
- * @param id User ID string to set
893
- */
894
- async function setUserId$1(gtagFunction, initializationPromise, id, options) {
895
- if (options && options.global) {
896
- gtagFunction("set" /* SET */, { 'user_id': id });
897
- return Promise.resolve();
898
- }
899
- else {
900
- const measurementId = await initializationPromise;
901
- gtagFunction("config" /* CONFIG */, measurementId, {
902
- update: true,
903
- 'user_id': id
904
- });
905
- }
906
- }
907
- /**
908
- * Set all other user properties other than user_id and screen_name.
909
- *
910
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
911
- * @param properties Map of user properties to set
912
- */
913
- async function setUserProperties$1(gtagFunction, initializationPromise, properties, options) {
914
- if (options && options.global) {
915
- const flatProperties = {};
916
- for (const key of Object.keys(properties)) {
917
- // use dot notation for merge behavior in gtag.js
918
- flatProperties[`user_properties.${key}`] = properties[key];
919
- }
920
- gtagFunction("set" /* SET */, flatProperties);
921
- return Promise.resolve();
922
- }
923
- else {
924
- const measurementId = await initializationPromise;
925
- gtagFunction("config" /* CONFIG */, measurementId, {
926
- update: true,
927
- 'user_properties': properties
928
- });
929
- }
930
- }
931
- /**
932
- * Set whether collection is enabled for this ID.
933
- *
934
- * @param enabled If true, collection is enabled for this ID.
935
- */
936
- async function setAnalyticsCollectionEnabled$1(initializationPromise, enabled) {
937
- const measurementId = await initializationPromise;
938
- window[`ga-disable-${measurementId}`] = !enabled;
939
- }
940
-
941
962
  /* eslint-disable @typescript-eslint/no-explicit-any */
942
963
  /**
943
964
  * Returns an {@link Analytics} instance for the given app.
@@ -1055,6 +1076,22 @@ function setAnalyticsCollectionEnabled(analyticsInstance, enabled) {
1055
1076
  analyticsInstance = getModularInstance(analyticsInstance);
1056
1077
  setAnalyticsCollectionEnabled$1(initializationPromisesMap[analyticsInstance.app.options.appId], enabled).catch(e => logger.error(e));
1057
1078
  }
1079
+ /**
1080
+ * Adds data that will be set on every event logged from the SDK, including automatic ones.
1081
+ * With gtag's "set" command, the values passed persist on the current page and are passed with
1082
+ * all subsequent events.
1083
+ * @public
1084
+ * @param customParams Any custom params the user may pass to gtag.js.
1085
+ */
1086
+ function setDefaultEventParameters(customParams) {
1087
+ // Check if reference to existing gtag function on window object exists
1088
+ if (wrappedGtagFunction) {
1089
+ wrappedGtagFunction("set" /* SET */, customParams);
1090
+ }
1091
+ else {
1092
+ _setDefaultEventParametersForInit(customParams);
1093
+ }
1094
+ }
1058
1095
  /**
1059
1096
  * Sends a Google Analytics event with given `eventParams`. This method
1060
1097
  * automatically associates this logged event with this Firebase web
@@ -1072,7 +1109,7 @@ function logEvent(analyticsInstance, eventName, eventParams, options) {
1072
1109
  }
1073
1110
 
1074
1111
  const name = "@firebase/analytics";
1075
- const version = "0.7.10";
1112
+ const version = "0.7.11-canary.69e2ee064";
1076
1113
 
1077
1114
  /**
1078
1115
  * Firebase Analytics
@@ -1108,5 +1145,5 @@ function registerAnalytics() {
1108
1145
  }
1109
1146
  registerAnalytics();
1110
1147
 
1111
- export { getAnalytics, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setCurrentScreen, setUserId, setUserProperties, settings };
1148
+ export { getAnalytics, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setCurrentScreen, setDefaultEventParameters, setUserId, setUserProperties, settings };
1112
1149
  //# sourceMappingURL=index.esm2017.js.map