Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1378131

    Hello all,

    I’m experiencing some troubles with custom cookies in combination with cookie consent enabled.

    I’ve built a form with Formidable Forms Pro to receive subscriptions and payments for a sports camp. To generate some documents or do some error handling i’m setting a custom cookie with next snippet of code:

    <script src="https: (Email address hidden if logged out) /dist/js.cookie.min.js"></script>
    <script type="text/javascript">
    function entryID(){
    	let timeStamp = Date.now();
    	console.log('timeStamp:', timeStamp);
    	document.getElementById("field_entry_unique_id").value = timeStamp;
    	Cookies.set('entry_unique_id', timeStamp, { expires: 1 })
    }
    </script>

    When I watch the DevTools, the cookie is set correctly with the correct value and lifetime of one day.

    After finishing payment through a payment service provider, the customer returns to the corresponding page (success, error, cancelled).

    On the pages “error” and “cancelled” i’m using next snippet of code to read the cookie:

    <script src="https: (Email address hidden if logged out) /dist/js.cookie.min.js"></script>
    <script type="text/javascript">
    
    let entryID = Cookies.get('entry_unique_id');
    console.log('Cookie entryID:', entryID);
    <do other stuff>

    And there comes the catch: With the cookie consent disabled everything works as expected and the cookie can be read.
    However, with the cookie consent enabled, the cookie “entry_unique_id” gets deleted upon returning after the PSP returns the status of the payment.

    Things I tried is: adding the custom cookies to the cookie modal window (didn’t help) and adding the cookie to the essential cookies in avia-snippet-cookieconsent.js at line 489 and 493 (no success either).

    What am I doing wrong / how can I fix this?

    Enfold: 5.3.1.1
    PHP: 8.0.27
    Browser: Microsoft Edge, Version 108.0.1462.76

    #1378199

    Hey Willem-Jan,

    Thank you for the inquiry.

    Your custom cookie gets removed because when the cookie consent is enabled and the user hasn’t agreed to accept cookies, the theme automatically blocks and removes the cookies from the local storage. The script or function responsible for this can be found in the enfold\js\avia-snippet-cookieconsent.js around line 528. You may need to modify the function to exclude your custom cookies. Unfortunately, this modification is beyond the scope of support.

    Best regards,
    Ismael

    #1378282

    Hi Ismael,

    I forgot to mention that I added the custom cookies to the consent window and I was testing the situation where all cookies are accepted.

    Nonetheless I was able to fix the issue by setting the cookie in a different way:

    Cookies.set('entry_unique_id', timeStamp, { expires: 1, sameSite: 'strict', secure: true });

    Setting sameSite: Strict and the “secure” flag fixed it and the cookie survives the redirect to the PSP and back to the site.

    #1378697

    Hi,
    Glad to hear that you have this sorted out, and thanks for sharing your solution, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.

    Best regards,
    Mike

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Custum cookies deleted after redirect’ is closed to new replies.