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