Skip to content

Avoid sending POST /consent requests on every page visit #202

@over-engineer

Description

@over-engineer

Describe the bug

The client-side of the plugin sends requests to the POST /wp-json/pressidium-cookie-consent/v1/consent endpoint on every page visit.

This happens because the request logic is currently attached to both the onConsent() and onChange() events, while onConsent() is triggered on every page load after consent has already been given.

As a result, redundant consent requests are sent even when the user’s consent state has not changed.

Steps to reproduce

Detailed steps to reproduce the behavior:

  1. Visit a site using the plugin
  2. Accept or reject cookies from the consent modal
  3. Open the browser’s Network tab
  4. Navigate to another page on the website or refresh the page
  5. Observe that a POST /wp-json/pressidium-cookie-consent/v1/consent request is sent on every page visit

Expected behavior

The consent endpoint should only be called:

  • The first time the user expresses their consent choice
  • Whenever the user changes their consent preferences afterward

The request should not be triggered again on every page load when the consent state remains unchanged.

Screenshots

N/A

Environment (please complete the following information):

  • Browser: Tested on Chrome (macOS) and FIrefox (macOS)
  • Plugin version: 1.9.1
  • WordPress version: 6.9.4
  • PHP version: 8.1

Server logs

N/A

Browser console logs

N/A

Checklist

  • I have searched the GitHub issues to ensure this is not a duplicate
  • I have provided sufficient information to reproduce and understand the issue
  • I have tested the issue using the latest version of the plugin
  • I have included any relevant error messages, logs, or screenshots
  • I have reviewed the wiki to ensure this issue is not related to a misconfiguration

Additional context

N/A

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions