react-query-firebase 1.1.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.
- package/dist/src/analytics/index.d.ts +1 -0
- package/dist/src/analytics/index.js +1 -0
- package/dist/src/analytics/useSetAnalyticsCollectionEnabled.d.ts +10 -0
- package/dist/src/analytics/useSetAnalyticsCollectionEnabled.js +16 -0
- package/dist/src/context/FirebaseContextProvider.d.ts +14 -0
- package/dist/src/context/FirebaseContextProvider.js +13 -2
- package/package.json +1 -1
- package/src/analytics/index.ts +1 -0
- package/src/analytics/useSetAnalyticsCollectionEnabled.ts +22 -0
- package/src/context/FirebaseContextProvider.tsx +28 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type UseSetAnalyticsCollectionEnabledOptions = {
|
|
2
|
+
enabled?: boolean;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Custom hook to enable or disable analytics collection
|
|
6
|
+
* @param {Object} options - The options for hook.
|
|
7
|
+
* @param {string} options.enabled - Flag that identifies if analytics collection is enabled.
|
|
8
|
+
*/
|
|
9
|
+
export declare const useSetAnalyticsCollectionEnabled: ({ enabled }: UseSetAnalyticsCollectionEnabledOptions) => void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { setAnalyticsCollectionEnabled } from "firebase/analytics";
|
|
2
|
+
import { useAnalytics } from "./useAnalytics";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* Custom hook to enable or disable analytics collection
|
|
6
|
+
* @param {Object} options - The options for hook.
|
|
7
|
+
* @param {string} options.enabled - Flag that identifies if analytics collection is enabled.
|
|
8
|
+
*/
|
|
9
|
+
export const useSetAnalyticsCollectionEnabled = ({ enabled = false }) => {
|
|
10
|
+
const analytics = useAnalytics();
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (analytics) {
|
|
13
|
+
setAnalyticsCollectionEnabled(analytics, enabled);
|
|
14
|
+
}
|
|
15
|
+
}, [analytics]);
|
|
16
|
+
};
|
|
@@ -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
package/src/analytics/index.ts
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { setAnalyticsCollectionEnabled } from "firebase/analytics";
|
|
2
|
+
import { useAnalytics } from "./useAnalytics";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
|
|
5
|
+
type UseSetAnalyticsCollectionEnabledOptions = {
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Custom hook to enable or disable analytics collection
|
|
11
|
+
* @param {Object} options - The options for hook.
|
|
12
|
+
* @param {string} options.enabled - Flag that identifies if analytics collection is enabled.
|
|
13
|
+
*/
|
|
14
|
+
export const useSetAnalyticsCollectionEnabled = ({ enabled = false }: UseSetAnalyticsCollectionEnabledOptions) => {
|
|
15
|
+
const analytics = useAnalytics();
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (analytics) {
|
|
19
|
+
setAnalyticsCollectionEnabled(analytics, enabled);
|
|
20
|
+
}
|
|
21
|
+
}, [analytics]);
|
|
22
|
+
};
|
|
@@ -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") {
|