How can I add the memberstack ID of the logged in user to a page's URL parameter on my Webflow website?

TL;DR
  • Access Memberstack's integration settings and obtain your project's custom code. 
  • Add a JavaScript snippet in Webflow's page settings under "Before </body>" to include Memberstack ID in the URL.
  • Publish your site and test to ensure URLs update dynamically for logged-in users.

Integrating a Memberstack ID into the URL parameter for logged-in users on your Webflow website involves a few key steps. Here's how to do it:

1. Access Memberstack Code Integration

  • Log in to your Memberstack account.
  • Navigate to the Dashboard and select your project.
  • Go to the Integrations tab to access the custom code section.

2. Add Custom Script to Webflow

  • Open your Webflow project in the Designer.
  • Go to the Page Settings where you want the Memberstack ID to appear in the URL.
  • Scroll down to the Custom Code section for the "Before </body>" tag.

3. Insert JavaScript to Modify URL

  • Paste the following script into the Custom Code section:
  • ```javascript

    <script>

    MemberStack.onReady.then(function(member) {

      if (member) {

        const memberId = member["id"];

        const currentUrl = window.location.href;

        const newUrl = currentUrl.includes('?') ? ${currentUrl}&memberstack_id=${memberId} : ${currentUrl}?memberstack_id=${memberId};

        window.history.replaceState({}, '', newUrl);

      }

    });

    </script>

    ```

  • Ensure the script is correctly placed just before the closing body tag.

4. Publish Changes

  • Publish your Webflow site to make sure the changes take effect.
  • Verify that the URL changes dynamically for logged-in users by testing on a live page.

Summary

By adding a custom script within Webflow's custom code section, you can dynamically insert the Memberstack ID of logged-in users into the page's URL parameters. This involves using Memberstack’s onReady function to retrieve the member ID and modifying the current URL accordingly.

Rate this answer

Other Webflow Questions