@firebase/analytics 0.7.11-canary.47b34555c → 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
@@ -666,6 +666,175 @@ var AnalyticsAbortSignal = /** @class */ (function () {
666
666
  return AnalyticsAbortSignal;
667
667
  }());
668
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
+
669
838
  /**
670
839
  * @license
671
840
  * Copyright 2020 Google LLC
@@ -783,6 +952,11 @@ function _initializeAnalytics(app, dynamicConfigPromisesList, measurementIdToApp
783
952
  // Note: This will trigger a page_view event unless 'send_page_view' is set to false in
784
953
  // `configProperties`.
785
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
+ }
786
960
  return [2 /*return*/, dynamicConfig.measurementId];
787
961
  }
788
962
  });
@@ -947,162 +1121,6 @@ function factory(app, installations, options) {
947
1121
  return analyticsInstance;
948
1122
  }
949
1123
 
950
- /**
951
- * @license
952
- * Copyright 2019 Google LLC
953
- *
954
- * Licensed under the Apache License, Version 2.0 (the "License");
955
- * you may not use this file except in compliance with the License.
956
- * You may obtain a copy of the License at
957
- *
958
- * http://www.apache.org/licenses/LICENSE-2.0
959
- *
960
- * Unless required by applicable law or agreed to in writing, software
961
- * distributed under the License is distributed on an "AS IS" BASIS,
962
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
963
- * See the License for the specific language governing permissions and
964
- * limitations under the License.
965
- */
966
- /**
967
- * Logs an analytics event through the Firebase SDK.
968
- *
969
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
970
- * @param eventName Google Analytics event name, choose from standard list or use a custom string.
971
- * @param eventParams Analytics event parameters.
972
- */
973
- function logEvent$1(gtagFunction, initializationPromise, eventName, eventParams, options) {
974
- return tslib.__awaiter(this, void 0, void 0, function () {
975
- var measurementId, params;
976
- return tslib.__generator(this, function (_a) {
977
- switch (_a.label) {
978
- case 0:
979
- if (!(options && options.global)) return [3 /*break*/, 1];
980
- gtagFunction("event" /* EVENT */, eventName, eventParams);
981
- return [2 /*return*/];
982
- case 1: return [4 /*yield*/, initializationPromise];
983
- case 2:
984
- measurementId = _a.sent();
985
- params = tslib.__assign(tslib.__assign({}, eventParams), { 'send_to': measurementId });
986
- gtagFunction("event" /* EVENT */, eventName, params);
987
- _a.label = 3;
988
- case 3: return [2 /*return*/];
989
- }
990
- });
991
- });
992
- }
993
- /**
994
- * Set screen_name parameter for this Google Analytics ID.
995
- *
996
- * @deprecated Use {@link logEvent} with `eventName` as 'screen_view' and add relevant `eventParams`.
997
- * See {@link https://firebase.google.com/docs/analytics/screenviews | Track Screenviews}.
998
- *
999
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
1000
- * @param screenName Screen name string to set.
1001
- */
1002
- function setCurrentScreen$1(gtagFunction, initializationPromise, screenName, options) {
1003
- return tslib.__awaiter(this, void 0, void 0, function () {
1004
- var measurementId;
1005
- return tslib.__generator(this, function (_a) {
1006
- switch (_a.label) {
1007
- case 0:
1008
- if (!(options && options.global)) return [3 /*break*/, 1];
1009
- gtagFunction("set" /* SET */, { 'screen_name': screenName });
1010
- return [2 /*return*/, Promise.resolve()];
1011
- case 1: return [4 /*yield*/, initializationPromise];
1012
- case 2:
1013
- measurementId = _a.sent();
1014
- gtagFunction("config" /* CONFIG */, measurementId, {
1015
- update: true,
1016
- 'screen_name': screenName
1017
- });
1018
- _a.label = 3;
1019
- case 3: return [2 /*return*/];
1020
- }
1021
- });
1022
- });
1023
- }
1024
- /**
1025
- * Set user_id parameter for this Google Analytics ID.
1026
- *
1027
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
1028
- * @param id User ID string to set
1029
- */
1030
- function setUserId$1(gtagFunction, initializationPromise, id, options) {
1031
- return tslib.__awaiter(this, void 0, void 0, function () {
1032
- var measurementId;
1033
- return tslib.__generator(this, function (_a) {
1034
- switch (_a.label) {
1035
- case 0:
1036
- if (!(options && options.global)) return [3 /*break*/, 1];
1037
- gtagFunction("set" /* SET */, { 'user_id': id });
1038
- return [2 /*return*/, Promise.resolve()];
1039
- case 1: return [4 /*yield*/, initializationPromise];
1040
- case 2:
1041
- measurementId = _a.sent();
1042
- gtagFunction("config" /* CONFIG */, measurementId, {
1043
- update: true,
1044
- 'user_id': id
1045
- });
1046
- _a.label = 3;
1047
- case 3: return [2 /*return*/];
1048
- }
1049
- });
1050
- });
1051
- }
1052
- /**
1053
- * Set all other user properties other than user_id and screen_name.
1054
- *
1055
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
1056
- * @param properties Map of user properties to set
1057
- */
1058
- function setUserProperties$1(gtagFunction, initializationPromise, properties, options) {
1059
- return tslib.__awaiter(this, void 0, void 0, function () {
1060
- var flatProperties, _i, _a, key, measurementId;
1061
- return tslib.__generator(this, function (_b) {
1062
- switch (_b.label) {
1063
- case 0:
1064
- if (!(options && options.global)) return [3 /*break*/, 1];
1065
- flatProperties = {};
1066
- for (_i = 0, _a = Object.keys(properties); _i < _a.length; _i++) {
1067
- key = _a[_i];
1068
- // use dot notation for merge behavior in gtag.js
1069
- flatProperties["user_properties." + key] = properties[key];
1070
- }
1071
- gtagFunction("set" /* SET */, flatProperties);
1072
- return [2 /*return*/, Promise.resolve()];
1073
- case 1: return [4 /*yield*/, initializationPromise];
1074
- case 2:
1075
- measurementId = _b.sent();
1076
- gtagFunction("config" /* CONFIG */, measurementId, {
1077
- update: true,
1078
- 'user_properties': properties
1079
- });
1080
- _b.label = 3;
1081
- case 3: return [2 /*return*/];
1082
- }
1083
- });
1084
- });
1085
- }
1086
- /**
1087
- * Set whether collection is enabled for this ID.
1088
- *
1089
- * @param enabled If true, collection is enabled for this ID.
1090
- */
1091
- function setAnalyticsCollectionEnabled$1(initializationPromise, enabled) {
1092
- return tslib.__awaiter(this, void 0, void 0, function () {
1093
- var measurementId;
1094
- return tslib.__generator(this, function (_a) {
1095
- switch (_a.label) {
1096
- case 0: return [4 /*yield*/, initializationPromise];
1097
- case 1:
1098
- measurementId = _a.sent();
1099
- window["ga-disable-" + measurementId] = !enabled;
1100
- return [2 /*return*/];
1101
- }
1102
- });
1103
- });
1104
- }
1105
-
1106
1124
  /* eslint-disable @typescript-eslint/no-explicit-any */
1107
1125
  /**
1108
1126
  * Returns an {@link Analytics} instance for the given app.
@@ -1234,6 +1252,22 @@ function setAnalyticsCollectionEnabled(analyticsInstance, enabled) {
1234
1252
  analyticsInstance = util.getModularInstance(analyticsInstance);
1235
1253
  setAnalyticsCollectionEnabled$1(initializationPromisesMap[analyticsInstance.app.options.appId], enabled).catch(function (e) { return logger.error(e); });
1236
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
+ }
1237
1271
  /**
1238
1272
  * Sends a Google Analytics event with given `eventParams`. This method
1239
1273
  * automatically associates this logged event with this Firebase web
@@ -1251,7 +1285,7 @@ function logEvent(analyticsInstance, eventName, eventParams, options) {
1251
1285
  }
1252
1286
 
1253
1287
  var name = "@firebase/analytics";
1254
- var version = "0.7.11-canary.47b34555c";
1288
+ var version = "0.7.11-canary.69e2ee064";
1255
1289
 
1256
1290
  /**
1257
1291
  * Firebase Analytics
@@ -1294,6 +1328,7 @@ exports.isSupported = isSupported;
1294
1328
  exports.logEvent = logEvent;
1295
1329
  exports.setAnalyticsCollectionEnabled = setAnalyticsCollectionEnabled;
1296
1330
  exports.setCurrentScreen = setCurrentScreen;
1331
+ exports.setDefaultEventParameters = setDefaultEventParameters;
1297
1332
  exports.setUserId = setUserId;
1298
1333
  exports.setUserProperties = setUserProperties;
1299
1334
  exports.settings = settings;