Change expire date for cookies? | XM Community
Skip to main content
Solved

Change expire date for cookies?


Christopher2408
Forum|alt.badge.img+1

Hi there,

i’m searching a possibility to change the expire date for the cookie which ist set for users, who answered a survey (CX Foundational survey). I need to make them expire latest after 3 month. Its an anonymous survey without any code or tracking options.

Does anyone knows how long the default for the cookoe expire date is?
And if longer than 2 months, is there any chance to override the default?

 

Thanks a lot for some ideas if there are :-)
Christopher

Best answer by hinchja

I have developed this, but it drops another cookie with the right expiration date, it doesn’t change the cookies expiration date. It makes a QST with a 2 month expiration date. 

 

yourCookieValue is the survey ID. 

 

It is put inside the first question of the survey’s java script. 


 

Qualtrics.SurveyEngine.addOnload(function() {

    // Function to set a cookie with a specific expiration date

    function setCookie(name, value, days) {

        const date = new Date();

        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));

        const expires = "expires=" + date.toUTCString();

        document.cookie = name + "=" + value + ";" + expires + ";path=/";

    }

 

    // Change the QST cookie's expiration date to 2 months (approximately 60 days)

    setCookie("QST", "yourCookieValue", 60);

});

 


 

View original

5 replies

hinchja
Level 1 ●
Forum|alt.badge.img+5
  • Level 1 ●
  • 8 replies
  • February 26, 2025

I know the QST Cookie that prevents multiple submissions lasts 6 months. This is likely the cookie that you are running into using an anonymous link. Here is the support pages for the cookies. The different cookies have different expiration dates. 

 

https://www.qualtrics.com/support/website-app-feedback/getting-started-with-website-app-feedback/website-app-feedback-browser-cookies/#Functional

 

https://www.qualtrics.com/support/survey-platform/getting-started/browser-cookies/

 

I would like to know if there is any JavaScript that we can add that allows us to manipulate the expiration date of the cookies we drop. I also want the expiration date to go from 6 months to 2 months. 


Christopher2408
Forum|alt.badge.img+1

Thans hinchja! And yes, i would also like to know this special JavaScript. Maybe someone here helps us out.


hinchja
Level 1 ●
Forum|alt.badge.img+5
  • Level 1 ●
  • 8 replies
  • Answer
  • February 27, 2025

I have developed this, but it drops another cookie with the right expiration date, it doesn’t change the cookies expiration date. It makes a QST with a 2 month expiration date. 

 

yourCookieValue is the survey ID. 

 

It is put inside the first question of the survey’s java script. 


 

Qualtrics.SurveyEngine.addOnload(function() {

    // Function to set a cookie with a specific expiration date

    function setCookie(name, value, days) {

        const date = new Date();

        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));

        const expires = "expires=" + date.toUTCString();

        document.cookie = name + "=" + value + ";" + expires + ";path=/";

    }

 

    // Change the QST cookie's expiration date to 2 months (approximately 60 days)

    setCookie("QST", "yourCookieValue", 60);

});

 


 


Christopher2408
Forum|alt.badge.img+1

Great, THANKS!!


hinchja
Level 1 ●
Forum|alt.badge.img+5
  • Level 1 ●
  • 8 replies
  • March 24, 2025

So I found out that the cookie was being overwritten at the end of the survey so putting the Cookie in the first question was pointless...soooo, add it into an end of survey message. Here’s how I did and it worked. 


Create an End of Survey Message.

Put this in the Source:


<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Set QST Cookie</title>

</head>

<body>

<p style="text-align: center;">Thank you! Your response has been recorded!</p>

<script>

        // Function to set a cookie with a specific expiration date

        function setCookie(name, value, days) {

            const date = new Date();

            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));

            const expires = "expires=" + date.toUTCString();

            document.cookie = name + "=" + value + ";" + expires + ";path=/;domain=.qualtrics.com";

        }

 

        // Overwrite the QST cookie and set its expiration date to 30 days

        setCookie("QST", "SV_8kKdESOGIo8QDci", 30);

    </script></body>

</html>


Update the bolded information above with your message, domain (may depend on if you use a vanity URL), your survey ID and the number of days you want the QST Cookie to expire after.  

 

Hope this helps.