allboatsrise / expo-marketingcloudsdk

Expo module for Salesforce Marketing Cloud SDK
MIT License
12 stars 12 forks source link

Feature request: enable/disable analytics programmatically #46

Closed pehagg closed 1 month ago

pehagg commented 1 month ago

Due to GDPR, we cannot enable analytics until the user has given consent for this. react-native-marketingcloudsdk has support for this, but I couldn't find any traces of being able to control this programmatically for expo-marketingcloudsdk.

I got this working for iOS by adding three new functions isAnalyticsEnabled, enableAnalytics, and disableAnalytics (in the spirit of isPushEnabled, enablePush, and disablePush), but I'm struggling with finding the correct way to do this for Android.

Any help would be appreciated, I can even post a PR of the changes later. This is the only thing that is preventing us from migrating our app to Expo.

andrejpavlovic commented 1 month ago

Try this, based on docs here: https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/MarketingCloudSdk/8.0/-marketing%20-cloud%20-s-d-k/com.salesforce.marketingcloud.analytics/index.html

    AsyncFunction("isAnalyticsEnabled") { promise: Promise ->
      whenPushModuleReady(promise) { mp -> promise.resolve(mp.analyticsManager.areAnalyticsEnabled()) }
    }

    AsyncFunction("enableAnalytics") { promise: Promise ->
      whenPushModuleReady(promise) { mp ->
        mp.analyticsManager.enableAnalytics()
        promise.resolve(mp.analyticsManager.enableAnalytics())
      }
    }

    AsyncFunction("disableAnalytics") { promise: Promise ->
      whenPushModuleReady(promise) { mp ->
        mp.analyticsManager.disableAnalytics()
        promise.resolve(mp.analyticsManager.areAnalyticsEnabled())
      }
    }

If you can submit a PR that would be great!

andrejpavlovic commented 1 month ago

Released in 51.0.6