react-query-firebase 1.2.0 → 1.2.1

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.
@@ -1,4 +1,5 @@
1
1
  import React, { PropsWithChildren } from "react";
2
+ import { ConsentSettings } from "firebase/analytics";
2
3
  import { RemoteConfigSettings } from "firebase/remote-config";
3
4
  import { FirebaseOptions } from "firebase/app";
4
5
  /**
@@ -57,6 +58,19 @@ export type FirebaseContextProviderProps = PropsWithChildren & {
57
58
  * @defaultValue `true`
58
59
  */
59
60
  analyticsEnabled?: boolean;
61
+ /**
62
+ * Default user consent settings. Make sure to either use a consent platform or install custom consent form for a certain regions.
63
+ * @defaultValue {
64
+ * ad_personalization: "denied",
65
+ * ad_storage: "denied",
66
+ * ad_user_data: "denied",
67
+ * analytics_storage: "denied",
68
+ * functionality_storage: "denied",
69
+ * personalization_storage: "denied",
70
+ * security_storage: "denied"
71
+ * }
72
+ */
73
+ defaultConsent?: ConsentSettings;
60
74
  /**
61
75
  * Flag indicating whether Firebase Firestore should be enabled.
62
76
  * @defaultValue `true`
@@ -1,7 +1,7 @@
1
1
  import React, { useMemo } from "react";
2
2
  import { FirebaseContext } from "./FirebaseContext";
3
3
  import { connectAuthEmulator, getAuth } from "firebase/auth";
4
- import { getAnalytics } from "firebase/analytics";
4
+ import { getAnalytics, setAnalyticsCollectionEnabled, setConsent } from "firebase/analytics";
5
5
  import { getRemoteConfig } from "firebase/remote-config";
6
6
  import { connectFirestoreEmulator, getFirestore } from "firebase/firestore";
7
7
  import { initializeApp } from "firebase/app";
@@ -28,7 +28,7 @@ import { initializeApp } from "firebase/app";
28
28
  * };
29
29
  * ```
30
30
  */
31
- export const FirebaseContextProvider = ({ emulators, options, children, authEnabled = true, firestoreEnabled = true, analyticsEnabled = true, remoteConfigEnabled = true, remoteConfigSettings, remoteConfigDefaults = {} }) => {
31
+ export const FirebaseContextProvider = ({ emulators, options, children, authEnabled = true, firestoreEnabled = true, analyticsEnabled = true, defaultConsent = {}, remoteConfigEnabled = true, remoteConfigSettings, remoteConfigDefaults = {} }) => {
32
32
  const firebase = useMemo(() => {
33
33
  return initializeApp(options);
34
34
  }, [options]);
@@ -50,9 +50,20 @@ export const FirebaseContextProvider = ({ emulators, options, children, authEnab
50
50
  }
51
51
  value.auth = auth;
52
52
  }
53
+ setConsent({
54
+ ad_personalization: "denied",
55
+ ad_storage: "denied",
56
+ ad_user_data: "denied",
57
+ analytics_storage: "denied",
58
+ functionality_storage: "denied",
59
+ personalization_storage: "denied",
60
+ security_storage: "denied",
61
+ ...defaultConsent
62
+ });
53
63
  if (analyticsEnabled && options.measurementId && typeof window !== "undefined") {
54
64
  const analytics = getAnalytics(firebase);
55
65
  value.analytics = analytics;
66
+ setAnalyticsCollectionEnabled(analytics, defaultConsent?.analytics_storage === "granted");
56
67
  }
57
68
  if (remoteConfigEnabled && typeof window !== "undefined") {
58
69
  const remoteConfig = getRemoteConfig(firebase);
package/package.json CHANGED
@@ -60,5 +60,5 @@
60
60
  "docs:build": "vitepress build docs",
61
61
  "docs:preview": "vitepress preview docs"
62
62
  },
63
- "version": "1.2.0"
63
+ "version": "1.2.1"
64
64
  }
@@ -1,7 +1,7 @@
1
1
  import React, { PropsWithChildren, useMemo } from "react";
2
2
  import { FirebaseContext } from "./FirebaseContext";
3
3
  import { connectAuthEmulator, getAuth } from "firebase/auth";
4
- import { getAnalytics } from "firebase/analytics";
4
+ import { ConsentSettings, getAnalytics, setAnalyticsCollectionEnabled, setConsent } from "firebase/analytics";
5
5
  import { getRemoteConfig, RemoteConfigSettings } from "firebase/remote-config";
6
6
  import { connectFirestoreEmulator, getFirestore } from "firebase/firestore";
7
7
  import { FirebaseOptions, initializeApp } from "firebase/app";
@@ -65,6 +65,19 @@ export type FirebaseContextProviderProps = PropsWithChildren & {
65
65
  * @defaultValue `true`
66
66
  */
67
67
  analyticsEnabled?: boolean;
68
+ /**
69
+ * Default user consent settings. Make sure to either use a consent platform or install custom consent form for a certain regions.
70
+ * @defaultValue {
71
+ * ad_personalization: "denied",
72
+ * ad_storage: "denied",
73
+ * ad_user_data: "denied",
74
+ * analytics_storage: "denied",
75
+ * functionality_storage: "denied",
76
+ * personalization_storage: "denied",
77
+ * security_storage: "denied"
78
+ * }
79
+ */
80
+ defaultConsent?: ConsentSettings;
68
81
  /**
69
82
  * Flag indicating whether Firebase Firestore should be enabled.
70
83
  * @defaultValue `true`
@@ -116,6 +129,7 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
116
129
  authEnabled = true,
117
130
  firestoreEnabled = true,
118
131
  analyticsEnabled = true,
132
+ defaultConsent = {},
119
133
  remoteConfigEnabled = true,
120
134
  remoteConfigSettings,
121
135
  remoteConfigDefaults = {}
@@ -147,9 +161,22 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
147
161
  value.auth = auth;
148
162
  }
149
163
 
164
+ setConsent({
165
+ ad_personalization: "denied",
166
+ ad_storage: "denied",
167
+ ad_user_data: "denied",
168
+ analytics_storage: "denied",
169
+ functionality_storage: "denied",
170
+ personalization_storage: "denied",
171
+ security_storage: "denied",
172
+ ...defaultConsent
173
+ });
174
+
150
175
  if (analyticsEnabled && options.measurementId && typeof window !== "undefined") {
151
176
  const analytics = getAnalytics(firebase);
152
177
  value.analytics = analytics;
178
+
179
+ setAnalyticsCollectionEnabled(analytics, defaultConsent?.analytics_storage === "granted");
153
180
  }
154
181
 
155
182
  if (remoteConfigEnabled && typeof window !== "undefined") {