#118 - Speichern der letzten IP-Adresse des Mitglieds

Aktualisieren Sie ein benutzerdefiniertes Feld mit der letzten IP-Adresse, mit der sich Ihre Mitglieder anmelden.

Video Tutorial

tutorial.mov

Watch the video for step-by-step implementation instructions

The Code

39 lines
Paste this into Webflow
<!-- 💙 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>

Script Info

Versionv0.1
PublishedNov 11, 2025
Last UpdatedNov 11, 2025

Need Help?

Join our Slack community for support, questions, and script requests.

Join Slack Community
Back to All Scripts

Related Scripts

More scripts in Custom Fields