So i have this Java script (Genereated with ChatGPT) to gather som information about the user. This information will be saved in a Data Type called device_info, this device_info will contain the following data fileds:
IP Address
City
Country
ISP
Latitude
Longitude
Browser
Language
Screen size
Platform
Cookies enabled
Java script (by chatGPT):
async function getUserInfo() {
let info = "";
// Get IP and location
try {
const ipRes = await fetch("https://ipapi.co/json/");
const ipData = await ipRes.json();
info += `IP Address: ${ipData.ip}\n`;
info += `City: ${ipData.city}\n`;
info += `Country: ${ipData.country_name}\n`;
info += `ISP: ${ipData.org}\n`;
info += `Latitude: ${ipData.latitude}, Longitude: ${ipData.longitude}\n\n`;
} catch (error) {
info += "Unable to fetch IP information.\n\n";
}
// Browser information
info += `Browser: ${navigator.userAgent}\n`;
info += `Language: ${navigator.language}\n`;
info += `Screen size: ${screen.width}x${screen.height}\n`;
info += `Platform: ${navigator.platform}\n`;
info += `Cookies enabled: ${navigator.cookieEnabled}\n`;
document.getElementById("info").innerText = info;
}
// Run the function
getUserInfo();
I have used Java script to bubble and the Tool box plugin before to save 1 data type but not sure how to do it with so many and what the best way is?
Step 4. Extract the data with Regex, i will share below the regex i used to only get the result and not the full JSON with quotes and everthing: "IP:"192.29.22.22", with Regex you will only save 192.29.22.22 (users IP adress)
Regnex Filters:
IP Regnex: (?<="ip":")[^"]+
City Regnex: (?<="city":")[^"]+
Country Regnex: (?<="country":\s*")[^"]+(?=")
Browser Regnex: (?<="browser":\s*")[^"]+(?=")
Dark Mode Regnex: (?<=^|\s)"darkMode":\s*(true|false)
DISCLAIMER: I do not have any programing knowlage and im not the best Bubble developer so i do not know if this is the best or most optimal way to do this but it works good for me. DISCLAIMER 2: If you have your service in the EU, remeber to comply with GDPR when you collect this data
If you found this useful, please consider giving it a like because i spent a lot of time with ChatGPT trying to figure this out.