I have 2 variables (source and platform) that has results such as:
“Source”: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.44 etc.
“Platform”: Win32 etc.
I want to create 2 new variables (device and system), "extracted" from the above ones.
I found some code, but I don't know how to implement it in spss syntax (or even if it's possible).
const getDeviceType = () => {
const ua = navigator.userAgent;
if (/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(ua)) {
return "tablet";
}
if (
/Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(
ua
)
) {
return "mobile";
}
return "desktop";
};
function getOS() {
var userAgent = window.navigator.userAgent,
platform = window.navigator.platform,
macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'],
iosPlatforms = ['iPhone', 'iPad', 'iPod'],
os = null;
if (macosPlatforms.indexOf(platform) !== -1) {
os = 'Mac OS';
} else if (iosPlatforms.indexOf(platform) !== -1) {
os = 'iOS';
} else if (windowsPlatforms.indexOf(platform) !== -1) {
os = 'Windows';
} else if (/Android/.test(userAgent)) {
os = 'Android';
} else if (!os && /Linux/.test(platform)) {
os = 'Linux';
}
return os;
}
I've also tried this, but every variables turns "zero":
IF PLATFORM contains the word 'Macintosh' or 'MacIntel' or 'MacPPC' or 'Mac68K'
Then SYSTEM is “Mac OS”
Else if PLATFORM contains the word 'iPhone' or 'iPad' or 'iPod'
Then SYSTEM is “iOS”
Else if PLATFORM contains the word 'Win32' or 'Win64' or 'Windows' or 'WinCE'
Then SYSTEM is “Windows”
Else if PLATFORM contains the word 'Android'
Then SYSTEM is “Android”
Else if PLATFORM does not contains ‘os’ but contains the word ‘Linux’
Then SYSTEM is “Linux”
and
IF SOURCE contains words tablet or ipad or playbook or silk or (android but not mobi)
Then DEVICE = Tablet
Else If source contains Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)
Then DEVICE = mobile
Else DEVICE = desktop
and
COMPUTE test = CHAR.INDEX(platform,"windows").
EXECUTE.
string c (A255).
IF test>0 c="windows".
EXECUTE.
COMPUTE wind = CHAR.INDEX(source,"windows").
EXECUTE.
COMPUTE wind32 = CHAR.INDEX(source,"Win32").
EXECUTE.
STRING c2 (A255).
IF wind>0 or wind32 > 0 c="Windows".
EXECUTE.
Can anyone help me on this? Thanks!