Saving respondent's paradata

More
3 years 10 months ago #116809 by eloner
eloner created the topic: Saving respondent's paradata
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 or Create an account to join the conversation.

More
3 years 10 months ago #116817 by tpartner
tpartner replied the topic: Saving respondent's paradata
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.
The following user(s) said Thank You: eloner

Please Log in or Create an account to join the conversation.

More
3 years 10 months ago #116823 by eloner
eloner replied the topic: Saving respondent's paradata
Wow!!!!
It works perfectly!
Thank you Tony for your precious help!!!!
Elo

Please Log in or Create an account to join the conversation.

More
2 weeks 3 days ago #177341 by gremlin
gremlin replied the topic: Saving respondent's paradata
Hi Tony,

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

Gre

Please Log in or Create an account to join the conversation.

More
2 weeks 3 days ago #177344 by tpartner
tpartner replied the topic: Saving respondent's paradata
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.
The following user(s) said Thank You: gremlin

Please Log in or Create an account to join the conversation.

More
2 weeks 3 days ago #177345 by gremlin
gremlin replied the topic: Saving respondent's paradata
Still doesn't seem to work. The fields are returning blanks on the view responses page.

Please Log in or Create an account to join the conversation.

More
2 weeks 3 days ago #177349 by DenisChenu
DenisChenu replied the topic: Saving respondent's paradata
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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
The following user(s) said Thank You: gremlin

Please Log in or Create an account to join the conversation.

More
2 weeks 3 days ago #177367 by holch
holch replied the topic: Saving respondent's paradata
Is your survey set up to use Javascript?

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds
The following user(s) said Thank You: gremlin

Please Log in or Create an account to join the conversation.

More
2 weeks 3 days ago #177381 by tpartner
tpartner replied the topic: Saving respondent's paradata

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

Please Log in or Create an account to join the conversation.

More
2 weeks 3 days ago #177383 by gremlin
gremlin replied the topic: Saving respondent's paradata
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 or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!