iframemanager icon indicating copy to clipboard operation
iframemanager copied to clipboard

Load iframes when a category from Cookie Consent is accepted

Open vyskoczilova opened this issue 2 years ago • 1 comments

Is there a way to allow load iframes when a category gets accepted from CookieConsent per default but allow the single-service management when not authorized?

I mean, one with allowed marketing cookies will get iframes loaded. The others could agree only to YouTube service on iframe. If they'll later eventually agree and disagree with marketing, the consent will be removed as well for YT.

I load the IframeManager only when the iframe is used in the WordPress Content (created a super simple plugin), and CookieConsent is running on all pages. Maybe a parameter will check the specified category before using cc_youtube or cc_vimeo? Or did I miss something?

P.S. Thanks for a great tool, hope you enjoy your ☕

vyskoczilova avatar Nov 30 '21 16:11 vyskoczilova

Hi @vyskoczilova, first of all, thank you!

If I understand correctly:

  1. you'd like to differentiate between "service accepted directly through iframemanager" and "service accepted through cookieconsent"
  2. if it is accepted via iframemanager then prevent the cookieconsent from clearing the service's data (cookie) — when the user opts out of the category in which the service is declared — so that iframes can load without the need of re-asking for permission.

In my opinion, the current behaviour is not wrong: if a user really comes back to opt-out from that category, then he really wants to opt out of everything in it. I get your point though!

Here's what you can do to make it work (I'm using as example cc_youtube as if it was under the marketing category, but the same logic would apply for other services):

  1. You need to disable the auto-clearing of that specific service's cookie, inside cookieconsent. To do this either entirely remove the block in which you declared the cookie, or intentionally specify a wrong path — to prevent the plugin from finding and erasing it!

      // ...
        cookie_table: [             
            {
                col1: 'cc_youtube', 
                col2: '...',
                col3: '...',
                col4: '...',
                path: '/WRONG_COOKIE_PATH/'    // 'path' is a reserved keyword and won't appear in the html table
            },
            // ...
        ],
    // ...
    
  2. You need to make use of the data field inside cc_cookie, and accept the service using the following logic:

    <script type="text/plain" data-cookiecategory="marketing">
        if( !cc.validCookie('cc_youtube') ){
            console.log('accepting youtube through cookieconsent');
            iframemanager.acceptService('youtube');
        }else{
            console.log('youtube already accepted through iframemanager');
            cc.set( 'data', { value: true, mode: 'update' })
        }
    </script>
    
  3. Manually reject the service (and erase the cookie) when the service is managed through the cookieconsent instead of iframemanager

    // ...
      onChange: function () {
    
          if( !cc.allowedCategory('marketing') && !cc.get('data') ){
              console.log("reject youtube through cookieconsent")
              iframemanager.rejectService('youtube');
          }
    
      },
    // ...
    

Note: for this to work, you need to have page_scripts enabled.

orestbida avatar Dec 01 '21 01:12 orestbida