Saving respondent's paradata

More
5 years 5 months ago #116809 by eloner
Hello!
I am using LS since 2012 and it is working fine for my purposes!
I need to save some paradata about the respondent's device (cookies enabled, browser name, engine) in the answers file.
To do this I created a question (Q10, type: equation):

File Attachment:

File Name: limesurvey...2524.lsq
File Size:2 KB



I added the following code to the question:

<p id="device">
</p>
<script>
document.getElementById("device").innerHTML =
"Cookies Enabled is: " + navigator.cookieEnabled
+ "; Browser name is: " + navigator.appName
+ "; Browser code name is: " + navigator.appCodeName
+ "; Engine: " + navigator.product
</script>

In the preview I can see the data I am requesting:

My problem is that the data should be stored in the answers, but it doesn't work.
(I also need to hide the question, but this is the second step of my problem).
What is wrong in my text? Maybe something in the code (I am not expert of Javascript :( !)?
I am using LS Version 2.05+ Build 141229.
Any suggestion would be appreciated!!!!
Thanks
elo
Attachments:

Please Log in to join the conversation.

LimeSurvey Partners
More
5 years 5 months ago #116817 by tpartner
Place the following script into a short-text question. It will hide that question and load your data.
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Hide this question
		thisQuestion.hide();
 
		// Load the text input
		$('input.text', thisQuestion).val("Cookies Enabled is: " + navigator.cookieEnabled + "; Browser name is: " + navigator.appName + "; Browser code name is: " + navigator.appCodeName + "; Engine: " + navigator.product);
    });	
</script>

Or better, this in the source of a multiple-short-text with 3 sub-questions:
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Hide this question
		thisQuestion.hide();
 
		// Load the text input
		$('input.text:eq(0)', thisQuestion).val(navigator.cookieEnabled);
		$('input.text:eq(1)', thisQuestion).val(navigator.appName);
		$('input.text:eq(2)', thisQuestion).val(navigator.product);
    });	
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: eloner

Please Log in to join the conversation.

More
5 years 5 months ago #116823 by eloner
Replied by eloner on topic Saving respondent's paradata
Wow!!!!
It works perfectly!
Thank you Tony for your precious help!!!!
Elo

Please Log in to join the conversation.

More
1 year 7 months ago #177341 by gremlin
Hi Tony,

This does not work in the latest version any more. Do the scripts need some updating? Thanks!!!

Gre

Please Log in to join the conversation.

More
1 year 7 months ago #177344 by tpartner
Try this:

<script type="text/javascript" charset="utf-8">	
	$(document).on('ready pjax:scriptcomplete',function(){
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Hide this question
		thisQuestion.hide();
 
		// Load the text input
		$('input:text:eq(0)', thisQuestion).val(navigator.cookieEnabled);
		$('input:text:eq(1)', thisQuestion).val(navigator.appName);
		$('input:text:eq(2)', thisQuestion).val(navigator.product);
    });	
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: gremlin

Please Log in to join the conversation.

More
1 year 7 months ago #177345 by gremlin
Still doesn't seem to work. The fields are returning blanks on the view responses page.

Please Log in to join the conversation.

More
1 year 7 months ago #177349 by DenisChenu
For browser name an version : gitlab.com/SondagesPro/QuestionSettingsType/findUserAgentInfo

Unsure it still work on 3.0 but can be tested

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.
The following user(s) said Thank You: gremlin

Please Log in to join the conversation.

More
1 year 7 months ago #177367 by holch
Replied by holch on topic Saving respondent's paradata
Is your survey set up to use Javascript?

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The following user(s) said Thank You: gremlin

Please Log in to join the conversation.

More
1 year 7 months ago #177381 by tpartner

Still doesn't seem to work. The fields are returning blanks on the view responses page.

It works for me. Can you activate a test survey and give a link here?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: gremlin

Please Log in to join the conversation.

More
1 year 7 months ago #177383 by gremlin
Sorry guys! Yes the new script works! I wasn't sure why it didn't at first but after replacing the entire script it worked! I had initially only replaced the 'ready pjax:scriptcomplete' portion. Thanks everyone!

Please Log in to join the conversation.

More
1 month 1 week ago #200228 by bedendo
Hi guys, I followed your steps but data is not being saved. What am I missing?

Here's what I did:
1)added new multiple short text question named device
2)pasted the following code in Source
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){

// Identify this question
var thisQuestion = $('#question{QID}');

// Hide this question
thisQuestion.hide();

// Load the text input
$('input:text:eq(0)', thisQuestion).val(navigator.cookieEnabled);
$('input:text:eq(1)', thisQuestion).val(navigator.appName);
$('input:text:eq(2)', thisQuestion).val(navigator.product);
});
</script>
3) saved the question


Here's a screenshot
Attachments:

Please Log in to join the conversation.

More
1 month 1 week ago #200229 by eloner
Replied by eloner on topic Saving respondent's paradata
Dear bedendo,
to answer we should know which version you are using.
However, on the latest release (3.2x) I found useful this solution:
forums.limesurvey.org/forum/design-issue...ed-via-mobile-device
Best,
Enzo
The following user(s) said Thank You: bedendo

Please Log in to join the conversation.

More
1 month 1 week ago #200231 by bedendo
Thanks, Enzo. I'll follow your suggestion.
I'm using Version 3.19.3+191023
Should I update or am fine with this version?
Many thanks,
Andre

Please Log in to join the conversation.

More
1 month 1 week ago #200232 by eloner
Replied by eloner on topic Saving respondent's paradata
I am not member of the LS developer's team, but it shoud work, you have just to try, the function shared in the post I sent you is vwey complete and powerful
The following user(s) said Thank You: bedendo

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now