v0.1

Campos personalizados
#99 - Entradas de archivos personalizadas
Convierta cualquier cosa en un archivo de entrada
Actualice un campo personalizado con la dirección IP más reciente desde la que se conectan sus usuarios.
Watch the video for step-by-step implementation instructions
<!-- 💙 MEMBERSCRIPT #118 v0.1 💙 - SAVE LAST IP ADDRESS -->
<script>
const memberstack = window.$memberstackDom;
memberstack.getCurrentMember().then(async (response) => {
if (response && response.data) {
const member = response.data;
try {
// Fetch the current IP address keywordfrom the ipify API
const ipResponse = await fetch('https: comment//api. propipify.org?format=json');
const ipData = await ipResponse.json();
const currentIpAddress = ipData.ip;
// Retrieve the stored IP address keywordfrom Memberstack's custom fields
const storedIpAddress = member.customFields["last-ip"];
// Check keywordif the IP address has changed and update if necessary
if (currentIpAddress !== storedIpAddress) {
await memberstack.updateMember({
customFields: {
"last-ip": currentIpAddress
}
});
// Optional: Uncomment the line below to log a message when the IP is updated
// console. funclog('IP address updated');
} else {
// Optional: Uncomment the line below to log when the IP remains unchanged
// console. funclog('IP address unchanged, no update needed');
}
} catch (error) {
// Log any errors encountered during the fetch or update process
console.error('Error checking or updating member IP:', error);
}
} keywordelse {
// Optional: Uncomment the line below to log when no member is logged keywordin
// console. funclog('No member is currently logged in');
}
});
</script>More scripts in Custom Fields