Page 2 of 3

Re: 2.0.1: Cookie problem

Posted: Sun Oct 11, 2015 7:20 pm
by pschoenb
Rolf wrote:The cookie *is* set at your website

Try to play with

Code: Select all

{if empty($smarty.cookies.cookie_consent)}
i.e.

Code: Select all

{if !isset($smarty.cookies.cookie_consent)}
Still the same behavior.

Re: 2.0.1: Cookie problem

Posted: Mon Oct 12, 2015 3:45 pm
by pschoenb
My suspicion: It is one of the following:
  1. The cookie is set but not accessible to Smarty.
  2. It is a caching issue.

Re: 2.0.1: Cookie problem

Posted: Tue Oct 13, 2015 11:53 am
by Rolf
What is the value of

Code: Select all

a{$smarty.cookies.cookie_consent}b
when you put it directly in your template.

Re: 2.0.1: Cookie problem

Posted: Tue Oct 13, 2015 4:00 pm
by pschoenb
Rolf wrote:What is the value of

Code: Select all

a{$smarty.cookies.cookie_consent}b
when you put it directly in your template.
When clicking "Continue", it remains

Code: Select all

ab
until I reload the page. Then, it turns

Code: Select all

ayesb

Re: 2.0.1: Cookie problem

Posted: Tue Oct 13, 2015 4:06 pm
by Rolf
Ahh, try

Code: Select all

<__script__ type="text/javascript">
  $(".accept_cookies").click(function () {
    $("#cookie_consent").toggle("slow");
    $.cookie("cookie_consent", "yes", { domain: "yourdomain.com", path: "/", expires: 1095 } );
    location.reload();
  } );

  $(document).ready(function() {
    $.cookie("cookie_consent", "yes", { domain: "yourdomain.com", path: "/", expires: 1095 } );
  } );
</__script>
Don't forget to change the domain name and the __ characters in the style tags

Re: 2.0.1: Cookie problem

Posted: Tue Oct 13, 2015 6:15 pm
by pschoenb
Rolf wrote:Ahh, try

Code: Select all

<__script__ type="text/javascript">
  $(".accept_cookies").click(function () {
    $("#cookie_consent").toggle("slow");
    $.cookie("cookie_consent", "yes", { domain: "yourdomain.com", path: "/", expires: 1095 } );
    location.reload();
  } );

  $(document).ready(function() {
    $.cookie("cookie_consent", "yes", { domain: "yourdomain.com", path: "/", expires: 1095 } );
  } );
</__script>
Don't forget to change the domain name and the __ characters in the style tags
Still the same.

Re: 2.0.1: Cookie problem

Posted: Wed Oct 14, 2015 10:02 am
by Rolf
I noticed the same behavior at one of my own websites, wil troubleshoot when I have a moment.
This website is on 1.12.1, so it has nothing to do with upgrade to CMSMS 2.x

Re: 2.0.1: Cookie problem

Posted: Wed Oct 14, 2015 2:28 pm
by pschoenb
Rolf wrote:I noticed the same behavior at one of my own websites, wil troubleshoot when I have a moment.
This website is on 1.12.1, so it has nothing to do with upgrade to CMSMS 2.x
Could it be a browser caching issue?

Re: 2.0.1: Cookie problem

Posted: Wed Oct 14, 2015 10:02 pm
by PinkElephant
pschoenb wrote:Ok, now, I have no JS errors anymore in the console
I'm still seeing the same pattern:

Code: Select all

if ( $(window).width() > 768) {
"ReferenceError: $ is not defined"

This is before jquery is loaded ... first here;

Code: Select all

<!-- Begin Bootstrap (JQuery) -->
<__script__ src="//code.jquery.com/jquery.min.js"></__script>
then here;

Code: Select all

<!-- Begin EU cookie consent (JQuery) -->
<__script__ type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></__script>

Re: 2.0.1: Cookie problem

Posted: Wed Oct 14, 2015 10:37 pm
by pschoenb
PinkElephant wrote:
pschoenb wrote:Ok, now, I have no JS errors anymore in the console
I'm still seeing the same pattern:

Code: Select all

if ( $(window).width() > 768) {
"ReferenceError: $ is not defined"

This is before jquery is loaded ... first here;

Code: Select all

<!-- Begin Bootstrap (JQuery) -->
<__script__ src="//code.jquery.com/jquery.min.js"></__script>
then here;

Code: Select all

<!-- Begin EU cookie consent (JQuery) -->
<__script__ type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></__script>
Maybe cached?

Bootstrap is now below the cookie consent query, and it looks like this:

Code: Select all

<!-- Begin Bootstrap (JQuery) -->

<__script__ src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></__script>

<!-- End Bootstrap (JQuery) -->

Re: 2.0.1: Cookie problem

Posted: Thu Oct 15, 2015 8:34 am
by PinkElephant
pschoenb wrote:
PinkElephant wrote:"ReferenceError: $ is not defined"
Maybe cached?
Ah, sorry - it must have been.

Looking anew, the cookie appears to be set 'yes' on document.ready - not under (".accept_cookies").click(function () ...

Only briefly tested but IE & Chrome never shows the "#cookie_consent" opt-in (expected) but Firefox always shows it even though the cookie is set although it's a session cookie - no fixed expiry... so, confused, need coffee. ;)

Re: 2.0.1: Cookie problem

Posted: Thu Oct 15, 2015 8:01 pm
by pschoenb
How to get a consistent behavior on all browsers?

Re: 2.0.1: Cookie problem

Posted: Fri Oct 16, 2015 7:26 am
by velden
I don't think it's a browser-specific issue. Would not make sense either.

In my opinion this part of the script should be removed:

Code: Select all

$(document).ready(function() {
    $.cookie("cookie_consent", "yes", { domain: "yourdomain.com", path: "/", expires: 1095 } );
though it won't fix the problem.

Actually the method is pretty simple so try to pinpoint the exact issue. Apparently the $smarty.cookies.cookie_consent cannot be read so find out where by placing this code at some points in you templates and 'global content blocks' (=templates too)

Code: Select all

<pre>cookies: {$smarty.cookies|print_r}</pre>
Another method could be:

create a udt 'read_cookie'

Code: Select all

return $_COOKIE[$params['name']];
Then use this condition in the template:

Code: Select all

{if {read_cookie name=cookie_consent} != 'yes'}<div id="cookie_consent">
    <p>
...
    <a class="accept_cookies">Continue</a><a href="privacy" target="_blank" class="more_info">More info...</a></p>
  </div>
{/if}

Re: 2.0.1: Cookie problem

Posted: Fri Oct 16, 2015 12:57 pm
by pschoenb
velden wrote: Actually the method is pretty simple so try to pinpoint the exact issue. Apparently the $smarty.cookies.cookie_consent cannot be read so find out where by placing this code at some points in you templates and 'global content blocks' (=templates too)

Code: Select all

<pre>cookies: {$smarty.cookies|print_r}</pre>
The cookie is not visible to Smarty anywhere on the page until I hit <Ctrl><Shift>-R in Firefox.

Is this a caching issue?

As I said, I had it working with 2.0.

Re: 2.0.1: Cookie problem

Posted: Tue Oct 20, 2015 3:40 pm
by pschoenb
Any further ideas?