Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why send consent POST on each request? #2

Closed
Ciantic opened this issue Dec 13, 2023 · 5 comments · May be fixed by #4
Closed

Why send consent POST on each request? #2

Ciantic opened this issue Dec 13, 2023 · 5 comments · May be fixed by #4

Comments

@Ciantic
Copy link

Ciantic commented Dec 13, 2023

Reproduce:

  1. Start Google Chrome as Guest user (so no extensions are affecting it)
  2. Navigate dude.fi
  3. Accept cookies
  4. Go to some sub page, hit refresh

I see POST https://www.dude.fi/wp-json/air-cookie/v1/consent on each request:

dude-fi-consent-POST.mp4
@ronilaukkarinen
Copy link
Member

Quick input: This could be because

  1. we need to know if the user changes the consent in any given moment.
  2. dude.fi is using swup.js for page transtions

Screen-Shot-2023-12-14-10-52-18

But I might be wrong about this. Need to check in some point.

@Ciantic
Copy link
Author

Ciantic commented Dec 14, 2023

It happened on our site too (not using swup.js), that's why I opened the issue. I just didn't want to post that site URL so I found out it happens on dude.fi which was better showcase.

@Ciantic
Copy link
Author

Ciantic commented Feb 21, 2024

Cookie Consent's onAccept is triggered on each page load.

I managed to fix this like this, add a new callback onFirstAction:

      airCookieSettings.onFirstAction = function() {
        airCookierecordConsent();
      }

Then commenting out airCookierecordConsent() from onAccept like this:

    <?php // Allow adding categiry specific javascript to be runned when the category is accepted.
    if ( ! empty( $cookie_categories ) && is_array( $cookie_categories ) ) : ?>
      airCookieSettings.onAccept = function() {
        // airCookierecordConsent(); // THIS LINE IS THE PROBLEM, BECAUSE CONSENT calls onAccept on each request

        <?php foreach ( $cookie_categories as $cookie_category ) {
          echo do_category_js( $cookie_category ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        } ?>
      }

I think they have changed many things in 3.0.0, because there is now onConsent callback.

@ronilaukkarinen
Copy link
Member

Hmm, I see. We should upgrade to 3 in some point (#3). In the meantime you could send a PR about your fix?

@Ciantic
Copy link
Author

Ciantic commented Mar 15, 2024

I was about to send PR, but I don't think it's useful anymore because there is now this excellent PR for upgrading directly 3.0 that also fixes this: #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants