Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Issue with redirecting out and back in from LS survey

  • jsmatte1
  • jsmatte1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 4 weeks ago #241800 by jsmatte1
Please help us help you and fill where relevant:
Your LimeSurvey version: Version 3.28.52
Own server or LimeSurvey hosting: LimeSurvey hosting
Survey theme/template: NA
==================
Hello LimeSurvey Community,

I have a survey in which respondents need to be directed to another url (Sawtooth conjoint experiment server), and then re-directed back into LS to complete the survey. I have found through  this link  and this link  that it is possible, and implemented the code of the latter link. However, I am left with one issue: when the respondents are done with the part in Sawtooth and directed back to LS, they land on the question that directs them to Sawtooth in the first place. As if when the are redirected out of LS, it doesn't register that the respondent is done with that question and hence why they land at the exact same place instead of one step further. 

The first link seems to have two actions built into it ('#movenextbtn, #movesubmitbtn'), but is for ls2, whereas the second link (the code I implemented) has only one ('#ls-button-submit'), but is for ls3. I am wondering if this is why it is not working, or if it is due to something else. The first link also refers to a config.php file in which the author added a bit of code. Since my survey is hosted by LimeSurvey, it is my understanding that I do not have access to that file. Is that where the problem comes from?

Any help is much appreciated!

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 4 weeks ago - 1 year 4 weeks ago #241803 by Joffm
Hi,
1. The ID of this button was changed in version 3.x.
And as there is no real difference between the button ión the last page (where it says "Submit") and the button on previous pages, now there is only one ID (ls-button-submit).

2. It is easy to understand that this same page is displayed. You do  not leave it.
You bind a different event to the button (to call the other location)

In the older thread you see how the TO queried the database to change the value of "lastpage".
As your installation is hosted at Limesurvey GMBH you have not access to the database.

So you have to think about a different approach.

An easy one:
Place the link to your Conjoint experiment in a question of type "text display"
Also in this question put a javascript snippet 
Code:
<script type="text/javascript" charset="utf-8">
      $(document).ready(function(){
            $('#ls-button-submit').hide();
            setTimeout(function () {
               $('#ls-button-submit').trigger('click').show();
          }, 30000);  // Proceed after 30 seconds
    });
</script>
While the respondent is doing the conjoint experiment this function triggers the "Next"click

Joffm

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 4 weeks ago by Joffm.

Please Log in to join the conversation.

More
1 year 4 weeks ago #241812 by jelo

So you have to think about a different approach.
An easy one:
Place the link to your Conjoint experiment in a question of type "text display"
 
Wouldn't that allow a complete circumvention off the conjoint experiment?
LimeSurvey seems lacking a few functions to better integrate third party websites into one survey.
Allow redirection during a survey and ensure that people reenter the survey via URL-link at a certain point (not always the last page saved by the session file).
I always used two survey with Sawtooth in between, which gave you headaches when you need to access data from the other survey.

 

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

Please Log in to join the conversation.

  • jsmatte1
  • jsmatte1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 4 weeks ago #241828 by jsmatte1
Hi Joffm,

I like your idea. However, I need to pass a token also to Sawtooth. Is there a way I can combine the approach used in the links I provided in my question, and your work around to ensure LS registers to go to the next question?

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 4 weeks ago #241831 by Joffm
You add the token to the link the same way as shown in your scripts.
As usual:
www.mypage.com?para1=ABC&para2=123


And to answer @jelo:
Yes, I forgot that I some long time ago showed such a scenario with two surveys.

And, yes, you can circumvent the conjoint part. But this is done by intention, And these respondents to screenout.
And if you only show a button which links to the sawtooth part and hide the "Next" button, it should be neglectable.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • jsmatte1
  • jsmatte1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 4 weeks ago #241859 by jsmatte1
FYI, your suggestion does not seem to work. Implemented it but it looks like the timer stops when respondents leaves LS to go to Sawtooth, and lands again on the same LS page, then has to wait 30s. for the auto click to happen.

Only way I can make it work is if the link to Sawtooth opens in a new tab, such that the LS page remains open until the auto trigger clicks to next.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 4 weeks ago #241860 by Joffm
How did you implement it?
Show it

Send a lss export of the protzotype!

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • jsmatte1
  • jsmatte1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 4 weeks ago #241861 by jsmatte1
This is the work around I have come up with. However, when I run the question preview, it behaves as expected and redirects to Sawtooth, whereas when I preview the survey, it stays on the question page...
Code:
<p>Please click to be redirected to the choice tasks.</p>
<button>Go to choice tasks</button><script>
$(document).ready(function() {
      var idnum=1234;
      // var idnum="{TOKEN:TOKEN}";
      var url="https://mystudy.com/cgi-bin/ciwweb.pl?studyname=mystudy&amp;amp;panelid="+idnum;
 
      $('#ls-button-submit').hide();
 
      $('button').click(function () {
            $('#ls-button-submit').trigger('click').show()
            $(location).attr("href", url);
            return false;
            });
 
      });
</script>

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 4 weeks ago - 1 year 4 weeks ago #241862 by Joffm
Yes, this is your old approach.
But I proposed this.
Code:
<a class="btn btn-primary btn-lg active" href="http://www.server.de?panelid={SAVEDID}" role="button" target="_blank">Please, click to enter the experiment</a>        
 
<script type="text/javascript" charset="utf-8">
      $(document).ready(function(){
            $('#ls-button-submit').hide();
            setTimeout(function () {
               $('#ls-button-submit').trigger('click').show();
          }, 30000);  // Proceed after 30 seconds
    });
</script>


 
Adapt to your needs.
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 4 weeks ago by Joffm.

Please Log in to join the conversation.

  • jsmatte1
  • jsmatte1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 4 weeks ago #241869 by jsmatte1
Hi Joffm,

Yes, but as I mentioned previously, your proposed method only works if you open a new tab when redirecting outside of LS. I see that you added target="_blank" for that, but it is not the cleanest way to do it as you will have two tabs open, and as someone else pointed out, this could make respondents circumvent the choice tasks altogether.

Is there a way this could work without the target="_blank"?

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 4 weeks ago #241870 by tpartner
An alternative may be to redirect to an intermediate PHP page before redirecting to Sawtooth. This PHP page could use the API to increment (or change) the "lastpage" value of the response so when the respondent returns to the survey after Sawtooth (via token response persistence) they land at a new "lastpage".

A note: To update the response via the update_response() method, you will also need to enable "Allow multiple responses or update responses with one token" - manual.limesurvey.org/Participant_settin...onses_with_one_token .

Here is a small PHP example which:

- Uses the export_responses_by_token() method to determine the response ID and lastpage values.
- Increments the lastpage value.
- Uses the update_response() method to modify the lastpage value.
- Redirects to another webpage.

Code:
<?php
 
  require_once 'jsonRPCClient.php';
 
  define( 'LS_BASEURL', 'http://localhost/limeSurvey3x');  
  define( 'LS_USER', 'admin' );
  define( 'LS_PASSWORD', 'password' );
 
  $iSurveyID = $_GET['sid'];
  $sToken = $_GET['token'];
 
  if(ctype_alnum($iSurveyID) &amp;&amp; (strlen($iSurveyID) == 5 || strlen($iSurveyID) == 6)) { // Valid SID format
 
    // Instantiate a new RPC client
    $myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' );
 
    // Get a session key
    $sSessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
 
    if(is_array($sSessionKey)) { // Invalid session
      echo $sSessionKey['status'];
    }
    else if($sSessionKey) { // Valid session
 
      // Get a response by token to determine the response ID and lastpage values
      $aFields = array('id', 'lastpage');
      $tokenResponse = $myJSONRPCClient->export_responses_by_token($sSessionKey, $iSurveyID, 'json', $sToken, null, 'all', 'code', 'short', $aFields);
 
      if(is_array($tokenResponse)) {
        // Oops, a response error...
 
        // Print any errors
        print_r($tokenResponse);
 
        // Release the session key
        $myJSONRPCClient->release_session_key( $sSessionKey );
      }
      // 
      else {
        // There is a valid response...
 
        // Decode the returned base-64 string and convert to an array
        $decodedString = base64_decode($tokenResponse);
        $tokenResponseArr = json_decode($decodedString, True);
        // Get the first item in the $tokenResponseArr['responses'][0] array
        $tokenResponseArr2 = reset($tokenResponseArr['responses'][0]);
 
        // Define vars for the response ID and lastpage values
        $responseID = $tokenResponseArr2['id'];
        $responseLastpage = $tokenResponseArr2['lastpage'];
 
        // Increment the lastpage
        // ...or, you could hard-code a lastpage value here instead
        $responseLastpage++;
 
        // Update the response lastpage value
        $aResponseData = array(
          'id' => $responseID,
          'lastpage' => $responseLastpage
        );
        $updatedResponse = $myJSONRPCClient->update_response($sSessionKey, $iSurveyID, $aResponseData);
 
        // Release the session key
        $myJSONRPCClient->release_session_key( $sSessionKey );
 
        // Redirect to the next site
        header("Location: https://google.com");
        die();
      }
    }
  }
  else { // Invalid SID format
    die( 'Invalid format!' );
  }
 
?>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 3 weeks ago #241998 by DenisChenu
@tpartner : i think you need Increments the lastpage value by 2, because it was set to the previous page, not current.

See gitlab.com/SondagesPro/coreAndTools/KeepCurrentStep

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose