/* Author: EK Date: 06/14/2022 Purpose: The code below allow the capture of the user responseID, email address, Facebook user profile token and Facebook user profile endpoints they select. The response id and email are embedded on Volunteer Science experiment link in this format https:&responseID=<$responseID>&email=<$email_address> See Qualtrics folder for more information on how the link is generated Code:Display Facebook user profile table for selection and experiment completion button Scope: This code is exclusively used for Qualtrics end of survey or email. i.e. The respondent take the survey in Qualtrics and are redirected to Volunteer Science via an iframe in Qualtrics, email, or url redirect. Note: Functions not defined within this script are part of Volunteer Science backend code */ // Capture email and response id from the redirect URL var params = new URLSearchParams(location.search) var responseID = params.get('responseID') var emailAddress = params.get('email') /* Function that determines the type of device the user is using This allows proper rendering of the user interface */ const deviceType = () => { const ua = navigator.userAgent; if (/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(ua)) { return "tablet"; } else if (/Mobile|Android|iP(hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(ua)) { return "mobile"; } return "desktop"; }; // function initialize() { // } // Variable to capture endpoints selected from user interface var permissions_sought=[] var permissions_granted='' var fbid='' //login to the app and request the permissions the user selected in the table //permissions_sought is a list e.g. ['email','user_likes'] function requestAccess(permissions_sought){ $("#quit_btn").attr("disabled","disabled"); permissions_sought=permissions_sought.join(',') console.log(permissions_sought) if (permissions_sought.length !==0) { FB.login(function(response) { if (response.authResponse) { permissions_granted=response.authResponse.grantedScopes console.log('granted', permissions_granted) FB.api('/me', 'GET', {fields: ['id','token_for_business'], access_token:response.authResponse.accessToken}, function(response){ fbid=response data = {responseId: responseID, email: emailAddress, language:"en", endpoints:permissions_sought, facebook_response: fbid['id']+','+fbid['token_for_business']+','+permissions_granted } submit(data) //save the ids and $('#approve').show() $('#done').show() $('#form').hide() }); } else { //something went wrong $('#error').show(); $('#form').hide(); } }, { scope: permissions_sought, return_scopes: true } ); } else { $('#no-selection').show(); $('#form').hide() } } //get the permissions they elected and turn it into a list function getDataFromTable(){ if (document.getElementById("user-posts").checked){ permissions_sought.push('user_posts') } if (document.getElementById("user-likes").checked){ permissions_sought.push('user_likes') } if (document.getElementById("user-friends").checked){ permissions_sought.push('user_friends') } if (document.getElementById("user-birthday").checked){ permissions_sought.push('user_birthday') } if (document.getElementById("user-link").checked){ permissions_sought.push('user_link') } /* Pending as of 6-13-22 */ // if (document.getElementById("user-gender").checked){ // permissions_sought.push('user_gender') // } // if (document.getElementById("user-hometown").checked){ // permissions_sought.push('user_hometown') // } // if (document.getElementById("user-age-range").checked){ // permissions_sought.push('user_age_range') // } // if (document.getElementById("user-location").checked){ // permissions_sought.push('user_locatin') // } } //get the permissions and request them from Facebook //results in an update to permissions_granted as list of what permissions they actually selected in the FB app function makeRequest(){ //Disables VS quit button to prevent accidental experiment closure getDataFromTable() requestAccess(permissions_sought) } function returnForm(){ $('#no-selection').hide() $('#error').hide() $('#form').show() } function closeExperiment() { /* closes the experiment and redirects to Volunteer science main page */ experimentComplete(); quit(); // Close experiment window. This is necessary as experimentComplete() takes back users to // main experiments page let new_window = open('https://volunteerscience.com', '_self'); new_window.close() alert("Thank you for participating on our research"); }