Skip to content

feat: Multiple consent types with one setConsent call #671

@gasci

Description

@gasci

Plugin(s)

  • Analytics
  • App
  • App Check
  • Authentication
  • Crashlytics
  • Cloud Firestore
  • Cloud Functions
  • Cloud Messaging
  • Cloud Storage
  • Performance
  • Remote Config

Current problem

Multiple consent calls cannot be sent within one function:

if (isPlatform(["web", "android", "ios"])) {
    const consent = await Preferences.get({ key: 'cookieConsent' });

    await FirebaseAnalytics.setConsent({
      type: ConsentType.AdPersonalization,
      status: consent.value === 'authorized' ? ConsentStatus.Granted : ConsentStatus.Denied
    });

    await FirebaseAnalytics.setConsent({
      type: ConsentType.PersonalizationStorage,
      status: consent.value === 'authorized' ? ConsentStatus.Granted : ConsentStatus.Denied
    });

    await FirebaseAnalytics.setConsent({
      type: ConsentType.AdUserData,
      status: consent.value === 'authorized' ? ConsentStatus.Granted : ConsentStatus.Denied
    });

    await FirebaseAnalytics.setConsent({
      type: ConsentType.AdStorage,
      status: consent.value === 'authorized' ? ConsentStatus.Granted : ConsentStatus.Denied
    });

    await FirebaseAnalytics.setConsent({
      type: ConsentType.AnalyticsStorage,
      status: consent.value === 'authorized' ? ConsentStatus.Granted : ConsentStatus.Denied
    });
  }

We get the following error:

VM4026:944 Uncaught (in promise) Error: consentType must be provided.
    at returnResult (<anonymous>:944:32)
    at win.androidBridge.onmessage (<anonymous>:919:21)

Preferred solution

Passing all the types in one parameter would result in only one call.

await FirebaseAnalytics.setConsent({
      type: [ConsentType.AnalyticsStorage, ConsentType.AdUserData],
      status: consent.value === 'authorized' ? ConsentStatus.Granted : ConsentStatus.Denied
    });

Alternative options

No response

Additional context

No response

Before submitting

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions