Skip to main content

How to insert Member Data into this script?

Hey,

I am integrating with a third part system and they have provided this code in order to push custom attributes about a members back into their service.

My questions is.. can someone help me update this script so that it will input the member-data and custom fields that I'd like to pull in from Memberstack?

You can see the placeholders that they have provided in the script. I'd like those tobe the field name and content from any custom field I choose from my MS account.

Much appreciated! I've tried a few things on my end, but not having any luck.

<script>
   **Our JS snippet goes here** 
   webpushr('attributes',{"Gender" : "Female", "User ID" : "874",  "E-mail" : "name@example.com"});
</script>

3 comments

  • Chukwudi
    Chukwudi Official comment

    Hi Dennis, 

    Here's what your code will look like:

    <script>
    window.$memberstackDom.getCurrentMember().then(async ({ data: member }) => {
        if (member) {
            // Extract custom fields from Memberstack
          const gender = member.customFields["gender"]; // Replace "gender" with the actual Custom field ID from your Memberstack account
          const userId = member.customFields["user-id"]; // Replace "user-id" with the actual Custom field ID from your Memberstack account
          const email = member.auth.email;
            // Push the member data to the third-party system
            webpushr('attributes', {
                "Gender": gender,
                "User ID": userId,
                "E-mail": email
            });

            console.log("Custom fields pushed:", { "Gender": gender, "User ID": userId, "E-mail": email });
        }
    });
    </script>


    I hope this helps.

  • Dennis Field
    Dennis Field OP

    I'm curious if anyone has any ideas here. Thanks!

    0
  • Dennis Field
    Dennis Field OP

    Thank you! I'll give this a go!

    0

Please sign in to leave a comment.

Sitemap