@firebase/analytics 0.7.11-canary.280c25605 → 0.7.11-canary.5edd81fb5

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.
@@ -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
  *
@@ -655,7 +698,7 @@ export declare function setCurrentScreen(analyticsInstance: Analytics, screenNam
655
698
  * With gtag's "set" command, the values passed persist on the current page and are passed with
656
699
  * all subsequent events.
657
700
  * @public
658
- * @param customParams Any custom params the user may pass to gtag.js.
701
+ * @param customParams - Any custom params the user may pass to gtag.js.
659
702
  */
660
703
  export declare function setDefaultEventParameters(customParams: CustomParams): void;
661
704
 
@@ -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
  *
@@ -655,7 +698,7 @@ export declare function setCurrentScreen(analyticsInstance: Analytics, screenNam
655
698
  * With gtag's "set" command, the values passed persist on the current page and are passed with
656
699
  * all subsequent events.
657
700
  * @public
658
- * @param customParams Any custom params the user may pass to gtag.js.
701
+ * @param customParams - Any custom params the user may pass to gtag.js.
659
702
  */
660
703
  export declare function setDefaultEventParameters(customParams: CustomParams): void;
661
704
 
@@ -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:
@@ -821,6 +827,19 @@ function setAnalyticsCollectionEnabled$1(initializationPromise, enabled) {
821
827
  });
822
828
  });
823
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
+ }
824
843
  /**
825
844
  * Sets the variable `defaultEventParametersForInit` for use in the initialization of
826
845
  * analytics.
@@ -931,6 +950,11 @@ function _initializeAnalytics(app, dynamicConfigPromisesList, measurementIdToApp
931
950
  if (!findGtagScriptOnPage()) {
932
951
  insertScriptTag(dataLayerName, dynamicConfig.measurementId);
933
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
+ }
934
958
  // This command initializes gtag.js and only needs to be called once for the entire web app,
935
959
  // but since it is idempotent, we can call it multiple times.
936
960
  // We keep it together with other initialization logic for better code structure.
@@ -1253,7 +1277,7 @@ function setAnalyticsCollectionEnabled(analyticsInstance, enabled) {
1253
1277
  * With gtag's "set" command, the values passed persist on the current page and are passed with
1254
1278
  * all subsequent events.
1255
1279
  * @public
1256
- * @param customParams Any custom params the user may pass to gtag.js.
1280
+ * @param customParams - Any custom params the user may pass to gtag.js.
1257
1281
  */
1258
1282
  function setDefaultEventParameters(customParams) {
1259
1283
  // Check if reference to existing gtag function on window object exists
@@ -1278,10 +1302,28 @@ function setDefaultEventParameters(customParams) {
1278
1302
  function logEvent(analyticsInstance, eventName, eventParams, options) {
1279
1303
  analyticsInstance = getModularInstance(analyticsInstance);
1280
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
+ }
1281
1323
  }
1282
1324
 
1283
1325
  var name = "@firebase/analytics";
1284
- var version = "0.7.11-canary.280c25605";
1326
+ var version = "0.7.11-canary.5edd81fb5";
1285
1327
 
1286
1328
  /**
1287
1329
  * Firebase Analytics
@@ -1318,5 +1360,5 @@ function registerAnalytics() {
1318
1360
  }
1319
1361
  registerAnalytics();
1320
1362
 
1321
- export { getAnalytics, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setCurrentScreen, setDefaultEventParameters, setUserId, setUserProperties, settings };
1363
+ export { getAnalytics, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setConsent, setCurrentScreen, setDefaultEventParameters, setUserId, setUserProperties, settings };
1322
1364
  //# sourceMappingURL=index.esm.js.map