MemberStack.io

What are the Front End API Variables?

I’m looking to use Mixpanel with my Memberstack implementation to track whether users are signed up and active.

Below is my code for

    <script>
    MemberStack.onReady.then(function(member) {  

    var membership = member.membership;


    mixpanel.people.set({
        
        "MEMBERSHIP_ID": membership.id,    // use human-readable names
        
        "MEMBERSHIP_STATUS": membership.status,    // ...or numbers

        "MEMBERS_LOGGED_IN": member.loggedIn,
        });
            
        mixpanel.identify(membership.id);
    })
</script>

My questions are the following:

  1. What does membership return when a user hasn’t signed up yet?
  2. How can I track email addresses using front end api?
  3. Can I access custom user fields from the front-end api?

See this for more info: https://help.memberstack.io/post/front-end-api

  1. when a user is not signed up yet, member.membership will return undefined
  2. member[“email”] will return the logged in member’s email address. Or you can access all members’ email addresses using the MemberStack dashboard
  3. Yes. Using JavaScript, member[“FavoriteBeer”] will return the value of the FavoriteBeer custom field for that user

Also, membership.id will return the ID of the membership (e.g., 5c9e44e9e23563344926562b) and not a human-readable membership plan name (e.g., Premium Plus). You could easily convert this in JavaScript. Something like this should do the trick:

if(membership.id == "5c9e44e9e23563344926562b"){  
    var membershipPlan = "Premium Plus";
    //then do something for Premium Plus members
}
else {
    var membershipPlan = "Basic";
    //then do something for Basic members
}
2 Likes

Would you know how to return the ID seen here? I’m familiar with using Postman to manually call the API is given the endpoint.

To find out which of your plans correspond to this ID, go to the MemberStack dashboard. Click “Memberships” on the left menu, then click the “Buttons” button (right side of screen) for each of your membership plans. This will show you which human-readable plan that the ID you identified above corresponds with.

Here is what mine looks like when I click “Buttons”. So the ID shown in this picture corresponds to my Premium membership plan.

That ID I showed isn’t the plans membership ID, it is another ID that is specific to each user.

I’m familiar with that ID and appreciate your insight.

Yeah, I don’t think a user’s unique ID is accessible via API. @belltyler would certainly know though!

1 Like

Actually, I just tried member.id and it returns what looks like the user’s unique ID. This isn’t in the documentation as far as I know, but it seems to work. Good luck!

1 Like

member.id returns the member’s unique id :grinning:

1 Like

Hey! I’m trying to pull in member ID via Javascript using member.id but it’s returning a null value. Any thoughts?

Code for reference:

Inside :

<script>
var memberID;

MemberStack.onReady.then(function(member) {
   memberID = member["member.id"]
});

</script>

Before :

<script>
pullID();

function pullID() {
		document.getElementById("user-id").value = memberID;
}
</script>

Thanks in advance for any help!

1 Like

If you change member["member.id"] to member["id"] or member.id, that should do the trick!

4 Likes

Ahhh, that did the trick. Thank you!

3 Likes