Jump to content

PrivacyWire - Cookie Management & async external asset loading


joshua

Recommended Posts

2 hours ago, fruid said:

The cookie domain of these 13 cookies in the console is .vimeo.com, so are they out of scope? Maybe it's just my lack of understanding… 

You need to avoid loading the iframe just try:

<iframe 
src=""
data-src="https://player.vimeo.com/video/<?=$page->vimeoID;?>?color=5a90ff&portrait=0" 
data-category="marketing"
style="position:absolute;top:0;left:0;width:100%;height:100%;" 
frameborder="0" 
allow="autoplay; fullscreen" 
allowfullscreen>
</iframe>

This will block the whole iframe to be loaded until the user agree to us "marketing" cookies. With a little bit of css you can hide the empty iframes:

iframe[src=""]{display:none};

 

  • Like 1
Link to comment
Share on other sites

21 hours ago, DV-JF said:

<iframe 
src=""
data-src="https://player.vimeo.com/video/<?=$page->vimeoID;?>?color=5a90ff&portrait=0" 
data-category="marketing"
style="position:absolute;top:0;left:0;width:100%;height:100%;" 
frameborder="0" 
allow="autoplay; fullscreen" 
allowfullscreen>
</iframe>

 

I did this. If I leave the src tag empty, nothing is loaded. If I accept the marketing cookies, nothing is loaded either ?
I'm on local BTW, not sure if that's relevant

Link to comment
Share on other sites

Hi. Is it possible to make it like a window or modal centered in the middle of the page and the background overlayed with a half transparent color?
I tried to customize it via CSS but didn’t manage it. Maybe there is an easier solution for this?

Link to comment
Share on other sites

  • 2 weeks later...
On 3/18/2021 at 1:57 PM, fruid said:

I did this. If I leave the src tag empty, nothing is loaded. If I accept the marketing cookies, nothing is loaded either ?
I'm on local BTW, not sure if that's relevant

You can ommit the src attribute also. In my test case it works that way.
I use it a lot in combination with vimeo video and used the implementation as in this video

Link to comment
Share on other sites

On 3/23/2021 at 10:28 AM, Matze said:

Hi. Is it possible to make it like a window or modal centered in the middle of the page and the background overlayed with a half transparent color?
I tried to customize it via CSS but didn’t manage it. Maybe there is an easier solution for this?

You mean something like the screenshot attached?

That's possible with some CSS (this is just an example, how one could do this)


    .show-banner > .privacywire-page-wrapper,
    .show-options > .privacywire-page-wrapper,
    .show-message > .privacywire-page-wrapper {
        position: fixed;
        left: 0;
        top: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(5px);
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .privacywire {
        display: none;
    }

    .show-banner .privacywire.privacywire-banner,
    .show-options .privacywire.privacywire-options,
    .show-message .privacywire.privacywire-message {
        display: block;
        position: relative;
        left: auto;
        right: auto;
        bottom: auto;
        max-width: 450px;
    }

 

Bildschirmfoto 2021-04-05 um 14.58.19.png

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

I started having trouble with <script type=text/plain" data-type="text/javascript" data-category="external_media" class="require-consent">

I get a JS error and the element isn't shown (any more?) on consent. Anyone else sees this too? Or did I use this in an unintended way? (Example)

 

Link to comment
Share on other sites

8 minutes ago, ceberlin said:

<script type=text/plain" data-type="text/javascript" data-category="external_media" class="require-consent">

In this example the starting quote at the type attribute is missing:

<script type="text/plain" data-type="text/javascript" data-category="external_media" class="require-consent">...</script>

In your example:

grafik.thumb.png.46242ea432b39cd9e48c40b9d1d4e4f1.png

 

Does it work with the quotation mark?

  • Like 1
Link to comment
Share on other sites

Thanks for noticing! I fixed the typo in the git repo, should be updated in the PW module repo soon.

Hm, I'm looking into this problem. Which version of PrivacyWire are you using?

  • Like 2
Link to comment
Share on other sites

Thank you @joshua for this great module!

Everything works perfectly. Only I can't get IE11 support to work.
I'm on ProcessWire 3.0.165 with PrivacyWire 1.0.4.
JS console says:

Quote

Object doesn't support property or method 'from'
PrivacyWire_legacy.js (1,10449)

Yes I know I should drop IE11 support... but this is more a legal issue than a functional or cosmetic one.

Edited by webaff
added system info
Link to comment
Share on other sites

  • 4 weeks later...

Hey @joshua,

I'm using your module in a "project master copy" of PW. Every time I start a new project I mirror this master copy.

Most of the time I don't need a consent banner - so a deinstall it. The disadvantage of this procedure is that if I need the banner later or the customer wants to add a banner, I have to make all the settings again after installing it.

Therefore it would be nice to have an option to disable the module. What do you think about this improvement?

Greets Jens alias DV-JF

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

I installed the module and the privacywire code (js and css) appears in my sourcecode (in the head) but the cookie toolbar insn't shown up.

<style>.privacywire{position:fixed;bottom:-250%;left:0;right:0;box-shadow:0 -1px 3px rgba(0,0,0,.3);opacity:0;background:#fff;z-index:1;padding:1rem;transition:bottom .3s ease-in,opacity .3s ease}.show-banner .privacywire-banner,.show-message .privacywire-message,.show-options .privacywire-options{bottom:0;opacity:1}.privacywire-header{font-weight:700}.privacywire-ask-consent-blueprint,.privacywire button[hidden],[data-ask-consent-rendered="1"]{display:none}</style>
<script>var PrivacyWireSettings={"version":1,"dnt":"0","customFunction":"","messageTimeout":1500,"consentByClass":"1","cookieGroups":{"necessary":"Necessary","functional":"Functional","statistics":"Statistik","marketing":"Marketing","external_media":"External Media"}};</script><script type='module' src='.../site/modules/PrivacyWire/js/PrivacyWire.js'></script><script nomodule type='text/javascript' src='/.../site/modules/PrivacyWire/js/ie_polyfill.js'></script><script nomodule type='text/javascript' src='.../site/modules/PrivacyWire/js/PrivacyWire_legacy.js'></script>

Is there somethings missing or do i make a mistake?
Thanks!

Link to comment
Share on other sites

Is your ProcessWire instance installed in the root web directory or somewhere else?

The only noticible change I find in your code examle is the directory within the script tag:

<script nomodule type='text/javascript' src='.../site/modules/PrivacyWire/js/PrivacyWire_legacy.js'>

Usually the src attribute starts directly with '/site/' instead of '.../site/'

<style>.privacywire{position:fixed;bottom:-250%;left:0;right:0;box-shadow:0 -1px 3px rgba(0,0,0,.3);opacity:0;background:#fff;z-index:1;padding:1rem;transition:bottom .3s ease-in,opacity .3s ease}.show-banner .privacywire-banner,.show-message .privacywire-message,.show-options .privacywire-options{bottom:0;opacity:1}.privacywire-header{font-weight:700}.privacywire-ask-consent-blueprint,.privacywire button[hidden],[data-ask-consent-rendered="1"]{display:none}</style>
<script>var PrivacyWireSettings={"version":1,"dnt":"0","customFunction":"","messageTimeout":1500,"consentByClass":"1","cookieGroups":{"necessary":"Necessary","functional":"Functional","statistics":"Statistics","marketing":"Marketing","external_media":"External Media"}};</script>
<script type='module' src='/site/modules/Privacywire/js/PrivacyWire.js'></script>
<script nomodule type='text/javascript' src='/site/modules/Privacywire/js/ie_polyfill.js'></script>
<script nomodule type='text/javascript' src='/site/modules/Privacywire/js/PrivacyWire_legacy.js'></script>

 

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
On 6/30/2021 at 8:51 AM, joshua said:
<style>.privacywire{position:fixed;bottom:-250%;left:0;right:0;box-shadow:0 -1px 3px rgba(0,0,0,.3);opacity:0;background:#fff;z-index:1;padding:1rem;transition:bottom .3s ease-in,opacity .3s ease}.show-banner .privacywire-banner,.show-message .privacywire-message,.show-options .privacywire-options{bottom:0;opacity:1}.privacywire-header{font-weight:700}.privacywire-ask-consent-blueprint,.privacywire button[hidden],[data-ask-consent-rendered="1"]{display:none}</style>
<script>var PrivacyWireSettings={"version":1,"dnt":"0","customFunction":"","messageTimeout":1500,"consentByClass":"1","cookieGroups":{"necessary":"Necessary","functional":"Functional","statistics":"Statistics","marketing":"Marketing","external_media":"External Media"}};</script>
<script type='module' src='/site/modules/Privacywire/js/PrivacyWire.js'></script>
<script nomodule type='text/javascript' src='/site/modules/Privacywire/js/ie_polyfill.js'></script>
<script nomodule type='text/javascript' src='/site/modules/Privacywire/js/PrivacyWire_legacy.js'></script>

 

Thanks for your answer!

I changed the .../site path just for the forum post.

After restarting the browser (new session) the privace wire toolbar is shown up!
 

 

  • Like 1
Link to comment
Share on other sites

  • 5 weeks later...

I have the following situation: in my initial html markup there is a PrivacyWire-ShowOptions link that gets initiated by the PrivacyWire module on content loaded.
Every thing works fine, as expected. 
After that, I update a part of the html markup (with the PrivacyWire-ShowOptions link included) via AJAX. The initial link is gone now, and the new link is not bound to the PrivacyWire event.
How can I bind it to the PrivacyWire event to show the options banner? A line of code or a keyword hint would be of great help. ?

 

Link to comment
Share on other sites

2 hours ago, horst said:

A line of code or a keyword hint would be of great help.

I just added a small function for this usecase in v1.0.7. You can trigger this "re-initiating" by calling

window.PrivacyWire.reHandleExternalButtons()

Updated / Added code: https://github.com/webworkerJoshua/privacywire/blob/1.0.7/src/js/PrivacyWire.js#L146-L149

  • Thanks 1
Link to comment
Share on other sites

41 minutes ago, joshua said:

I just added a small function for this usecase in v1.0.7. You can trigger this "re-initiating" by calling

window.PrivacyWire.reHandleExternalButtons()

Hey, many many thanks! Works fine!

Your support is extraordinary! ? ? ?

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

Hi, I've got a site that uses multi-language URLs based on a query-param, ie. https://example.com/some/page?lang=de.
The site exists of a Vue.js app on top of a very basic HTML skeleton generated by PW, and we don't use the LanguageSupportPageNames module at all (so no example.com/de & example.com/en ).

In order to set the initial skeleton HTML (such as page title etc), which gets rendered before the Vue app has booted, I set my $user->language based on the $input->get('lang') value. After the Vue app has booted, it takes over control and loads the remaining data in the appropriate language through a multilingual API endpoint.

Next to the Vue app, we also use PrivacyWire.

However, due to the way PrivacyWire has been built, it looks at the $users language BEFORE any of this takes place (in its ready() function).
As a result, I can't get the correct language content inside the PrivacyWire popups, it always shows the default language content instead.

So probably I need to hook into the getPrivacyWireConfigObject method, and overrule the PrivacyWire::lang variable with the language that I get from my $input->get('lang')?
Or would there be another, easier approach?

Any pointers would be most welcome! Thanks.

Link to comment
Share on other sites

3 hours ago, eelkenet said:

However, due to the way PrivacyWire has been built, it looks at the $users language BEFORE any of this takes place (in its ready() function).

That's correct, currently PrivacyWire loads itself in the module ready() method.

I played around with some settings to load PrivacyWire later. You can find the feature in this branch:
https://github.com/webworkerJoshua/privacywire/tree/feature-initiate-privacywire-laster
In this version PrivacyWire initiates itself before Page::render:

$this->addHookBefore('Page::render', $this, 'initiatePrivacyWire');

Could you try this version and confirm, that it's working the way you wanted / expected? After that I will do some more testing before merging into the main branch just to be sure that there are no side effects ?

Thanks!
 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Hi @joshua, that works - sort of. When setting the user language inside a template we still only get the default language, as your hook gets called earlier. 

However, what does work is hooking into the same Page::render method with a lower priority number, so our code gets an earlier execution. Great!

In ready.php we now have:

<?php

namespace ProcessWire;

// Hook into Page::render, just before PrivacyWire's hook 
// Which uses the default priority of 100
wire()->addHookBefore('Page::render', function (HookEvent $evt) {

  // Only apply to front-end pages
  $page = $evt->object;
  if (
    $page->template == 'admin' || // exclude admin pages
    $page->template == 'form-builder' // exclude from form-builder iframe
  ) {
    return;
  }

  $user = wire()->user;
  $languages = wire()->languages;
  
  // Get and sanitize the ?lang= get param
  $lang = strtolower(wire()->input->get("lang", "text"));

  // Set appropriate language
  if ($lang === "en") {
    $user->language = $languages->get("default");
  } else {
    $user->language = $languages->get("de");
  }
}, ['priority' => 99]);

 

 

  • Like 2
Link to comment
Share on other sites

1 hour ago, eelkenet said:

However, what does work is hooking into the same Page::render method with a lower priority number, so our code gets an earlier execution. Great!

That's great! Thanks for the feedback. It is even easier now in v1.0.9 as I reduced the hook priority, so every "usual" hook written inside a template should work, too.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...