@firebase/analytics 0.7.10-canary.efe2000fc → 0.7.11-canary.1d3a34d7d

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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @firebase/analytics
2
2
 
3
+ ## 0.7.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [`835f1d46a`](https://github.com/firebase/firebase-js-sdk/commit/835f1d46a6780535bc660ef7dc23293350d5fe43) [#6357](https://github.com/firebase/firebase-js-sdk/pull/6357) - Fix typo in GtagConfigParams
8
+
9
+ - Updated dependencies [[`efe2000fc`](https://github.com/firebase/firebase-js-sdk/commit/efe2000fc499e2c85c4e5e0fef6741ff3bad2eb0)]:
10
+ - @firebase/util@1.6.2
11
+ - @firebase/component@0.5.16
12
+ - @firebase/installations@0.5.11
13
+
3
14
  ## 0.7.10
4
15
 
5
16
  ### Patch Changes
@@ -42,6 +42,38 @@ export declare interface AnalyticsSettings {
42
42
  config?: GtagConfigParams | EventParams;
43
43
  }
44
44
 
45
+ /**
46
+ * Consent status settings for each consent type.
47
+ * For more information, see
48
+ * {@link https://developers.google.com/tag-platform/tag-manager/templates/consent-apis
49
+ * | the GA4 reference documentation for consent state and consent types}.
50
+ * @public
51
+ */
52
+ export declare interface ConsentSettings {
53
+ /** Enables storage, such as cookies, related to advertising */
54
+ ad_storage?: ConsentStatusString;
55
+ /** Enables storage, such as cookies, related to analytics (for example, visit duration) */
56
+ analytics_storage?: ConsentStatusString;
57
+ /**
58
+ * Enables storage that supports the functionality of the website or app such as language settings
59
+ */
60
+ functionality_storage?: ConsentStatusString;
61
+ /** Enables storage related to personalization such as video recommendations */
62
+ personalization_storage?: ConsentStatusString;
63
+ /**
64
+ * Enables storage related to security such as authentication functionality, fraud prevention,
65
+ * and other user protection.
66
+ */
67
+ security_storage?: ConsentStatusString;
68
+ [key: string]: unknown;
69
+ }
70
+
71
+ /**
72
+ * Whether a particular consent type has been granted or denied.
73
+ * @public
74
+ */
75
+ export declare type ConsentStatusString = 'granted' | 'denied';
76
+
45
77
  /**
46
78
  * Standard `gtag.js` control parameters.
47
79
  * For more information, see
@@ -637,6 +669,17 @@ export declare interface Promotion {
637
669
  */
638
670
  export declare function setAnalyticsCollectionEnabled(analyticsInstance: Analytics, enabled: boolean): void;
639
671
 
672
+ /**
673
+ * Sets the applicable end user consent state for this web app across all gtag references once
674
+ * Firebase Analytics is initialized.
675
+ *
676
+ * Use the {@link ConsentSettings} to specify individual consent type values. By default consent
677
+ * types are set to "granted".
678
+ * @public
679
+ * @param consentSettings - Maps the applicable end user consent state for gtag.js.
680
+ */
681
+ export declare function setConsent(consentSettings: ConsentSettings): void;
682
+
640
683
  /**
641
684
  * Use gtag `config` command to set `screen_name`.
642
685
  *
@@ -650,6 +693,15 @@ export declare function setAnalyticsCollectionEnabled(analyticsInstance: Analyti
650
693
  */
651
694
  export declare function setCurrentScreen(analyticsInstance: Analytics, screenName: string, options?: AnalyticsCallOptions): void;
652
695
 
696
+ /**
697
+ * Adds data that will be set on every event logged from the SDK, including automatic ones.
698
+ * With gtag's "set" command, the values passed persist on the current page and are passed with
699
+ * all subsequent events.
700
+ * @public
701
+ * @param customParams - Any custom params the user may pass to gtag.js.
702
+ */
703
+ export declare function setDefaultEventParameters(customParams: CustomParams): void;
704
+
653
705
  /**
654
706
  * Configures Firebase Analytics to use custom `gtag` or `dataLayer` names.
655
707
  * Intended to be used if `gtag.js` script has been installed on
@@ -42,6 +42,38 @@ export declare interface AnalyticsSettings {
42
42
  config?: GtagConfigParams | EventParams;
43
43
  }
44
44
 
45
+ /**
46
+ * Consent status settings for each consent type.
47
+ * For more information, see
48
+ * {@link https://developers.google.com/tag-platform/tag-manager/templates/consent-apis
49
+ * | the GA4 reference documentation for consent state and consent types}.
50
+ * @public
51
+ */
52
+ export declare interface ConsentSettings {
53
+ /** Enables storage, such as cookies, related to advertising */
54
+ ad_storage?: ConsentStatusString;
55
+ /** Enables storage, such as cookies, related to analytics (for example, visit duration) */
56
+ analytics_storage?: ConsentStatusString;
57
+ /**
58
+ * Enables storage that supports the functionality of the website or app such as language settings
59
+ */
60
+ functionality_storage?: ConsentStatusString;
61
+ /** Enables storage related to personalization such as video recommendations */
62
+ personalization_storage?: ConsentStatusString;
63
+ /**
64
+ * Enables storage related to security such as authentication functionality, fraud prevention,
65
+ * and other user protection.
66
+ */
67
+ security_storage?: ConsentStatusString;
68
+ [key: string]: unknown;
69
+ }
70
+
71
+ /**
72
+ * Whether a particular consent type has been granted or denied.
73
+ * @public
74
+ */
75
+ export declare type ConsentStatusString = 'granted' | 'denied';
76
+
45
77
  /**
46
78
  * Standard `gtag.js` control parameters.
47
79
  * For more information, see
@@ -637,6 +669,17 @@ export declare interface Promotion {
637
669
  */
638
670
  export declare function setAnalyticsCollectionEnabled(analyticsInstance: Analytics, enabled: boolean): void;
639
671
 
672
+ /**
673
+ * Sets the applicable end user consent state for this web app across all gtag references once
674
+ * Firebase Analytics is initialized.
675
+ *
676
+ * Use the {@link ConsentSettings} to specify individual consent type values. By default consent
677
+ * types are set to "granted".
678
+ * @public
679
+ * @param consentSettings - Maps the applicable end user consent state for gtag.js.
680
+ */
681
+ export declare function setConsent(consentSettings: ConsentSettings): void;
682
+
640
683
  /**
641
684
  * Use gtag `config` command to set `screen_name`.
642
685
  *
@@ -650,6 +693,15 @@ export declare function setAnalyticsCollectionEnabled(analyticsInstance: Analyti
650
693
  */
651
694
  export declare function setCurrentScreen(analyticsInstance: Analytics, screenName: string, options?: AnalyticsCallOptions): void;
652
695
 
696
+ /**
697
+ * Adds data that will be set on every event logged from the SDK, including automatic ones.
698
+ * With gtag's "set" command, the values passed persist on the current page and are passed with
699
+ * all subsequent events.
700
+ * @public
701
+ * @param customParams - Any custom params the user may pass to gtag.js.
702
+ */
703
+ export declare function setDefaultEventParameters(customParams: CustomParams): void;
704
+
653
705
  /**
654
706
  * Configures Firebase Analytics to use custom `gtag` or `dataLayer` names.
655
707
  * Intended to be used if `gtag.js` script has been installed on
@@ -277,8 +277,14 @@ measurementIdToAppId) {
277
277
  _a.sent();
278
278
  return [3 /*break*/, 5];
279
279
  case 4:
280
- // If SET, second arg must be params.
281
- gtagCore("set" /* SET */, idOrNameOrParams);
280
+ if (command === "consent" /* CONSENT */) {
281
+ // If CONFIG, second arg must be measurementId.
282
+ gtagCore("consent" /* CONSENT */, 'update', gtagParams);
283
+ }
284
+ else {
285
+ // If SET, second arg must be params.
286
+ gtagCore("set" /* SET */, idOrNameOrParams);
287
+ }
282
288
  _a.label = 5;
283
289
  case 5: return [3 /*break*/, 7];
284
290
  case 6:
@@ -536,53 +542,55 @@ retryData, timeoutMillis) {
536
542
  */
537
543
  function attemptFetchDynamicConfigWithRetry(appFields, _a, signal, retryData // for testing
538
544
  ) {
545
+ var _b, _c;
539
546
  var throttleEndTimeMillis = _a.throttleEndTimeMillis, backoffCount = _a.backoffCount;
540
547
  if (retryData === void 0) { retryData = defaultRetryData; }
541
548
  return __awaiter(this, void 0, void 0, function () {
542
- var appId, measurementId, e_1, response, e_2, backoffMillis, throttleMetadata;
543
- return __generator(this, function (_b) {
544
- switch (_b.label) {
549
+ var appId, measurementId, e_1, response, e_2, error, backoffMillis, throttleMetadata;
550
+ return __generator(this, function (_d) {
551
+ switch (_d.label) {
545
552
  case 0:
546
553
  appId = appFields.appId, measurementId = appFields.measurementId;
547
- _b.label = 1;
554
+ _d.label = 1;
548
555
  case 1:
549
- _b.trys.push([1, 3, , 4]);
556
+ _d.trys.push([1, 3, , 4]);
550
557
  return [4 /*yield*/, setAbortableTimeout(signal, throttleEndTimeMillis)];
551
558
  case 2:
552
- _b.sent();
559
+ _d.sent();
553
560
  return [3 /*break*/, 4];
554
561
  case 3:
555
- e_1 = _b.sent();
562
+ e_1 = _d.sent();
556
563
  if (measurementId) {
557
564
  logger.warn("Timed out fetching this Firebase app's measurement ID from the server." +
558
565
  (" Falling back to the measurement ID " + measurementId) +
559
- (" provided in the \"measurementId\" field in the local Firebase config. [" + e_1.message + "]"));
566
+ (" provided in the \"measurementId\" field in the local Firebase config. [" + ((_b = e_1) === null || _b === void 0 ? void 0 : _b.message) + "]"));
560
567
  return [2 /*return*/, { appId: appId, measurementId: measurementId }];
561
568
  }
562
569
  throw e_1;
563
570
  case 4:
564
- _b.trys.push([4, 6, , 7]);
571
+ _d.trys.push([4, 6, , 7]);
565
572
  return [4 /*yield*/, fetchDynamicConfig(appFields)];
566
573
  case 5:
567
- response = _b.sent();
574
+ response = _d.sent();
568
575
  // Note the SDK only clears throttle state if response is success or non-retriable.
569
576
  retryData.deleteThrottleMetadata(appId);
570
577
  return [2 /*return*/, response];
571
578
  case 6:
572
- e_2 = _b.sent();
573
- if (!isRetriableError(e_2)) {
579
+ e_2 = _d.sent();
580
+ error = e_2;
581
+ if (!isRetriableError(error)) {
574
582
  retryData.deleteThrottleMetadata(appId);
575
583
  if (measurementId) {
576
584
  logger.warn("Failed to fetch this Firebase app's measurement ID from the server." +
577
585
  (" Falling back to the measurement ID " + measurementId) +
578
- (" provided in the \"measurementId\" field in the local Firebase config. [" + e_2.message + "]"));
586
+ (" provided in the \"measurementId\" field in the local Firebase config. [" + (error === null || error === void 0 ? void 0 : error.message) + "]"));
579
587
  return [2 /*return*/, { appId: appId, measurementId: measurementId }];
580
588
  }
581
589
  else {
582
590
  throw e_2;
583
591
  }
584
592
  }
585
- backoffMillis = Number(e_2.customData.httpStatus) === 503
593
+ backoffMillis = Number((_c = error === null || error === void 0 ? void 0 : error.customData) === null || _c === void 0 ? void 0 : _c.httpStatus) === 503
586
594
  ? calculateBackoffMillis(backoffCount, retryData.intervalMillis, LONG_RETRY_FACTOR)
587
595
  : calculateBackoffMillis(backoffCount, retryData.intervalMillis);
588
596
  throttleMetadata = {
@@ -660,6 +668,188 @@ var AnalyticsAbortSignal = /** @class */ (function () {
660
668
  return AnalyticsAbortSignal;
661
669
  }());
662
670
 
671
+ /**
672
+ * @license
673
+ * Copyright 2019 Google LLC
674
+ *
675
+ * Licensed under the Apache License, Version 2.0 (the "License");
676
+ * you may not use this file except in compliance with the License.
677
+ * You may obtain a copy of the License at
678
+ *
679
+ * http://www.apache.org/licenses/LICENSE-2.0
680
+ *
681
+ * Unless required by applicable law or agreed to in writing, software
682
+ * distributed under the License is distributed on an "AS IS" BASIS,
683
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
684
+ * See the License for the specific language governing permissions and
685
+ * limitations under the License.
686
+ */
687
+ /**
688
+ * Event parameters to set on 'gtag' during initialization.
689
+ */
690
+ var defaultEventParametersForInit;
691
+ /**
692
+ * Logs an analytics event through the Firebase SDK.
693
+ *
694
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
695
+ * @param eventName Google Analytics event name, choose from standard list or use a custom string.
696
+ * @param eventParams Analytics event parameters.
697
+ */
698
+ function logEvent$1(gtagFunction, initializationPromise, eventName, eventParams, options) {
699
+ return __awaiter(this, void 0, void 0, function () {
700
+ var measurementId, params;
701
+ return __generator(this, function (_a) {
702
+ switch (_a.label) {
703
+ case 0:
704
+ if (!(options && options.global)) return [3 /*break*/, 1];
705
+ gtagFunction("event" /* EVENT */, eventName, eventParams);
706
+ return [2 /*return*/];
707
+ case 1: return [4 /*yield*/, initializationPromise];
708
+ case 2:
709
+ measurementId = _a.sent();
710
+ params = __assign(__assign({}, eventParams), { 'send_to': measurementId });
711
+ gtagFunction("event" /* EVENT */, eventName, params);
712
+ _a.label = 3;
713
+ case 3: return [2 /*return*/];
714
+ }
715
+ });
716
+ });
717
+ }
718
+ /**
719
+ * Set screen_name parameter for this Google Analytics ID.
720
+ *
721
+ * @deprecated Use {@link logEvent} with `eventName` as 'screen_view' and add relevant `eventParams`.
722
+ * See {@link https://firebase.google.com/docs/analytics/screenviews | Track Screenviews}.
723
+ *
724
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
725
+ * @param screenName Screen name string to set.
726
+ */
727
+ function setCurrentScreen$1(gtagFunction, initializationPromise, screenName, options) {
728
+ return __awaiter(this, void 0, void 0, function () {
729
+ var measurementId;
730
+ return __generator(this, function (_a) {
731
+ switch (_a.label) {
732
+ case 0:
733
+ if (!(options && options.global)) return [3 /*break*/, 1];
734
+ gtagFunction("set" /* SET */, { 'screen_name': screenName });
735
+ return [2 /*return*/, Promise.resolve()];
736
+ case 1: return [4 /*yield*/, initializationPromise];
737
+ case 2:
738
+ measurementId = _a.sent();
739
+ gtagFunction("config" /* CONFIG */, measurementId, {
740
+ update: true,
741
+ 'screen_name': screenName
742
+ });
743
+ _a.label = 3;
744
+ case 3: return [2 /*return*/];
745
+ }
746
+ });
747
+ });
748
+ }
749
+ /**
750
+ * Set user_id parameter for this Google Analytics ID.
751
+ *
752
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
753
+ * @param id User ID string to set
754
+ */
755
+ function setUserId$1(gtagFunction, initializationPromise, id, options) {
756
+ return __awaiter(this, void 0, void 0, function () {
757
+ var measurementId;
758
+ return __generator(this, function (_a) {
759
+ switch (_a.label) {
760
+ case 0:
761
+ if (!(options && options.global)) return [3 /*break*/, 1];
762
+ gtagFunction("set" /* SET */, { 'user_id': id });
763
+ return [2 /*return*/, Promise.resolve()];
764
+ case 1: return [4 /*yield*/, initializationPromise];
765
+ case 2:
766
+ measurementId = _a.sent();
767
+ gtagFunction("config" /* CONFIG */, measurementId, {
768
+ update: true,
769
+ 'user_id': id
770
+ });
771
+ _a.label = 3;
772
+ case 3: return [2 /*return*/];
773
+ }
774
+ });
775
+ });
776
+ }
777
+ /**
778
+ * Set all other user properties other than user_id and screen_name.
779
+ *
780
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
781
+ * @param properties Map of user properties to set
782
+ */
783
+ function setUserProperties$1(gtagFunction, initializationPromise, properties, options) {
784
+ return __awaiter(this, void 0, void 0, function () {
785
+ var flatProperties, _i, _a, key, measurementId;
786
+ return __generator(this, function (_b) {
787
+ switch (_b.label) {
788
+ case 0:
789
+ if (!(options && options.global)) return [3 /*break*/, 1];
790
+ flatProperties = {};
791
+ for (_i = 0, _a = Object.keys(properties); _i < _a.length; _i++) {
792
+ key = _a[_i];
793
+ // use dot notation for merge behavior in gtag.js
794
+ flatProperties["user_properties." + key] = properties[key];
795
+ }
796
+ gtagFunction("set" /* SET */, flatProperties);
797
+ return [2 /*return*/, Promise.resolve()];
798
+ case 1: return [4 /*yield*/, initializationPromise];
799
+ case 2:
800
+ measurementId = _b.sent();
801
+ gtagFunction("config" /* CONFIG */, measurementId, {
802
+ update: true,
803
+ 'user_properties': properties
804
+ });
805
+ _b.label = 3;
806
+ case 3: return [2 /*return*/];
807
+ }
808
+ });
809
+ });
810
+ }
811
+ /**
812
+ * Set whether collection is enabled for this ID.
813
+ *
814
+ * @param enabled If true, collection is enabled for this ID.
815
+ */
816
+ function setAnalyticsCollectionEnabled$1(initializationPromise, enabled) {
817
+ return __awaiter(this, void 0, void 0, function () {
818
+ var measurementId;
819
+ return __generator(this, function (_a) {
820
+ switch (_a.label) {
821
+ case 0: return [4 /*yield*/, initializationPromise];
822
+ case 1:
823
+ measurementId = _a.sent();
824
+ window["ga-disable-" + measurementId] = !enabled;
825
+ return [2 /*return*/];
826
+ }
827
+ });
828
+ });
829
+ }
830
+ /**
831
+ * Consent parameters to default to during 'gtag' initialization.
832
+ */
833
+ var defaultConsentSettingsForInit;
834
+ /**
835
+ * Sets the variable {@link defaultConsentSettingsForInit} for use in the initialization of
836
+ * analytics.
837
+ *
838
+ * @param consentSettings Maps the applicable end user consent state for gtag.js.
839
+ */
840
+ function _setConsentDefaultForInit(consentSettings) {
841
+ defaultConsentSettingsForInit = consentSettings;
842
+ }
843
+ /**
844
+ * Sets the variable `defaultEventParametersForInit` for use in the initialization of
845
+ * analytics.
846
+ *
847
+ * @param customParams Any custom params the user may pass to gtag.js.
848
+ */
849
+ function _setDefaultEventParametersForInit(customParams) {
850
+ defaultEventParametersForInit = customParams;
851
+ }
852
+
663
853
  /**
664
854
  * @license
665
855
  * Copyright 2020 Google LLC
@@ -760,6 +950,11 @@ function _initializeAnalytics(app, dynamicConfigPromisesList, measurementIdToApp
760
950
  if (!findGtagScriptOnPage()) {
761
951
  insertScriptTag(dataLayerName, dynamicConfig.measurementId);
762
952
  }
953
+ // Detects if there are consent settings that need to be configured.
954
+ if (defaultConsentSettingsForInit) {
955
+ gtagCore("consent" /* CONSENT */, 'default', defaultConsentSettingsForInit);
956
+ _setConsentDefaultForInit(undefined);
957
+ }
763
958
  // This command initializes gtag.js and only needs to be called once for the entire web app,
764
959
  // but since it is idempotent, we can call it multiple times.
765
960
  // We keep it together with other initialization logic for better code structure.
@@ -777,6 +972,11 @@ function _initializeAnalytics(app, dynamicConfigPromisesList, measurementIdToApp
777
972
  // Note: This will trigger a page_view event unless 'send_page_view' is set to false in
778
973
  // `configProperties`.
779
974
  gtagCore("config" /* CONFIG */, dynamicConfig.measurementId, configProperties);
975
+ // Detects if there is data that will be set on every event logged from the SDK.
976
+ if (defaultEventParametersForInit) {
977
+ gtagCore("set" /* SET */, defaultEventParametersForInit);
978
+ _setDefaultEventParametersForInit(undefined);
979
+ }
780
980
  return [2 /*return*/, dynamicConfig.measurementId];
781
981
  }
782
982
  });
@@ -941,162 +1141,6 @@ function factory(app, installations, options) {
941
1141
  return analyticsInstance;
942
1142
  }
943
1143
 
944
- /**
945
- * @license
946
- * Copyright 2019 Google LLC
947
- *
948
- * Licensed under the Apache License, Version 2.0 (the "License");
949
- * you may not use this file except in compliance with the License.
950
- * You may obtain a copy of the License at
951
- *
952
- * http://www.apache.org/licenses/LICENSE-2.0
953
- *
954
- * Unless required by applicable law or agreed to in writing, software
955
- * distributed under the License is distributed on an "AS IS" BASIS,
956
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
957
- * See the License for the specific language governing permissions and
958
- * limitations under the License.
959
- */
960
- /**
961
- * Logs an analytics event through the Firebase SDK.
962
- *
963
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
964
- * @param eventName Google Analytics event name, choose from standard list or use a custom string.
965
- * @param eventParams Analytics event parameters.
966
- */
967
- function logEvent$1(gtagFunction, initializationPromise, eventName, eventParams, options) {
968
- return __awaiter(this, void 0, void 0, function () {
969
- var measurementId, params;
970
- return __generator(this, function (_a) {
971
- switch (_a.label) {
972
- case 0:
973
- if (!(options && options.global)) return [3 /*break*/, 1];
974
- gtagFunction("event" /* EVENT */, eventName, eventParams);
975
- return [2 /*return*/];
976
- case 1: return [4 /*yield*/, initializationPromise];
977
- case 2:
978
- measurementId = _a.sent();
979
- params = __assign(__assign({}, eventParams), { 'send_to': measurementId });
980
- gtagFunction("event" /* EVENT */, eventName, params);
981
- _a.label = 3;
982
- case 3: return [2 /*return*/];
983
- }
984
- });
985
- });
986
- }
987
- /**
988
- * Set screen_name parameter for this Google Analytics ID.
989
- *
990
- * @deprecated Use {@link logEvent} with `eventName` as 'screen_view' and add relevant `eventParams`.
991
- * See {@link https://firebase.google.com/docs/analytics/screenviews | Track Screenviews}.
992
- *
993
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
994
- * @param screenName Screen name string to set.
995
- */
996
- function setCurrentScreen$1(gtagFunction, initializationPromise, screenName, options) {
997
- return __awaiter(this, void 0, void 0, function () {
998
- var measurementId;
999
- return __generator(this, function (_a) {
1000
- switch (_a.label) {
1001
- case 0:
1002
- if (!(options && options.global)) return [3 /*break*/, 1];
1003
- gtagFunction("set" /* SET */, { 'screen_name': screenName });
1004
- return [2 /*return*/, Promise.resolve()];
1005
- case 1: return [4 /*yield*/, initializationPromise];
1006
- case 2:
1007
- measurementId = _a.sent();
1008
- gtagFunction("config" /* CONFIG */, measurementId, {
1009
- update: true,
1010
- 'screen_name': screenName
1011
- });
1012
- _a.label = 3;
1013
- case 3: return [2 /*return*/];
1014
- }
1015
- });
1016
- });
1017
- }
1018
- /**
1019
- * Set user_id parameter for this Google Analytics ID.
1020
- *
1021
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
1022
- * @param id User ID string to set
1023
- */
1024
- function setUserId$1(gtagFunction, initializationPromise, id, options) {
1025
- return __awaiter(this, void 0, void 0, function () {
1026
- var measurementId;
1027
- return __generator(this, function (_a) {
1028
- switch (_a.label) {
1029
- case 0:
1030
- if (!(options && options.global)) return [3 /*break*/, 1];
1031
- gtagFunction("set" /* SET */, { 'user_id': id });
1032
- return [2 /*return*/, Promise.resolve()];
1033
- case 1: return [4 /*yield*/, initializationPromise];
1034
- case 2:
1035
- measurementId = _a.sent();
1036
- gtagFunction("config" /* CONFIG */, measurementId, {
1037
- update: true,
1038
- 'user_id': id
1039
- });
1040
- _a.label = 3;
1041
- case 3: return [2 /*return*/];
1042
- }
1043
- });
1044
- });
1045
- }
1046
- /**
1047
- * Set all other user properties other than user_id and screen_name.
1048
- *
1049
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
1050
- * @param properties Map of user properties to set
1051
- */
1052
- function setUserProperties$1(gtagFunction, initializationPromise, properties, options) {
1053
- return __awaiter(this, void 0, void 0, function () {
1054
- var flatProperties, _i, _a, key, measurementId;
1055
- return __generator(this, function (_b) {
1056
- switch (_b.label) {
1057
- case 0:
1058
- if (!(options && options.global)) return [3 /*break*/, 1];
1059
- flatProperties = {};
1060
- for (_i = 0, _a = Object.keys(properties); _i < _a.length; _i++) {
1061
- key = _a[_i];
1062
- // use dot notation for merge behavior in gtag.js
1063
- flatProperties["user_properties." + key] = properties[key];
1064
- }
1065
- gtagFunction("set" /* SET */, flatProperties);
1066
- return [2 /*return*/, Promise.resolve()];
1067
- case 1: return [4 /*yield*/, initializationPromise];
1068
- case 2:
1069
- measurementId = _b.sent();
1070
- gtagFunction("config" /* CONFIG */, measurementId, {
1071
- update: true,
1072
- 'user_properties': properties
1073
- });
1074
- _b.label = 3;
1075
- case 3: return [2 /*return*/];
1076
- }
1077
- });
1078
- });
1079
- }
1080
- /**
1081
- * Set whether collection is enabled for this ID.
1082
- *
1083
- * @param enabled If true, collection is enabled for this ID.
1084
- */
1085
- function setAnalyticsCollectionEnabled$1(initializationPromise, enabled) {
1086
- return __awaiter(this, void 0, void 0, function () {
1087
- var measurementId;
1088
- return __generator(this, function (_a) {
1089
- switch (_a.label) {
1090
- case 0: return [4 /*yield*/, initializationPromise];
1091
- case 1:
1092
- measurementId = _a.sent();
1093
- window["ga-disable-" + measurementId] = !enabled;
1094
- return [2 /*return*/];
1095
- }
1096
- });
1097
- });
1098
- }
1099
-
1100
1144
  /* eslint-disable @typescript-eslint/no-explicit-any */
1101
1145
  /**
1102
1146
  * Returns an {@link Analytics} instance for the given app.
@@ -1228,6 +1272,22 @@ function setAnalyticsCollectionEnabled(analyticsInstance, enabled) {
1228
1272
  analyticsInstance = getModularInstance(analyticsInstance);
1229
1273
  setAnalyticsCollectionEnabled$1(initializationPromisesMap[analyticsInstance.app.options.appId], enabled).catch(function (e) { return logger.error(e); });
1230
1274
  }
1275
+ /**
1276
+ * Adds data that will be set on every event logged from the SDK, including automatic ones.
1277
+ * With gtag's "set" command, the values passed persist on the current page and are passed with
1278
+ * all subsequent events.
1279
+ * @public
1280
+ * @param customParams - Any custom params the user may pass to gtag.js.
1281
+ */
1282
+ function setDefaultEventParameters(customParams) {
1283
+ // Check if reference to existing gtag function on window object exists
1284
+ if (wrappedGtagFunction) {
1285
+ wrappedGtagFunction("set" /* SET */, customParams);
1286
+ }
1287
+ else {
1288
+ _setDefaultEventParametersForInit(customParams);
1289
+ }
1290
+ }
1231
1291
  /**
1232
1292
  * Sends a Google Analytics event with given `eventParams`. This method
1233
1293
  * automatically associates this logged event with this Firebase web
@@ -1242,10 +1302,28 @@ function setAnalyticsCollectionEnabled(analyticsInstance, enabled) {
1242
1302
  function logEvent(analyticsInstance, eventName, eventParams, options) {
1243
1303
  analyticsInstance = getModularInstance(analyticsInstance);
1244
1304
  logEvent$1(wrappedGtagFunction, initializationPromisesMap[analyticsInstance.app.options.appId], eventName, eventParams, options).catch(function (e) { return logger.error(e); });
1305
+ }
1306
+ /**
1307
+ * Sets the applicable end user consent state for this web app across all gtag references once
1308
+ * Firebase Analytics is initialized.
1309
+ *
1310
+ * Use the {@link ConsentSettings} to specify individual consent type values. By default consent
1311
+ * types are set to "granted".
1312
+ * @public
1313
+ * @param consentSettings - Maps the applicable end user consent state for gtag.js.
1314
+ */
1315
+ function setConsent(consentSettings) {
1316
+ // Check if reference to existing gtag function on window object exists
1317
+ if (wrappedGtagFunction) {
1318
+ wrappedGtagFunction("consent" /* CONSENT */, 'update', consentSettings);
1319
+ }
1320
+ else {
1321
+ _setConsentDefaultForInit(consentSettings);
1322
+ }
1245
1323
  }
1246
1324
 
1247
1325
  var name = "@firebase/analytics";
1248
- var version = "0.7.10-canary.efe2000fc";
1326
+ var version = "0.7.11-canary.1d3a34d7d";
1249
1327
 
1250
1328
  /**
1251
1329
  * Firebase Analytics
@@ -1282,5 +1360,5 @@ function registerAnalytics() {
1282
1360
  }
1283
1361
  registerAnalytics();
1284
1362
 
1285
- export { getAnalytics, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setCurrentScreen, setUserId, setUserProperties, settings };
1363
+ export { getAnalytics, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setConsent, setCurrentScreen, setDefaultEventParameters, setUserId, setUserProperties, settings };
1286
1364
  //# sourceMappingURL=index.esm.js.map