@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.
@@ -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);
@@ -456,6 +460,7 @@ retryData = defaultRetryData, timeoutMillis) {
456
460
  */
457
461
  async function attemptFetchDynamicConfigWithRetry(appFields, { throttleEndTimeMillis, backoffCount }, signal, retryData = defaultRetryData // for testing
458
462
  ) {
463
+ var _a, _b;
459
464
  const { appId, measurementId } = appFields;
460
465
  // Starts with a (potentially zero) timeout to support resumption from stored state.
461
466
  // Ensures the throttle end time is honored if the last attempt timed out.
@@ -467,7 +472,7 @@ async function attemptFetchDynamicConfigWithRetry(appFields, { throttleEndTimeMi
467
472
  if (measurementId) {
468
473
  logger.warn(`Timed out fetching this Firebase app's measurement ID from the server.` +
469
474
  ` Falling back to the measurement ID ${measurementId}` +
470
- ` provided in the "measurementId" field in the local Firebase config. [${e.message}]`);
475
+ ` provided in the "measurementId" field in the local Firebase config. [${(_a = e) === null || _a === void 0 ? void 0 : _a.message}]`);
471
476
  return { appId, measurementId };
472
477
  }
473
478
  throw e;
@@ -479,19 +484,20 @@ async function attemptFetchDynamicConfigWithRetry(appFields, { throttleEndTimeMi
479
484
  return response;
480
485
  }
481
486
  catch (e) {
482
- if (!isRetriableError(e)) {
487
+ const error = e;
488
+ if (!isRetriableError(error)) {
483
489
  retryData.deleteThrottleMetadata(appId);
484
490
  if (measurementId) {
485
491
  logger.warn(`Failed to fetch this Firebase app's measurement ID from the server.` +
486
492
  ` Falling back to the measurement ID ${measurementId}` +
487
- ` provided in the "measurementId" field in the local Firebase config. [${e.message}]`);
493
+ ` provided in the "measurementId" field in the local Firebase config. [${error === null || error === void 0 ? void 0 : error.message}]`);
488
494
  return { appId, measurementId };
489
495
  }
490
496
  else {
491
497
  throw e;
492
498
  }
493
499
  }
494
- const backoffMillis = Number(e.customData.httpStatus) === 503
500
+ const backoffMillis = Number((_b = error === null || error === void 0 ? void 0 : error.customData) === null || _b === void 0 ? void 0 : _b.httpStatus) === 503
495
501
  ? calculateBackoffMillis(backoffCount, retryData.intervalMillis, LONG_RETRY_FACTOR)
496
502
  : calculateBackoffMillis(backoffCount, retryData.intervalMillis);
497
503
  // Increments backoff state.
@@ -566,6 +572,141 @@ class AnalyticsAbortSignal {
566
572
  }
567
573
  }
568
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
+
569
710
  /**
570
711
  * @license
571
712
  * Copyright 2020 Google LLC
@@ -651,6 +792,11 @@ async function _initializeAnalytics(app, dynamicConfigPromisesList, measurementI
651
792
  if (!findGtagScriptOnPage()) {
652
793
  insertScriptTag(dataLayerName, dynamicConfig.measurementId);
653
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
+ }
654
800
  // This command initializes gtag.js and only needs to be called once for the entire web app,
655
801
  // but since it is idempotent, we can call it multiple times.
656
802
  // We keep it together with other initialization logic for better code structure.
@@ -670,6 +816,11 @@ async function _initializeAnalytics(app, dynamicConfigPromisesList, measurementI
670
816
  // Note: This will trigger a page_view event unless 'send_page_view' is set to false in
671
817
  // `configProperties`.
672
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
+ }
673
824
  return dynamicConfig.measurementId;
674
825
  }
675
826
 
@@ -830,115 +981,6 @@ function factory(app, installations, options) {
830
981
  return analyticsInstance;
831
982
  }
832
983
 
833
- /**
834
- * @license
835
- * Copyright 2019 Google LLC
836
- *
837
- * Licensed under the Apache License, Version 2.0 (the "License");
838
- * you may not use this file except in compliance with the License.
839
- * You may obtain a copy of the License at
840
- *
841
- * http://www.apache.org/licenses/LICENSE-2.0
842
- *
843
- * Unless required by applicable law or agreed to in writing, software
844
- * distributed under the License is distributed on an "AS IS" BASIS,
845
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
846
- * See the License for the specific language governing permissions and
847
- * limitations under the License.
848
- */
849
- /**
850
- * Logs an analytics event through the Firebase SDK.
851
- *
852
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
853
- * @param eventName Google Analytics event name, choose from standard list or use a custom string.
854
- * @param eventParams Analytics event parameters.
855
- */
856
- async function logEvent$1(gtagFunction, initializationPromise, eventName, eventParams, options) {
857
- if (options && options.global) {
858
- gtagFunction("event" /* EVENT */, eventName, eventParams);
859
- return;
860
- }
861
- else {
862
- const measurementId = await initializationPromise;
863
- const params = Object.assign(Object.assign({}, eventParams), { 'send_to': measurementId });
864
- gtagFunction("event" /* EVENT */, eventName, params);
865
- }
866
- }
867
- /**
868
- * Set screen_name parameter for this Google Analytics ID.
869
- *
870
- * @deprecated Use {@link logEvent} with `eventName` as 'screen_view' and add relevant `eventParams`.
871
- * See {@link https://firebase.google.com/docs/analytics/screenviews | Track Screenviews}.
872
- *
873
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
874
- * @param screenName Screen name string to set.
875
- */
876
- async function setCurrentScreen$1(gtagFunction, initializationPromise, screenName, options) {
877
- if (options && options.global) {
878
- gtagFunction("set" /* SET */, { 'screen_name': screenName });
879
- return Promise.resolve();
880
- }
881
- else {
882
- const measurementId = await initializationPromise;
883
- gtagFunction("config" /* CONFIG */, measurementId, {
884
- update: true,
885
- 'screen_name': screenName
886
- });
887
- }
888
- }
889
- /**
890
- * Set user_id parameter for this Google Analytics ID.
891
- *
892
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
893
- * @param id User ID string to set
894
- */
895
- async function setUserId$1(gtagFunction, initializationPromise, id, options) {
896
- if (options && options.global) {
897
- gtagFunction("set" /* SET */, { 'user_id': id });
898
- return Promise.resolve();
899
- }
900
- else {
901
- const measurementId = await initializationPromise;
902
- gtagFunction("config" /* CONFIG */, measurementId, {
903
- update: true,
904
- 'user_id': id
905
- });
906
- }
907
- }
908
- /**
909
- * Set all other user properties other than user_id and screen_name.
910
- *
911
- * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
912
- * @param properties Map of user properties to set
913
- */
914
- async function setUserProperties$1(gtagFunction, initializationPromise, properties, options) {
915
- if (options && options.global) {
916
- const flatProperties = {};
917
- for (const key of Object.keys(properties)) {
918
- // use dot notation for merge behavior in gtag.js
919
- flatProperties[`user_properties.${key}`] = properties[key];
920
- }
921
- gtagFunction("set" /* SET */, flatProperties);
922
- return Promise.resolve();
923
- }
924
- else {
925
- const measurementId = await initializationPromise;
926
- gtagFunction("config" /* CONFIG */, measurementId, {
927
- update: true,
928
- 'user_properties': properties
929
- });
930
- }
931
- }
932
- /**
933
- * Set whether collection is enabled for this ID.
934
- *
935
- * @param enabled If true, collection is enabled for this ID.
936
- */
937
- async function setAnalyticsCollectionEnabled$1(initializationPromise, enabled) {
938
- const measurementId = await initializationPromise;
939
- window[`ga-disable-${measurementId}`] = !enabled;
940
- }
941
-
942
984
  /* eslint-disable @typescript-eslint/no-explicit-any */
943
985
  /**
944
986
  * Returns an {@link Analytics} instance for the given app.
@@ -1056,6 +1098,22 @@ function setAnalyticsCollectionEnabled(analyticsInstance, enabled) {
1056
1098
  analyticsInstance = getModularInstance(analyticsInstance);
1057
1099
  setAnalyticsCollectionEnabled$1(initializationPromisesMap[analyticsInstance.app.options.appId], enabled).catch(e => logger.error(e));
1058
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
+ }
1059
1117
  /**
1060
1118
  * Sends a Google Analytics event with given `eventParams`. This method
1061
1119
  * automatically associates this logged event with this Firebase web
@@ -1070,10 +1128,28 @@ function setAnalyticsCollectionEnabled(analyticsInstance, enabled) {
1070
1128
  function logEvent(analyticsInstance, eventName, eventParams, options) {
1071
1129
  analyticsInstance = getModularInstance(analyticsInstance);
1072
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
+ }
1073
1149
  }
1074
1150
 
1075
1151
  const name = "@firebase/analytics";
1076
- const version = "0.7.10-canary.efe2000fc";
1152
+ const version = "0.7.11-canary.1d3a34d7d";
1077
1153
 
1078
1154
  /**
1079
1155
  * Firebase Analytics
@@ -1109,5 +1185,5 @@ function registerAnalytics() {
1109
1185
  }
1110
1186
  registerAnalytics();
1111
1187
 
1112
- export { getAnalytics, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setCurrentScreen, setUserId, setUserProperties, settings };
1188
+ export { getAnalytics, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setConsent, setCurrentScreen, setDefaultEventParameters, setUserId, setUserProperties, settings };
1113
1189
  //# sourceMappingURL=index.esm2017.js.map