@firebase/analytics 0.7.11 → 0.8.0-20220706191717

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.
@@ -234,6 +234,10 @@ measurementIdToAppId) {
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 */) {
238
+ // If CONFIG, second arg must be measurementId.
239
+ gtagCore("consent" /* CONSENT */, 'update', gtagParams);
240
+ }
237
241
  else {
238
242
  // If SET, second arg must be params.
239
243
  gtagCore("set" /* SET */, idOrNameOrParams);
@@ -568,6 +572,141 @@ class AnalyticsAbortSignal {
568
572
  }
569
573
  }
570
574
 
575
+ /**
576
+ * @license
577
+ * Copyright 2019 Google LLC
578
+ *
579
+ * Licensed under the Apache License, Version 2.0 (the "License");
580
+ * you may not use this file except in compliance with the License.
581
+ * You may obtain a copy of the License at
582
+ *
583
+ * http://www.apache.org/licenses/LICENSE-2.0
584
+ *
585
+ * Unless required by applicable law or agreed to in writing, software
586
+ * distributed under the License is distributed on an "AS IS" BASIS,
587
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
588
+ * See the License for the specific language governing permissions and
589
+ * limitations under the License.
590
+ */
591
+ /**
592
+ * Event parameters to set on 'gtag' during initialization.
593
+ */
594
+ let defaultEventParametersForInit;
595
+ /**
596
+ * Logs an analytics event through the Firebase SDK.
597
+ *
598
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
599
+ * @param eventName Google Analytics event name, choose from standard list or use a custom string.
600
+ * @param eventParams Analytics event parameters.
601
+ */
602
+ async function logEvent$1(gtagFunction, initializationPromise, eventName, eventParams, options) {
603
+ if (options && options.global) {
604
+ gtagFunction("event" /* EVENT */, eventName, eventParams);
605
+ return;
606
+ }
607
+ else {
608
+ const measurementId = await initializationPromise;
609
+ const params = Object.assign(Object.assign({}, eventParams), { 'send_to': measurementId });
610
+ gtagFunction("event" /* EVENT */, eventName, params);
611
+ }
612
+ }
613
+ /**
614
+ * Set screen_name parameter for this Google Analytics ID.
615
+ *
616
+ * @deprecated Use {@link logEvent} with `eventName` as 'screen_view' and add relevant `eventParams`.
617
+ * See {@link https://firebase.google.com/docs/analytics/screenviews | Track Screenviews}.
618
+ *
619
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
620
+ * @param screenName Screen name string to set.
621
+ */
622
+ async function setCurrentScreen$1(gtagFunction, initializationPromise, screenName, options) {
623
+ if (options && options.global) {
624
+ gtagFunction("set" /* SET */, { 'screen_name': screenName });
625
+ return Promise.resolve();
626
+ }
627
+ else {
628
+ const measurementId = await initializationPromise;
629
+ gtagFunction("config" /* CONFIG */, measurementId, {
630
+ update: true,
631
+ 'screen_name': screenName
632
+ });
633
+ }
634
+ }
635
+ /**
636
+ * Set user_id parameter for this Google Analytics ID.
637
+ *
638
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
639
+ * @param id User ID string to set
640
+ */
641
+ async function setUserId$1(gtagFunction, initializationPromise, id, options) {
642
+ if (options && options.global) {
643
+ gtagFunction("set" /* SET */, { 'user_id': id });
644
+ return Promise.resolve();
645
+ }
646
+ else {
647
+ const measurementId = await initializationPromise;
648
+ gtagFunction("config" /* CONFIG */, measurementId, {
649
+ update: true,
650
+ 'user_id': id
651
+ });
652
+ }
653
+ }
654
+ /**
655
+ * Set all other user properties other than user_id and screen_name.
656
+ *
657
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
658
+ * @param properties Map of user properties to set
659
+ */
660
+ async function setUserProperties$1(gtagFunction, initializationPromise, properties, options) {
661
+ if (options && options.global) {
662
+ const flatProperties = {};
663
+ for (const key of Object.keys(properties)) {
664
+ // use dot notation for merge behavior in gtag.js
665
+ flatProperties[`user_properties.${key}`] = properties[key];
666
+ }
667
+ gtagFunction("set" /* SET */, flatProperties);
668
+ return Promise.resolve();
669
+ }
670
+ else {
671
+ const measurementId = await initializationPromise;
672
+ gtagFunction("config" /* CONFIG */, measurementId, {
673
+ update: true,
674
+ 'user_properties': properties
675
+ });
676
+ }
677
+ }
678
+ /**
679
+ * Set whether collection is enabled for this ID.
680
+ *
681
+ * @param enabled If true, collection is enabled for this ID.
682
+ */
683
+ async function setAnalyticsCollectionEnabled$1(initializationPromise, enabled) {
684
+ const measurementId = await initializationPromise;
685
+ window[`ga-disable-${measurementId}`] = !enabled;
686
+ }
687
+ /**
688
+ * Consent parameters to default to during 'gtag' initialization.
689
+ */
690
+ let defaultConsentSettingsForInit;
691
+ /**
692
+ * Sets the variable {@link defaultConsentSettingsForInit} for use in the initialization of
693
+ * analytics.
694
+ *
695
+ * @param consentSettings Maps the applicable end user consent state for gtag.js.
696
+ */
697
+ function _setConsentDefaultForInit(consentSettings) {
698
+ defaultConsentSettingsForInit = consentSettings;
699
+ }
700
+ /**
701
+ * Sets the variable `defaultEventParametersForInit` for use in the initialization of
702
+ * analytics.
703
+ *
704
+ * @param customParams Any custom params the user may pass to gtag.js.
705
+ */
706
+ function _setDefaultEventParametersForInit(customParams) {
707
+ defaultEventParametersForInit = customParams;
708
+ }
709
+
571
710
  /**
572
711
  * @license
573
712
  * Copyright 2020 Google LLC
@@ -653,6 +792,11 @@ async function _initializeAnalytics(app, dynamicConfigPromisesList, measurementI
653
792
  if (!findGtagScriptOnPage()) {
654
793
  insertScriptTag(dataLayerName, dynamicConfig.measurementId);
655
794
  }
795
+ // Detects if there are consent settings that need to be configured.
796
+ if (defaultConsentSettingsForInit) {
797
+ gtagCore("consent" /* CONSENT */, 'default', defaultConsentSettingsForInit);
798
+ _setConsentDefaultForInit(undefined);
799
+ }
656
800
  // This command initializes gtag.js and only needs to be called once for the entire web app,
657
801
  // but since it is idempotent, we can call it multiple times.
658
802
  // We keep it together with other initialization logic for better code structure.
@@ -672,6 +816,11 @@ async function _initializeAnalytics(app, dynamicConfigPromisesList, measurementI
672
816
  // Note: This will trigger a page_view event unless 'send_page_view' is set to false in
673
817
  // `configProperties`.
674
818
  gtagCore("config" /* CONFIG */, dynamicConfig.measurementId, configProperties);
819
+ // Detects if there is data that will be set on every event logged from the SDK.
820
+ if (defaultEventParametersForInit) {
821
+ gtagCore("set" /* SET */, defaultEventParametersForInit);
822
+ _setDefaultEventParametersForInit(undefined);
823
+ }
675
824
  return dynamicConfig.measurementId;
676
825
  }
677
826
 
@@ -832,115 +981,6 @@ function factory(app, installations, options) {
832
981
  return analyticsInstance;
833
982
  }
834
983
 
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
984
  /* eslint-disable @typescript-eslint/no-explicit-any */
945
985
  /**
946
986
  * Returns an {@link Analytics} instance for the given app.
@@ -1058,6 +1098,22 @@ function setAnalyticsCollectionEnabled(analyticsInstance, enabled) {
1058
1098
  analyticsInstance = getModularInstance(analyticsInstance);
1059
1099
  setAnalyticsCollectionEnabled$1(initializationPromisesMap[analyticsInstance.app.options.appId], enabled).catch(e => logger.error(e));
1060
1100
  }
1101
+ /**
1102
+ * Adds data that will be set on every event logged from the SDK, including automatic ones.
1103
+ * With gtag's "set" command, the values passed persist on the current page and are passed with
1104
+ * all subsequent events.
1105
+ * @public
1106
+ * @param customParams - Any custom params the user may pass to gtag.js.
1107
+ */
1108
+ function setDefaultEventParameters(customParams) {
1109
+ // Check if reference to existing gtag function on window object exists
1110
+ if (wrappedGtagFunction) {
1111
+ wrappedGtagFunction("set" /* SET */, customParams);
1112
+ }
1113
+ else {
1114
+ _setDefaultEventParametersForInit(customParams);
1115
+ }
1116
+ }
1061
1117
  /**
1062
1118
  * Sends a Google Analytics event with given `eventParams`. This method
1063
1119
  * automatically associates this logged event with this Firebase web
@@ -1072,10 +1128,28 @@ function setAnalyticsCollectionEnabled(analyticsInstance, enabled) {
1072
1128
  function logEvent(analyticsInstance, eventName, eventParams, options) {
1073
1129
  analyticsInstance = getModularInstance(analyticsInstance);
1074
1130
  logEvent$1(wrappedGtagFunction, initializationPromisesMap[analyticsInstance.app.options.appId], eventName, eventParams, options).catch(e => logger.error(e));
1131
+ }
1132
+ /**
1133
+ * Sets the applicable end user consent state for this web app across all gtag references once
1134
+ * Firebase Analytics is initialized.
1135
+ *
1136
+ * Use the {@link ConsentSettings} to specify individual consent type values. By default consent
1137
+ * types are set to "granted".
1138
+ * @public
1139
+ * @param consentSettings - Maps the applicable end user consent state for gtag.js.
1140
+ */
1141
+ function setConsent(consentSettings) {
1142
+ // Check if reference to existing gtag function on window object exists
1143
+ if (wrappedGtagFunction) {
1144
+ wrappedGtagFunction("consent" /* CONSENT */, 'update', consentSettings);
1145
+ }
1146
+ else {
1147
+ _setConsentDefaultForInit(consentSettings);
1148
+ }
1075
1149
  }
1076
1150
 
1077
1151
  const name = "@firebase/analytics";
1078
- const version = "0.7.11";
1152
+ const version = "0.8.0-20220706191717";
1079
1153
 
1080
1154
  /**
1081
1155
  * Firebase Analytics
@@ -1111,5 +1185,5 @@ function registerAnalytics() {
1111
1185
  }
1112
1186
  registerAnalytics();
1113
1187
 
1114
- export { getAnalytics, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setCurrentScreen, setUserId, setUserProperties, settings };
1188
+ export { getAnalytics, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setConsent, setCurrentScreen, setDefaultEventParameters, setUserId, setUserProperties, settings };
1115
1189
  //# sourceMappingURL=index.esm2017.js.map