Skip to content

Instantly share code, notes, and snippets.

@mackenziechild
Last active October 10, 2020 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mackenziechild/c42e28f46c6fb31cf466596ebffadad9 to your computer and use it in GitHub Desktop.
Save mackenziechild/c42e28f46c6fb31cf466596ebffadad9 to your computer and use it in GitHub Desktop.
This will add meta data to the member profile in Memberstack which allows us to hide or show the mark as complete form.
<script src="https://api.memberstack.io/static/memberstack.js?webflow" data-memberstack-id="[GET FROM MEMBERSTACK]"></script>
<script>
MemberStack.onReady.then(async function(member) {
// Checks if member is logged in
if(member.loggedIn){
const metadata = await member.getMetaData();
// If no metadata.video exists, create it in MemberStack.
metadata.videos = metadata.videos || [];
// Defines the webflow video ID to a const of itemID (Pull this from the CMS)
const itemID = "[GET FROM CMS]"
// If they have the item ID in their profile, hide the form, show the 'completed button'
if(metadata.videos.includes(itemID)){
document.getElementById('mark-as-watched').style.display = 'none';
document.getElementById('video-complete').style.display = 'block';
}
// When the button is clicked, if the itemID doesn't exist on their profile
// add it, then push the metadata to MemberStack.
$('#mark-as-watched').click(function(){
if(metadata.videos.indexOf(itemID) === -1){
metadata.videos.push(itemID);
member.updateMetaData(metadata);
}
});
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment