Skip to content

Commit 72834b2

Browse files
committed
feat: implement set consent for web
1 parent 31f5bd7 commit 72834b2

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

packages/firebase_analytics/firebase_analytics_web/lib/firebase_analytics_web.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,19 @@ class FirebaseAnalyticsWeb extends FirebaseAnalyticsPlatform {
7373
bool? personalizationStorageConsentGranted,
7474
bool? securityStorageConsentGranted,
7575
}) async {
76-
throw UnimplementedError('setConsent() is not supported on Web.');
76+
return convertWebExceptions(() {
77+
return _delegate.setConsent(
78+
adStorageConsentGranted: adStorageConsentGranted,
79+
analyticsStorageConsentGranted: analyticsStorageConsentGranted,
80+
adPersonalizationSignalsConsentGranted:
81+
adPersonalizationSignalsConsentGranted,
82+
adUserDataConsentGranted: adUserDataConsentGranted,
83+
functionalityStorageConsentGranted: functionalityStorageConsentGranted,
84+
personalizationStorageConsentGranted:
85+
personalizationStorageConsentGranted,
86+
securityStorageConsentGranted: securityStorageConsentGranted,
87+
);
88+
});
7789
}
7890

7991
@override

packages/firebase_analytics/firebase_analytics_web/lib/interop/analytics.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,42 @@ class Analytics extends JsObjectWrapper<analytics_interop.AnalyticsJsImpl> {
5353
);
5454
}
5555

56+
void setConsent({
57+
bool? adPersonalizationSignalsConsentGranted,
58+
bool? adStorageConsentGranted,
59+
bool? adUserDataConsentGranted,
60+
bool? analyticsStorageConsentGranted,
61+
bool? functionalityStorageConsentGranted,
62+
bool? personalizationStorageConsentGranted,
63+
bool? securityStorageConsentGranted,
64+
}) {
65+
final consentSettings = {
66+
if (adPersonalizationSignalsConsentGranted != null)
67+
'ad_personalization':
68+
adPersonalizationSignalsConsentGranted ? 'granted' : 'denied',
69+
if (adStorageConsentGranted != null)
70+
'ad_storage': adStorageConsentGranted ? 'granted' : 'denied',
71+
if (adUserDataConsentGranted != null)
72+
'ad_user_data': adUserDataConsentGranted ? 'granted' : 'denied',
73+
if (analyticsStorageConsentGranted != null)
74+
'analytics_storage':
75+
analyticsStorageConsentGranted ? 'granted' : 'denied',
76+
if (functionalityStorageConsentGranted != null)
77+
'functionality_storage':
78+
functionalityStorageConsentGranted ? 'granted' : 'denied',
79+
if (personalizationStorageConsentGranted != null)
80+
'personalization_storage':
81+
personalizationStorageConsentGranted ? 'granted' : 'denied',
82+
if (securityStorageConsentGranted != null)
83+
'security_storage':
84+
securityStorageConsentGranted ? 'granted' : 'denied',
85+
}.jsify();
86+
87+
return analytics_interop.setConsent(
88+
consentSettings,
89+
);
90+
}
91+
5692
void setAnalyticsCollectionEnabled({required bool enabled}) {
5793
return analytics_interop.setAnalyticsCollectionEnabled(
5894
jsObject,

packages/firebase_analytics/firebase_analytics_web/lib/interop/analytics_interop.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ external void logEvent(
3232
JSObject? callOptions,
3333
);
3434

35+
@JS()
36+
@staticInterop
37+
external void setConsent(
38+
JSAny? consentSettings,
39+
);
40+
3541
@JS()
3642
@staticInterop
3743
external void setAnalyticsCollectionEnabled(

0 commit comments

Comments
 (0)