@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.
@@ -568,6 +568,128 @@ class AnalyticsAbortSignal {
568
568
  }
569
569
  }
570
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
+
571
693
  /**
572
694
  * @license
573
695
  * Copyright 2020 Google LLC
@@ -672,6 +794,11 @@ async function _initializeAnalytics(app, dynamicConfigPromisesList, measurementI
672
794
  // Note: This will trigger a page_view event unless 'send_page_view' is set to false in
673
795
  // `configProperties`.
674
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
+ }
675
802
  return dynamicConfig.measurementId;
676
803
  }
677
804
 
@@ -832,115 +959,6 @@ function factory(app, installations, options) {
832
959
  return analyticsInstance;
833
960
  }
834
961
 
835
- /**
836
- * @license
837
- * Copyright 2019 Google LLC
838
- *
839
- * Licensed under the Apache License, Version 2.0 (the "License");
840
- * you may not use this file except in compliance with the License.
841
- * You may obtain a copy of the License at
842
- *
843
- * http://www.apache.org/licenses/LICENSE-2.0
844
- *
845
- * Unless required by applicable law or agreed to in writing, software
846
- * distributed under the License is distributed on an "AS IS" BASIS,
847
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
848
- * See the License for the specific language governing permissions and
849
- * limitations under the License.
850
- */
851
- /**
852
- * Logs an analytics event through the Firebase SDK.
853
- *
854
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
855
- * @param eventName Google Analytics event name, choose from standard list or use a custom string.
856
- * @param eventParams Analytics event parameters.
857
- */
858
- async function logEvent$1(gtagFunction, initializationPromise, eventName, eventParams, options) {
859
- if (options && options.global) {
860
- gtagFunction("event" /* EVENT */, eventName, eventParams);
861
- return;
862
- }
863
- else {
864
- const measurementId = await initializationPromise;
865
- const params = Object.assign(Object.assign({}, eventParams), { 'send_to': measurementId });
866
- gtagFunction("event" /* EVENT */, eventName, params);
867
- }
868
- }
869
- /**
870
- * Set screen_name parameter for this Google Analytics ID.
871
- *
872
- * @deprecated Use {@link logEvent} with `eventName` as 'screen_view' and add relevant `eventParams`.
873
- * See {@link https://firebase.google.com/docs/analytics/screenviews | Track Screenviews}.
874
- *
875
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
876
- * @param screenName Screen name string to set.
877
- */
878
- async function setCurrentScreen$1(gtagFunction, initializationPromise, screenName, options) {
879
- if (options && options.global) {
880
- gtagFunction("set" /* SET */, { 'screen_name': screenName });
881
- return Promise.resolve();
882
- }
883
- else {
884
- const measurementId = await initializationPromise;
885
- gtagFunction("config" /* CONFIG */, measurementId, {
886
- update: true,
887
- 'screen_name': screenName
888
- });
889
- }
890
- }
891
- /**
892
- * Set user_id parameter for this Google Analytics ID.
893
- *
894
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
895
- * @param id User ID string to set
896
- */
897
- async function setUserId$1(gtagFunction, initializationPromise, id, options) {
898
- if (options && options.global) {
899
- gtagFunction("set" /* SET */, { 'user_id': id });
900
- return Promise.resolve();
901
- }
902
- else {
903
- const measurementId = await initializationPromise;
904
- gtagFunction("config" /* CONFIG */, measurementId, {
905
- update: true,
906
- 'user_id': id
907
- });
908
- }
909
- }
910
- /**
911
- * Set all other user properties other than user_id and screen_name.
912
- *
913
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
914
- * @param properties Map of user properties to set
915
- */
916
- async function setUserProperties$1(gtagFunction, initializationPromise, properties, options) {
917
- if (options && options.global) {
918
- const flatProperties = {};
919
- for (const key of Object.keys(properties)) {
920
- // use dot notation for merge behavior in gtag.js
921
- flatProperties[`user_properties.${key}`] = properties[key];
922
- }
923
- gtagFunction("set" /* SET */, flatProperties);
924
- return Promise.resolve();
925
- }
926
- else {
927
- const measurementId = await initializationPromise;
928
- gtagFunction("config" /* CONFIG */, measurementId, {
929
- update: true,
930
- 'user_properties': properties
931
- });
932
- }
933
- }
934
- /**
935
- * Set whether collection is enabled for this ID.
936
- *
937
- * @param enabled If true, collection is enabled for this ID.
938
- */
939
- async function setAnalyticsCollectionEnabled$1(initializationPromise, enabled) {
940
- const measurementId = await initializationPromise;
941
- window[`ga-disable-${measurementId}`] = !enabled;
942
- }
943
-
944
962
  /* eslint-disable @typescript-eslint/no-explicit-any */
945
963
  /**
946
964
  * Returns an {@link Analytics} instance for the given app.
@@ -1058,6 +1076,22 @@ function setAnalyticsCollectionEnabled(analyticsInstance, enabled) {
1058
1076
  analyticsInstance = getModularInstance(analyticsInstance);
1059
1077
  setAnalyticsCollectionEnabled$1(initializationPromisesMap[analyticsInstance.app.options.appId], enabled).catch(e => logger.error(e));
1060
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
+ }
1061
1095
  /**
1062
1096
  * Sends a Google Analytics event with given `eventParams`. This method
1063
1097
  * automatically associates this logged event with this Firebase web
@@ -1075,7 +1109,7 @@ function logEvent(analyticsInstance, eventName, eventParams, options) {
1075
1109
  }
1076
1110
 
1077
1111
  const name = "@firebase/analytics";
1078
- const version = "0.7.11-canary.47b34555c";
1112
+ const version = "0.7.11-canary.69e2ee064";
1079
1113
 
1080
1114
  /**
1081
1115
  * Firebase Analytics
@@ -1111,5 +1145,5 @@ function registerAnalytics() {
1111
1145
  }
1112
1146
  registerAnalytics();
1113
1147
 
1114
- export { getAnalytics, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setCurrentScreen, setUserId, setUserProperties, settings };
1148
+ export { getAnalytics, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setCurrentScreen, setDefaultEventParameters, setUserId, setUserProperties, settings };
1115
1149
  //# sourceMappingURL=index.esm2017.js.map