@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.
package/dist/index.cjs.js CHANGED
@@ -540,53 +540,55 @@ retryData, timeoutMillis) {
540
540
  */
541
541
  function attemptFetchDynamicConfigWithRetry(appFields, _a, signal, retryData // for testing
542
542
  ) {
543
+ var _b, _c;
543
544
  var throttleEndTimeMillis = _a.throttleEndTimeMillis, backoffCount = _a.backoffCount;
544
545
  if (retryData === void 0) { retryData = defaultRetryData; }
545
546
  return tslib.__awaiter(this, void 0, void 0, function () {
546
- var appId, measurementId, e_1, response, e_2, backoffMillis, throttleMetadata;
547
- return tslib.__generator(this, function (_b) {
548
- switch (_b.label) {
547
+ var appId, measurementId, e_1, response, e_2, error, backoffMillis, throttleMetadata;
548
+ return tslib.__generator(this, function (_d) {
549
+ switch (_d.label) {
549
550
  case 0:
550
551
  appId = appFields.appId, measurementId = appFields.measurementId;
551
- _b.label = 1;
552
+ _d.label = 1;
552
553
  case 1:
553
- _b.trys.push([1, 3, , 4]);
554
+ _d.trys.push([1, 3, , 4]);
554
555
  return [4 /*yield*/, setAbortableTimeout(signal, throttleEndTimeMillis)];
555
556
  case 2:
556
- _b.sent();
557
+ _d.sent();
557
558
  return [3 /*break*/, 4];
558
559
  case 3:
559
- e_1 = _b.sent();
560
+ e_1 = _d.sent();
560
561
  if (measurementId) {
561
562
  logger.warn("Timed out fetching this Firebase app's measurement ID from the server." +
562
563
  (" Falling back to the measurement ID " + measurementId) +
563
- (" provided in the \"measurementId\" field in the local Firebase config. [" + e_1.message + "]"));
564
+ (" provided in the \"measurementId\" field in the local Firebase config. [" + ((_b = e_1) === null || _b === void 0 ? void 0 : _b.message) + "]"));
564
565
  return [2 /*return*/, { appId: appId, measurementId: measurementId }];
565
566
  }
566
567
  throw e_1;
567
568
  case 4:
568
- _b.trys.push([4, 6, , 7]);
569
+ _d.trys.push([4, 6, , 7]);
569
570
  return [4 /*yield*/, fetchDynamicConfig(appFields)];
570
571
  case 5:
571
- response = _b.sent();
572
+ response = _d.sent();
572
573
  // Note the SDK only clears throttle state if response is success or non-retriable.
573
574
  retryData.deleteThrottleMetadata(appId);
574
575
  return [2 /*return*/, response];
575
576
  case 6:
576
- e_2 = _b.sent();
577
- if (!isRetriableError(e_2)) {
577
+ e_2 = _d.sent();
578
+ error = e_2;
579
+ if (!isRetriableError(error)) {
578
580
  retryData.deleteThrottleMetadata(appId);
579
581
  if (measurementId) {
580
582
  logger.warn("Failed to fetch this Firebase app's measurement ID from the server." +
581
583
  (" Falling back to the measurement ID " + measurementId) +
582
- (" provided in the \"measurementId\" field in the local Firebase config. [" + e_2.message + "]"));
584
+ (" provided in the \"measurementId\" field in the local Firebase config. [" + (error === null || error === void 0 ? void 0 : error.message) + "]"));
583
585
  return [2 /*return*/, { appId: appId, measurementId: measurementId }];
584
586
  }
585
587
  else {
586
588
  throw e_2;
587
589
  }
588
590
  }
589
- backoffMillis = Number(e_2.customData.httpStatus) === 503
591
+ backoffMillis = Number((_c = error === null || error === void 0 ? void 0 : error.customData) === null || _c === void 0 ? void 0 : _c.httpStatus) === 503
590
592
  ? util.calculateBackoffMillis(backoffCount, retryData.intervalMillis, LONG_RETRY_FACTOR)
591
593
  : util.calculateBackoffMillis(backoffCount, retryData.intervalMillis);
592
594
  throttleMetadata = {
@@ -664,6 +666,175 @@ var AnalyticsAbortSignal = /** @class */ (function () {
664
666
  return AnalyticsAbortSignal;
665
667
  }());
666
668
 
669
+ /**
670
+ * @license
671
+ * Copyright 2019 Google LLC
672
+ *
673
+ * Licensed under the Apache License, Version 2.0 (the "License");
674
+ * you may not use this file except in compliance with the License.
675
+ * You may obtain a copy of the License at
676
+ *
677
+ * http://www.apache.org/licenses/LICENSE-2.0
678
+ *
679
+ * Unless required by applicable law or agreed to in writing, software
680
+ * distributed under the License is distributed on an "AS IS" BASIS,
681
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
682
+ * See the License for the specific language governing permissions and
683
+ * limitations under the License.
684
+ */
685
+ /**
686
+ * Event parameters to set on 'gtag' during initialization.
687
+ */
688
+ var defaultEventParametersForInit;
689
+ /**
690
+ * Logs an analytics event through the Firebase SDK.
691
+ *
692
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
693
+ * @param eventName Google Analytics event name, choose from standard list or use a custom string.
694
+ * @param eventParams Analytics event parameters.
695
+ */
696
+ function logEvent$1(gtagFunction, initializationPromise, eventName, eventParams, options) {
697
+ return tslib.__awaiter(this, void 0, void 0, function () {
698
+ var measurementId, params;
699
+ return tslib.__generator(this, function (_a) {
700
+ switch (_a.label) {
701
+ case 0:
702
+ if (!(options && options.global)) return [3 /*break*/, 1];
703
+ gtagFunction("event" /* EVENT */, eventName, eventParams);
704
+ return [2 /*return*/];
705
+ case 1: return [4 /*yield*/, initializationPromise];
706
+ case 2:
707
+ measurementId = _a.sent();
708
+ params = tslib.__assign(tslib.__assign({}, eventParams), { 'send_to': measurementId });
709
+ gtagFunction("event" /* EVENT */, eventName, params);
710
+ _a.label = 3;
711
+ case 3: return [2 /*return*/];
712
+ }
713
+ });
714
+ });
715
+ }
716
+ /**
717
+ * Set screen_name parameter for this Google Analytics ID.
718
+ *
719
+ * @deprecated Use {@link logEvent} with `eventName` as 'screen_view' and add relevant `eventParams`.
720
+ * See {@link https://firebase.google.com/docs/analytics/screenviews | Track Screenviews}.
721
+ *
722
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
723
+ * @param screenName Screen name string to set.
724
+ */
725
+ function setCurrentScreen$1(gtagFunction, initializationPromise, screenName, options) {
726
+ return tslib.__awaiter(this, void 0, void 0, function () {
727
+ var measurementId;
728
+ return tslib.__generator(this, function (_a) {
729
+ switch (_a.label) {
730
+ case 0:
731
+ if (!(options && options.global)) return [3 /*break*/, 1];
732
+ gtagFunction("set" /* SET */, { 'screen_name': screenName });
733
+ return [2 /*return*/, Promise.resolve()];
734
+ case 1: return [4 /*yield*/, initializationPromise];
735
+ case 2:
736
+ measurementId = _a.sent();
737
+ gtagFunction("config" /* CONFIG */, measurementId, {
738
+ update: true,
739
+ 'screen_name': screenName
740
+ });
741
+ _a.label = 3;
742
+ case 3: return [2 /*return*/];
743
+ }
744
+ });
745
+ });
746
+ }
747
+ /**
748
+ * Set user_id parameter for this Google Analytics ID.
749
+ *
750
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
751
+ * @param id User ID string to set
752
+ */
753
+ function setUserId$1(gtagFunction, initializationPromise, id, options) {
754
+ return tslib.__awaiter(this, void 0, void 0, function () {
755
+ var measurementId;
756
+ return tslib.__generator(this, function (_a) {
757
+ switch (_a.label) {
758
+ case 0:
759
+ if (!(options && options.global)) return [3 /*break*/, 1];
760
+ gtagFunction("set" /* SET */, { 'user_id': id });
761
+ return [2 /*return*/, Promise.resolve()];
762
+ case 1: return [4 /*yield*/, initializationPromise];
763
+ case 2:
764
+ measurementId = _a.sent();
765
+ gtagFunction("config" /* CONFIG */, measurementId, {
766
+ update: true,
767
+ 'user_id': id
768
+ });
769
+ _a.label = 3;
770
+ case 3: return [2 /*return*/];
771
+ }
772
+ });
773
+ });
774
+ }
775
+ /**
776
+ * Set all other user properties other than user_id and screen_name.
777
+ *
778
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
779
+ * @param properties Map of user properties to set
780
+ */
781
+ function setUserProperties$1(gtagFunction, initializationPromise, properties, options) {
782
+ return tslib.__awaiter(this, void 0, void 0, function () {
783
+ var flatProperties, _i, _a, key, measurementId;
784
+ return tslib.__generator(this, function (_b) {
785
+ switch (_b.label) {
786
+ case 0:
787
+ if (!(options && options.global)) return [3 /*break*/, 1];
788
+ flatProperties = {};
789
+ for (_i = 0, _a = Object.keys(properties); _i < _a.length; _i++) {
790
+ key = _a[_i];
791
+ // use dot notation for merge behavior in gtag.js
792
+ flatProperties["user_properties." + key] = properties[key];
793
+ }
794
+ gtagFunction("set" /* SET */, flatProperties);
795
+ return [2 /*return*/, Promise.resolve()];
796
+ case 1: return [4 /*yield*/, initializationPromise];
797
+ case 2:
798
+ measurementId = _b.sent();
799
+ gtagFunction("config" /* CONFIG */, measurementId, {
800
+ update: true,
801
+ 'user_properties': properties
802
+ });
803
+ _b.label = 3;
804
+ case 3: return [2 /*return*/];
805
+ }
806
+ });
807
+ });
808
+ }
809
+ /**
810
+ * Set whether collection is enabled for this ID.
811
+ *
812
+ * @param enabled If true, collection is enabled for this ID.
813
+ */
814
+ function setAnalyticsCollectionEnabled$1(initializationPromise, enabled) {
815
+ return tslib.__awaiter(this, void 0, void 0, function () {
816
+ var measurementId;
817
+ return tslib.__generator(this, function (_a) {
818
+ switch (_a.label) {
819
+ case 0: return [4 /*yield*/, initializationPromise];
820
+ case 1:
821
+ measurementId = _a.sent();
822
+ window["ga-disable-" + measurementId] = !enabled;
823
+ return [2 /*return*/];
824
+ }
825
+ });
826
+ });
827
+ }
828
+ /**
829
+ * Sets the variable `defaultEventParametersForInit` for use in the initialization of
830
+ * analytics.
831
+ *
832
+ * @param customParams Any custom params the user may pass to gtag.js.
833
+ */
834
+ function _setDefaultEventParametersForInit(customParams) {
835
+ defaultEventParametersForInit = customParams;
836
+ }
837
+
667
838
  /**
668
839
  * @license
669
840
  * Copyright 2020 Google LLC
@@ -681,10 +852,11 @@ var AnalyticsAbortSignal = /** @class */ (function () {
681
852
  * limitations under the License.
682
853
  */
683
854
  function validateIndexedDB() {
855
+ var _a;
684
856
  return tslib.__awaiter(this, void 0, void 0, function () {
685
857
  var e_1;
686
- return tslib.__generator(this, function (_a) {
687
- switch (_a.label) {
858
+ return tslib.__generator(this, function (_b) {
859
+ switch (_b.label) {
688
860
  case 0:
689
861
  if (!!util.isIndexedDBAvailable()) return [3 /*break*/, 1];
690
862
  logger.warn(ERROR_FACTORY.create("indexeddb-unavailable" /* INDEXEDDB_UNAVAILABLE */, {
@@ -692,15 +864,15 @@ function validateIndexedDB() {
692
864
  }).message);
693
865
  return [2 /*return*/, false];
694
866
  case 1:
695
- _a.trys.push([1, 3, , 4]);
867
+ _b.trys.push([1, 3, , 4]);
696
868
  return [4 /*yield*/, util.validateIndexedDBOpenable()];
697
869
  case 2:
698
- _a.sent();
870
+ _b.sent();
699
871
  return [3 /*break*/, 4];
700
872
  case 3:
701
- e_1 = _a.sent();
873
+ e_1 = _b.sent();
702
874
  logger.warn(ERROR_FACTORY.create("indexeddb-unavailable" /* INDEXEDDB_UNAVAILABLE */, {
703
- errorInfo: e_1
875
+ errorInfo: (_a = e_1) === null || _a === void 0 ? void 0 : _a.toString()
704
876
  }).message);
705
877
  return [2 /*return*/, false];
706
878
  case 4: return [2 /*return*/, true];
@@ -780,6 +952,11 @@ function _initializeAnalytics(app, dynamicConfigPromisesList, measurementIdToApp
780
952
  // Note: This will trigger a page_view event unless 'send_page_view' is set to false in
781
953
  // `configProperties`.
782
954
  gtagCore("config" /* CONFIG */, dynamicConfig.measurementId, configProperties);
955
+ // Detects if there is data that will be set on every event logged from the SDK.
956
+ if (defaultEventParametersForInit) {
957
+ gtagCore("set" /* SET */, defaultEventParametersForInit);
958
+ _setDefaultEventParametersForInit(undefined);
959
+ }
783
960
  return [2 /*return*/, dynamicConfig.measurementId];
784
961
  }
785
962
  });
@@ -944,162 +1121,6 @@ function factory(app, installations, options) {
944
1121
  return analyticsInstance;
945
1122
  }
946
1123
 
947
- /**
948
- * @license
949
- * Copyright 2019 Google LLC
950
- *
951
- * Licensed under the Apache License, Version 2.0 (the "License");
952
- * you may not use this file except in compliance with the License.
953
- * You may obtain a copy of the License at
954
- *
955
- * http://www.apache.org/licenses/LICENSE-2.0
956
- *
957
- * Unless required by applicable law or agreed to in writing, software
958
- * distributed under the License is distributed on an "AS IS" BASIS,
959
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
960
- * See the License for the specific language governing permissions and
961
- * limitations under the License.
962
- */
963
- /**
964
- * Logs an analytics event through the Firebase SDK.
965
- *
966
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
967
- * @param eventName Google Analytics event name, choose from standard list or use a custom string.
968
- * @param eventParams Analytics event parameters.
969
- */
970
- function logEvent$1(gtagFunction, initializationPromise, eventName, eventParams, options) {
971
- return tslib.__awaiter(this, void 0, void 0, function () {
972
- var measurementId, params;
973
- return tslib.__generator(this, function (_a) {
974
- switch (_a.label) {
975
- case 0:
976
- if (!(options && options.global)) return [3 /*break*/, 1];
977
- gtagFunction("event" /* EVENT */, eventName, eventParams);
978
- return [2 /*return*/];
979
- case 1: return [4 /*yield*/, initializationPromise];
980
- case 2:
981
- measurementId = _a.sent();
982
- params = tslib.__assign(tslib.__assign({}, eventParams), { 'send_to': measurementId });
983
- gtagFunction("event" /* EVENT */, eventName, params);
984
- _a.label = 3;
985
- case 3: return [2 /*return*/];
986
- }
987
- });
988
- });
989
- }
990
- /**
991
- * Set screen_name parameter for this Google Analytics ID.
992
- *
993
- * @deprecated Use {@link logEvent} with `eventName` as 'screen_view' and add relevant `eventParams`.
994
- * See {@link https://firebase.google.com/docs/analytics/screenviews | Track Screenviews}.
995
- *
996
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
997
- * @param screenName Screen name string to set.
998
- */
999
- function setCurrentScreen$1(gtagFunction, initializationPromise, screenName, options) {
1000
- return tslib.__awaiter(this, void 0, void 0, function () {
1001
- var measurementId;
1002
- return tslib.__generator(this, function (_a) {
1003
- switch (_a.label) {
1004
- case 0:
1005
- if (!(options && options.global)) return [3 /*break*/, 1];
1006
- gtagFunction("set" /* SET */, { 'screen_name': screenName });
1007
- return [2 /*return*/, Promise.resolve()];
1008
- case 1: return [4 /*yield*/, initializationPromise];
1009
- case 2:
1010
- measurementId = _a.sent();
1011
- gtagFunction("config" /* CONFIG */, measurementId, {
1012
- update: true,
1013
- 'screen_name': screenName
1014
- });
1015
- _a.label = 3;
1016
- case 3: return [2 /*return*/];
1017
- }
1018
- });
1019
- });
1020
- }
1021
- /**
1022
- * Set user_id parameter for this Google Analytics ID.
1023
- *
1024
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
1025
- * @param id User ID string to set
1026
- */
1027
- function setUserId$1(gtagFunction, initializationPromise, id, options) {
1028
- return tslib.__awaiter(this, void 0, void 0, function () {
1029
- var measurementId;
1030
- return tslib.__generator(this, function (_a) {
1031
- switch (_a.label) {
1032
- case 0:
1033
- if (!(options && options.global)) return [3 /*break*/, 1];
1034
- gtagFunction("set" /* SET */, { 'user_id': id });
1035
- return [2 /*return*/, Promise.resolve()];
1036
- case 1: return [4 /*yield*/, initializationPromise];
1037
- case 2:
1038
- measurementId = _a.sent();
1039
- gtagFunction("config" /* CONFIG */, measurementId, {
1040
- update: true,
1041
- 'user_id': id
1042
- });
1043
- _a.label = 3;
1044
- case 3: return [2 /*return*/];
1045
- }
1046
- });
1047
- });
1048
- }
1049
- /**
1050
- * Set all other user properties other than user_id and screen_name.
1051
- *
1052
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
1053
- * @param properties Map of user properties to set
1054
- */
1055
- function setUserProperties$1(gtagFunction, initializationPromise, properties, options) {
1056
- return tslib.__awaiter(this, void 0, void 0, function () {
1057
- var flatProperties, _i, _a, key, measurementId;
1058
- return tslib.__generator(this, function (_b) {
1059
- switch (_b.label) {
1060
- case 0:
1061
- if (!(options && options.global)) return [3 /*break*/, 1];
1062
- flatProperties = {};
1063
- for (_i = 0, _a = Object.keys(properties); _i < _a.length; _i++) {
1064
- key = _a[_i];
1065
- // use dot notation for merge behavior in gtag.js
1066
- flatProperties["user_properties." + key] = properties[key];
1067
- }
1068
- gtagFunction("set" /* SET */, flatProperties);
1069
- return [2 /*return*/, Promise.resolve()];
1070
- case 1: return [4 /*yield*/, initializationPromise];
1071
- case 2:
1072
- measurementId = _b.sent();
1073
- gtagFunction("config" /* CONFIG */, measurementId, {
1074
- update: true,
1075
- 'user_properties': properties
1076
- });
1077
- _b.label = 3;
1078
- case 3: return [2 /*return*/];
1079
- }
1080
- });
1081
- });
1082
- }
1083
- /**
1084
- * Set whether collection is enabled for this ID.
1085
- *
1086
- * @param enabled If true, collection is enabled for this ID.
1087
- */
1088
- function setAnalyticsCollectionEnabled$1(initializationPromise, enabled) {
1089
- return tslib.__awaiter(this, void 0, void 0, function () {
1090
- var measurementId;
1091
- return tslib.__generator(this, function (_a) {
1092
- switch (_a.label) {
1093
- case 0: return [4 /*yield*/, initializationPromise];
1094
- case 1:
1095
- measurementId = _a.sent();
1096
- window["ga-disable-" + measurementId] = !enabled;
1097
- return [2 /*return*/];
1098
- }
1099
- });
1100
- });
1101
- }
1102
-
1103
1124
  /* eslint-disable @typescript-eslint/no-explicit-any */
1104
1125
  /**
1105
1126
  * Returns an {@link Analytics} instance for the given app.
@@ -1231,6 +1252,22 @@ function setAnalyticsCollectionEnabled(analyticsInstance, enabled) {
1231
1252
  analyticsInstance = util.getModularInstance(analyticsInstance);
1232
1253
  setAnalyticsCollectionEnabled$1(initializationPromisesMap[analyticsInstance.app.options.appId], enabled).catch(function (e) { return logger.error(e); });
1233
1254
  }
1255
+ /**
1256
+ * Adds data that will be set on every event logged from the SDK, including automatic ones.
1257
+ * With gtag's "set" command, the values passed persist on the current page and are passed with
1258
+ * all subsequent events.
1259
+ * @public
1260
+ * @param customParams Any custom params the user may pass to gtag.js.
1261
+ */
1262
+ function setDefaultEventParameters(customParams) {
1263
+ // Check if reference to existing gtag function on window object exists
1264
+ if (wrappedGtagFunction) {
1265
+ wrappedGtagFunction("set" /* SET */, customParams);
1266
+ }
1267
+ else {
1268
+ _setDefaultEventParametersForInit(customParams);
1269
+ }
1270
+ }
1234
1271
  /**
1235
1272
  * Sends a Google Analytics event with given `eventParams`. This method
1236
1273
  * automatically associates this logged event with this Firebase web
@@ -1248,7 +1285,7 @@ function logEvent(analyticsInstance, eventName, eventParams, options) {
1248
1285
  }
1249
1286
 
1250
1287
  var name = "@firebase/analytics";
1251
- var version = "0.7.10";
1288
+ var version = "0.7.11-canary.69e2ee064";
1252
1289
 
1253
1290
  /**
1254
1291
  * Firebase Analytics
@@ -1291,6 +1328,7 @@ exports.isSupported = isSupported;
1291
1328
  exports.logEvent = logEvent;
1292
1329
  exports.setAnalyticsCollectionEnabled = setAnalyticsCollectionEnabled;
1293
1330
  exports.setCurrentScreen = setCurrentScreen;
1331
+ exports.setDefaultEventParameters = setDefaultEventParameters;
1294
1332
  exports.setUserId = setUserId;
1295
1333
  exports.setUserProperties = setUserProperties;
1296
1334
  exports.settings = settings;