Welcome to the LimeSurvey Community Forum

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

collecting browser information

  • pomaikai
  • pomaikai's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 7 months ago #84094 by pomaikai
collecting browser information was created by pomaikai
It is possible for limesurvey to collect browser version and screen resolution and media device ie pc, tablet etc automatically from participants.

I though I could issue a url with id and pass to google analytics and somehow merge the data at a later stage, but does anyone know of an easier way.

cheers

tom
The topic has been locked.
More
11 years 7 months ago - 11 years 7 months ago #84097 by Ben_V
Replied by Ben_V on topic collecting browser information
Hi,
you can try to use this following code in the source of a long free text question (adapted from another code I've found few weeks ago in the forum and working well with my installation)

You just have to adapt the var IDs (see 3 first lines) with yours...
(the last line will hide the question)

Code:
<script type="text/javascript">
var SID = '123';  // survey ID
var GID = '456';    // group ID
var QID = '789';  //  question ID
 
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName  = navigator.appName;
var fullVersion  = ''+parseFloat(navigator.appVersion); 
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;
 
// In Opera, the true version is after "Opera" or after "Version"
if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
 browserName = "Opera";
 fullVersion = nAgt.substring(verOffset+6);
 if ((verOffset=nAgt.indexOf("Version"))!=-1) 
   fullVersion = nAgt.substring(verOffset+8);
}
// In MSIE, the true version is after "MSIE" in userAgent
else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
 browserName = "Microsoft Internet Explorer";
 fullVersion = nAgt.substring(verOffset+5);
}
// In Chrome, the true version is after "Chrome" 
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
 browserName = "Chrome";
 fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari" or after "Version" 
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
 browserName = "Safari";
 fullVersion = nAgt.substring(verOffset+7);
 if ((verOffset=nAgt.indexOf("Version"))!=-1) 
   fullVersion = nAgt.substring(verOffset+8);
}
// In Firefox, the true version is after "Firefox" 
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
 browserName = "Firefox";
 fullVersion = nAgt.substring(verOffset+8);
}
// In most other browsers, "name/version" is at the end of userAgent 
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < 
          (verOffset=nAgt.lastIndexOf('/')) ) 
{
 browserName = nAgt.substring(nameOffset,verOffset);
 fullVersion = nAgt.substring(verOffset+1);
 if (browserName.toLowerCase()==browserName.toUpperCase()) {
  browserName = navigator.appName;
 }
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1)
   fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1)
   fullVersion=fullVersion.substring(0,ix);
 
majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
 fullVersion  = ''+parseFloat(navigator.appVersion); 
 majorVersion = parseInt(navigator.appVersion,10);
}
 
$(document).ready(function() {
  $('#answer'+SID+'X'+GID+'X'+QID).val(''
+'Browser name = '+browserName+'<br>'
+'Full version = '+fullVersion+'<br>'
+'Major version = '+majorVersion+'<br>'
+'navigator.appName = '+navigator.appName+'\n'
+'navigator.userAgent = '+navigator.userAgent); 
 
// hiding the question 
$('#question'+QID).hide();
 
});
</script>
Ben/

Remember that if you want to use javascript within Limesurvey you have to disable a security filter before you can add your javascript in source code mode. =>Go to global settings and set the setting 'XSS-Filter' to 'off'.

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last edit: 11 years 7 months ago by Ben_V.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 7 months ago #84099 by holch
Replied by holch on topic collecting browser information
Google Analytics data is usually agregated. I am not an expert, but in my opinion you should not be able connect they survey data with the GA data.

However, Google is getting this information via Javascript, so you should be able to create a script reading this and then write it into hidden questions.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 7 months ago #84101 by holch
Replied by holch on topic collecting browser information
Benitovs answer works for me as well. Now you just need to find a way to access the information about resolution (or is it the viewport you want to know?) and the media type.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
More
11 years 7 months ago - 11 years 7 months ago #84105 by Ben_V
Replied by Ben_V on topic collecting browser information
for screen size maybe you can use a 2nd hidden question... for example button radio list, prechecked via javascript...
using some code like this (not tested, it's just an idea ...) ;)
Code:
<script type="text/javascript" charset="utf-8"> 
  var SID = '012';  // survey ID
  var GID = '345';    // group ID
  var QID = '678';  //  question ID
 
  $(document).ready(function() {
    if (screen.width==800||screen.height==600) //if 800x600
    {$('#answer'+SID+'X'+GID+'X'+QID+'A1').attr('checked', true);}
 
 
    else if (screen.width==640||screen.height==480) //if 640x480
    {$('#answer'+SID+'X'+GID+'X'+QID+'A2').attr('checked', true);}
 
 
    else if (screen.width==1024||screen.height==768) //if 1024x768
    {$('#answer'+SID+'X'+GID+'X'+QID+'A3').attr('checked', true);}
 
    else //if all else
    {$('#answer'+SID+'X'+GID+'X'+QID+'A0').attr('checked', true);}
 
  // document.limesurvey.submit();
  });
 
</script>

Note A0, A1, A2... are the codes for your answer options.
Benoît.

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last edit: 11 years 7 months ago by Ben_V.
The following user(s) said Thank You: pomaikai
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 7 months ago #84107 by holch
Replied by holch on topic collecting browser information
@Benitov: I wouldn't create a closed question. I would write the screen resolution directly into the same text field. Because today the list of screen resolutions can be quite ample, with more and more mobile devices (smartphones, tablets) on the market.

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: pomaikai
The topic has been locked.
  • pomaikai
  • pomaikai's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 7 months ago #84109 by pomaikai
Replied by pomaikai on topic collecting browser information
Thank you all so much for your input.

I want to try to gain as much information about the device being used by the respondents similar if you like to the spec here www.w3.org/TR/2012/REC-css3-mediaqueries-20120619/

@Benitov: thank you for the code.
@holch: you have 'hit the nail on the head' as it were. I am putting together a research project looking at web site design and its relationship with browsing behaviour on a commerce site based on different devices because as you say mobile and tablets are more and more important.

If it is possible to collect details of the device etc automatically it will save a lot of bother later on.

I now appreciate that javascript within a question would appear to be the way to go. I had not considered that, nor can I write it, but I am familiar with other basic code so will have a play.


Thanks again

Tom
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 7 months ago #84111 by holch
Replied by holch on topic collecting browser information
So you might want not only the screen width, but also the view port. But this is all accessible with JavaScript.

Here maybe also an approach to find out the device:

www.abeautifulsite.net/blog/2011/11/dete...ces-with-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: Ben_V
The topic has been locked.
More
11 years 7 months ago #84122 by Ben_V
Replied by Ben_V on topic collecting browser information

now appreciate that javascript within a question would appear to be the way to go. I had not considered that, nor can I write it, but I am familiar with other basic code so will have a play.


So ... in the same serie the following code can be a good base to gather the browser window size !
Code:
<script type="text/javascript">
 
var SID = '123';
var GID = '456';
var QID = '789'; 
 
jQuery(document).ready(function() {
 
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  }
  else if( document.documentElement &amp;&amp; ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  }
  else if( document.body &amp;&amp; ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
 
   $('#answer'+SID+'X'+GID+'X'+QID).val(myWidth +' X '+ myHeight); 
 
 
});
</script>

Ben/

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.
  • pomaikai
  • pomaikai's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 7 months ago - 11 years 7 months ago #84169 by pomaikai
Replied by pomaikai on topic collecting browser information
I can get the scripts to work however, I can only get them working depending on certain settings.

Scripts work when the survey is set formatted to be 'question by question' but not 'all in one'. I can get them to work 'group by group' as long as there is not more than one script in each group.

I have searched as best I can the forums and the work arounds to no avail.

I assuming at this stage that when loading the scripts are conflicting / affecting each other, but I am unsure how to isolate them so that they don't. When loading 'all in one' it is always the last script that essentially works.

Do you know if this is a limitation of Limesurvey or I am doing something obviously wrong.

Limesurvey Version 1.92+ Build 120725

Tom
Last edit: 11 years 7 months ago by pomaikai. Reason: typos
The topic has been locked.
  • pomaikai
  • pomaikai's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 7 months ago #84170 by pomaikai
Replied by pomaikai on topic collecting browser information
OK, I am a plonker !

Should have noticed I was defining the same variable more than once on the same page.

Please ignore last.

Tom
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 7 months ago #84178 by holch
Replied by holch on topic collecting browser information
Why do you need to create various scripts anyway? You could put all into one big script, I guess.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose