Welcome to the LimeSurvey Community Forum

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

collecting browser information

More
6 years 5 months ago #160143 by letty
Replied by letty on topic collecting browser information
Thanks for sharing the script.

I tried to adopt the script. I have updated the var ID in the first 3 lines as below.
The browser information is captured. However, the question failed to be hidden in the survey.
Is there anything I have missed?






<script type="text/javascript">
var SID = '818123';
var GID = '3069';
var QID = '121321';

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);
}

var vpw = Math.max(document.documentElement.clientWidth, window.innerWidth || 0)
var vph = Math.max(document.documentElement.clientHeight, window.innerHeight || 0)

$(document).ready(function() {
$('#answer'+SID+'X'+GID+'X'+QID).val(''
+'Browser name = '+browserName+'\n'
+'Full version = '+fullVersion+'\n'
+'Major version = '+majorVersion+'\n'
+'navigator.appName = '+navigator.appName+'\n'
+'navigator.userAgent = '+navigator.userAgent+'\n'
+'viewport-width = '+vpw+'\n'
+'viewport-height = '+vph+'\n');

// hide the question
//$('#question'+QID).hide();

});
</script>
The topic has been locked.
More
6 years 5 months ago #160158 by jelo
Replied by jelo on topic collecting browser information

letty wrote: // hide the question
//$('#question'+QID).hide();


Remove the comment marker //
Code:
$('#question'+QID).hide();

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The following user(s) said Thank You: Ben_V, letty
The topic has been locked.
More
6 years 5 months ago #160166 by letty
Replied by letty on topic collecting browser information
It works. Many thanks!
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
5 years 4 months ago #178274 by Mazi
Replied by Mazi on topic collecting browser information
Thanks for sharing the example. Are there any known reasons why Internet Explorer is stored with "browser name = Netscape"?

BTW, instead of setting the survey, group and question ID manually you can simply use this at the beginning of the code:
var SID = '{SID}'; // survey ID
var GID = '{GID}'; // group ID
var QID = '{QID}'; // question ID

Also note that the question type should be "short free text" because when using "long free text" the input field ID is different and no data may get stored. This also depends on the Limesurvey version used.

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 4 months ago #178280 by DenisChenu
Replied by DenisChenu on topic collecting browser information

Mazi wrote: Thanks for sharing the example. Are there any known reasons why Internet Explorer is stored with "browser name = Netscape"?

Can you check if it's OK on demo.sondages.pro/772229 ?

Denis

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 topic has been locked.
More
5 years 4 months ago #178281 by jelo
Replied by jelo on topic collecting browser information

Mazi wrote: Thanks for sharing the example. Are there any known reasons why Internet Explorer is stored with "browser name = Netscape"?

You see that in your results?

The NavigatorID.appName can be Netscape by default (in every browser).
developer.mozilla.org/en-US/docs/Web/API/NavigatorID/appName

The "navigator.userAgent" is relevant.

Beside that:
1. UserAgent can be forged.
2. When it comes to IE, IE forged the useragent to prevent false browser detection (in the haydays of Netscape/Mozilla). And IE had a UA string which caused a lot of cause and was stopped years ago. But older browser might still send a long userstring with crap.

blogs.msdn.microsoft.com/ieinternals/200...tring-use-and-abuse/

Mazi wrote: Also note that the question type should be "short free text" because when using "long free text" the input field ID is different and no data may get stored. This also depends on the Limesurvey version used.

A new issue with LS 3?

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
5 years 4 months ago #178288 by Mazi
Replied by Mazi on topic collecting browser information

DenisChenu wrote: Can you check if it's OK on demo.sondages.pro/772229 ?

It is fine there!

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
5 years 4 months ago #178289 by Mazi
Replied by Mazi on topic collecting browser information

jelo wrote: You see that in your results?


Exactly!

I was assuming that the stone-old code was just not able to deal with more recent browser agent details.

The issue with the field ID is not related to LS 3 but if that has changed, it must have been quite a while ago. Even at the old 2.06 version I tested, the ID of the textarea of a "long free text" question is different from what the code tries to write to (if I didn't miss anything).

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
More
5 years 4 months ago #178290 by jelo
Replied by jelo on topic collecting browser information

Mazi wrote: It is fine there!

Which is no surprise, since navigator.appVersion is not used in that demo.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 4 months ago - 5 years 4 months ago #178293 by DenisChenu
Replied by DenisChenu on topic collecting browser information

jelo wrote:

Mazi wrote: It is fine there!

Which is no surprise, since navigator.appVersion is not used in that demo.

No, and never use javascript if server can do it ;).

Use
Code:
$_SERVER['HTTP_USER_AGENT']

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.
Last edit: 5 years 4 months ago by DenisChenu.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose