Countly/countly-sdk-web

Bug: Countly doesn't correctly remove consent for custom groups.

Closed this issue · 3 comments

See https://codepen.io/SgtPooki/pen/xxJKqBP?editors=1011

import countlySdkWeb from "https://cdn.skypack.dev/countly-sdk-web@22.6.4";

countlySdkWeb.init({
  app_key: 'nothing',
  url: 'https://support.count.ly',
  require_consent: true,
})

countlySdkWeb.group_features({
    activity:["sessions","events","views"],
    interaction:["scrolls","clicks","forms"]
});

countlySdkWeb.track_clicks()
countlySdkWeb.track_errors()
countlySdkWeb.track_forms()
countlySdkWeb.track_links()
countlySdkWeb.track_pageview()
countlySdkWeb.track_scrolls()
countlySdkWeb.track_sessions()
countlySdkWeb.track_view()

function logConsent(preMsg) {
  console.log()
  console.log(preMsg)
  console.log('activity consent: ', countlySdkWeb.check_consent('activity'))
  console.log('sessions consent: ', countlySdkWeb.check_consent('sessions'))
  console.log('events consent: ', countlySdkWeb.check_consent('events'))
  console.log('views consent: ', countlySdkWeb.check_consent('views'))
}

logConsent('prior to adding consent')
countlySdkWeb.add_consent('activity')
logConsent('after to adding consent')
countlySdkWeb.remove_consent('activity')
logConsent('after to removing consent')

console log output is:

"prior to adding consent"
"activity consent: " false
"sessions consent: " false
"events consent: " false
"views consent: " false
"after to adding consent"
"activity consent: " true
"sessions consent: " true
"events consent: " true
"views consent: " true
"after to removing consent"
"activity consent: " true # <-- THIS should be false 
"sessions consent: " false
"events consent: " false
"views consent: " false

workaround until this is fixed:

  function checkConsent (consent: string) {
    const featuresArray = this.groupedFeatures[consent]
    if (featuresArray == null) {
      return countlySdkWeb.check_consent(consent)
    }
    return featuresArray.every((feature) => countlySdkWeb.check_consent(feature))
  }

Hi SgtPooki thank you for reaching out. Consent grouping is a convenience method for adding or removing consent. It is not intended for using with check_consent function, which is implemented to check only a specific core consent, not a consent group. So currently that function is not tracking the state of consent groups and we do not want it to do that also in near feature. But as you have mentioned it, it would be better for us to give the developer a warning, stating that they should not be using this function with a consent group name. We will consider the possibility of this option in future releases. Thank you.

@turtledreams Thanks for the extremely quick response.

At the minimum, I would suggest a docs update, but it's good to know this is expected.