Is there a way to delay the survey from showing up for first time visitors to my site?

andreas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 8, 2016

I don't want users to be polled immediately when they first visit my site. Is there a way to delay polling for first time visitors?

1 answer

1 accepted

1 vote
Answer accepted
andreas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 8, 2016

You have full control over how you embed the survey in your site.  You could for example achieve this by setting a timestamp in localstorage like this:

<script   src="https://code.jquery.com/jquery-2.2.4.min.js"   integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="   crossorigin="anonymous"></script>
<script>
(function() {
  var firstVisitDate = window.localStorage.getItem("firstVisit");
  if(firstVisitDate === null) {
    window.localStorage.setItem("firstVisit", Date.now());
  } else {
    if(Date.now() > (parseInt(firstVisitDate) + (24*60*60*1000))) {
      window.CODEBARREL_NPS = {
          getUserId: function () {
              return undefined;
          }
      };
      $.when(
        $.getScript("https://nps-for-jira.codebarrel.io/676c3c95851177199ebf9f5f3f1747/js/i18n.pack.js"),
        $.getScript("https://nps-for-jira.codebarrel.io/676c3c95851177199ebf9f5f3f1747/js/npssurvey.pack.js"),
        $.Deferred(function(deferred){$(deferred.resolve);}))
      .done(function() { 
        $.getScript("https://nps-for-jira.codebarrel.io/rest/remote/survey-init.js?surveyId=d8c0d83f-8da3-4574-8007-cabd0c8b6c17&clientKey=jira:2c5273f3-2840-4087-bc1f-485df7dd34");
      });
   }
  }
})();
</script>

 

This code inserts a timestamp in local storage on first visit to your site, and then compares this timestamp on subsequent visits to check if it is older than 24 hours.  The NPS survey javascript will only be requested if this condition is met.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events