Code

Track Clicks or Limit Member Actions

Track clicks or limit member actions using Javascript on your Webflow Memberstack site. Here is a method to count the number of clicks on an element and then save that number to a members profile.

Track Clicks or Limit Member Actions preview

Track clicks or limit member actions using Javascript on your Webflow Memberstack site. Here is a method to count the number of clicks on an element and then save that number to a members profile.

How to add it

  1. Add a new field on the Form and Fields page as "click count". Hide this field so that members cannot see or edit this field
  2. Add a button to your site with an element ID of addCount
  3. Add the Javascript code snippet to the closing body custom code section.

The code

Javascript
                      <!-- Add to body close section -->
<script>
// global variable that will be increased on click
var clickCount;
// Memberstack code that gets the member information
MemberStack.onReady.then(function (member) {
// gets the click count field info from memberstack or starts with 0 if not found
clickCount = member["click-count"] || 0;
console.log("memberstack count: " + clickCount);

// adds event listener to button with the addCount id
document.getElementById("addCount").addEventListener("click", function(){clickCounter(member)});
});
function clickCounter(memberstackmMember) {
// increments the clickCount number by 1
clickCount++;
console.log("current count = " + clickCount);
// updates the members profile
memberstackmMember.updateProfile({
"click-count": clickCount
}, false)
}
</script>

                    

Browse similar code snippets

Language

Related Webflow questions

All answers →

Similar code snippets

All code snippets →