react-query-firebase 1.2.0 → 1.2.2
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
|
+
consentSettings?: ConsentSettings;
|
|
60
74
|
/**
|
|
61
75
|
* Flag indicating whether Firebase Firestore should be enabled.
|
|
62
76
|
* @defaultValue `true`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React, { useMemo } from "react";
|
|
1
|
+
import React, { useEffect, 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,10 +28,22 @@ 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, consentSettings = {}, remoteConfigEnabled = true, remoteConfigSettings, remoteConfigDefaults = {} }) => {
|
|
32
32
|
const firebase = useMemo(() => {
|
|
33
33
|
return initializeApp(options);
|
|
34
34
|
}, [options]);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
setConsent({
|
|
37
|
+
ad_personalization: "denied",
|
|
38
|
+
ad_storage: "denied",
|
|
39
|
+
ad_user_data: "denied",
|
|
40
|
+
analytics_storage: "denied",
|
|
41
|
+
functionality_storage: "denied",
|
|
42
|
+
personalization_storage: "denied",
|
|
43
|
+
security_storage: "denied",
|
|
44
|
+
...consentSettings
|
|
45
|
+
});
|
|
46
|
+
}, [consentSettings]);
|
|
35
47
|
const contextValue = useMemo(() => {
|
|
36
48
|
const value = {};
|
|
37
49
|
if (firestoreEnabled) {
|
|
@@ -65,5 +77,10 @@ export const FirebaseContextProvider = ({ emulators, options, children, authEnab
|
|
|
65
77
|
}
|
|
66
78
|
return { firebase, ...value };
|
|
67
79
|
}, [firebase]);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (contextValue.analytics) {
|
|
82
|
+
setAnalyticsCollectionEnabled(contextValue.analytics, consentSettings?.analytics_storage === "granted");
|
|
83
|
+
}
|
|
84
|
+
}, [consentSettings]);
|
|
68
85
|
return (React.createElement(FirebaseContext.Provider, { value: contextValue }, children));
|
|
69
86
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React, { PropsWithChildren, useMemo } from "react";
|
|
1
|
+
import React, { PropsWithChildren, useEffect, 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
|
+
consentSettings?: 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
|
+
consentSettings = {},
|
|
119
133
|
remoteConfigEnabled = true,
|
|
120
134
|
remoteConfigSettings,
|
|
121
135
|
remoteConfigDefaults = {}
|
|
@@ -124,6 +138,19 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
|
|
|
124
138
|
return initializeApp(options);
|
|
125
139
|
}, [options]);
|
|
126
140
|
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
setConsent({
|
|
143
|
+
ad_personalization: "denied",
|
|
144
|
+
ad_storage: "denied",
|
|
145
|
+
ad_user_data: "denied",
|
|
146
|
+
analytics_storage: "denied",
|
|
147
|
+
functionality_storage: "denied",
|
|
148
|
+
personalization_storage: "denied",
|
|
149
|
+
security_storage: "denied",
|
|
150
|
+
...consentSettings
|
|
151
|
+
});
|
|
152
|
+
}, [consentSettings]);
|
|
153
|
+
|
|
127
154
|
const contextValue = useMemo(() => {
|
|
128
155
|
const value: Partial<React.ContextType<typeof FirebaseContext>> = {};
|
|
129
156
|
|
|
@@ -165,6 +192,12 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
|
|
|
165
192
|
return { firebase, ...value };
|
|
166
193
|
}, [firebase]);
|
|
167
194
|
|
|
195
|
+
useEffect(() => {
|
|
196
|
+
if (contextValue.analytics) {
|
|
197
|
+
setAnalyticsCollectionEnabled(contextValue.analytics, consentSettings?.analytics_storage === "granted");
|
|
198
|
+
}
|
|
199
|
+
}, [consentSettings]);
|
|
200
|
+
|
|
168
201
|
return (
|
|
169
202
|
<FirebaseContext.Provider value={contextValue as React.ContextType<typeof FirebaseContext>}>
|
|
170
203
|
{children}
|