How to get the IP address of the participant?

Description of the problem: I have a learning experiment where we are trying to understand how people learn to make decisions. This is why I want to make sure that I dont have the same person do the experiment twice. Is there some way for me to save the IP address?

Typically this is something you’d manage from your recruitment system (e.g. Prolific). You would set that so that participants can only come once.

Thank you

1 Like

I was also wondering if there is a way to detect the IP address. For example, Qualtrics returns the ip addresses of the participants (without any name or surname obviously).

Has anybody found a way to do it in javascript? Saving the ip in the data output?

Hello, in case it can be useful per somebody, I figured it out:
You have to create a component (better if at the beginning of the experiment) with the following code:

  $.getJSON('https://api.ipify.org?format=json', function(data){

    console.log(data.ip);
    localStorage.setItem('ip',data.ip);

    psychoJS.experiment.addData('IP_Addresss', data.ip)

  });
2 Likes

How exactly do you implement this code? When copying it exactly as you wrote to a code component which runs at the begin of the experiment, my experiment gets stuck in “initializing the experiment…”

Hello,
I made a code component in the very first routine, and inserted the code in “Begin Experiment”, in the Javascript section.
Hope it helps!

1 Like

Hi Jon,

Just to confirm, if we are are not using a recruitment system such as Prolific, and the experiment is entirely run through PsychoPy/Pavlovia (it is not linked to Qualtrics), there is no way to programme it so that an IP address can not be ‘repeated’?

Thanks.

I could write a PHP/MySQL app similar to my existing survey.php and pavlovia.php apps (see my crib sheet) which also counted IP addresses. However, it would probably need to record completions and IP address isn’t a one to one mapping to individual or even device. It might be possible to record some additional information to help distinguish between devices but it still wouldn’t be perfect.

Hi Wakecarter,

Thank you for that offer. It sounds as if it would be a lot of work for something that wouldn’t necessarily solve the problem. I’ll try linking with Qualtrics to prevent multiple submissions from the same IP address (assuming the user isn’t tech savvy).