Download Limitation

Hi there !

I’m totally blocked on Memberstack anf Webflow.
I want to establish a monthly download limit for users. When a member has a custom attribute with Memberstack set to false, this prevents them from downloading additional files. It blocks access to the external URL link of the button and displays a popup that suggests upgrading to download more files. If the custom attribute value is true, the member can click on the download button and proceed to download the document.
I would like your point of view :

Preview link :
https://preview.webflow.com/preview/leadrocket-dashboard-v2?utm_medium=preview_link&utm_source=designer&utm_content=leadrocket-dashboard-v2&preview=546a378a5483dd8646d9149ebbf08409&pageId=64c11881c994e54ce5e5cad3&itemId=6500248379fa1710e58aba33&workflow=preview

This is my code :

<script>
  document.addEventListener('DOMContentLoaded', function() {
      const downloadButton = document.getElementById('DownloadButton');
      if (downloadButton) {
          downloadButton.addEventListener('click', function(e) {
              const divCanDownload = document.getElementById('div-candownload');
              if (divCanDownload) {
                  const canDownload = divCanDownload.getAttribute('data-ms-member');
                  if (canDownload === "false") {
                      e.preventDefault(); // prevents navigating to the external URL
                      const popup = document.getElementById('popup');
                      if (popup) {
                          popup.style.display = 'block'; // show the popup
                      }
                  }
              }
          });
      }
  });
</script>

Which part are you having difficulty with? Generally I’d setup this system as;

  • Function to capture and record the debit event
  • Function to determine remaining credits
  • Function to determine whether viewing is allowed and display the popup if not
  • Process to reset usage counts at the end of the month

It’s pretty easy to do 1 through 3 using MS user data fields directly, but #4 might be trickier, I’m not sure if there is an MS API that gives you access to that data.

How you do this also depends on whether your “months” are calendar months or based on the date of subscription, e.g. Jan 7 to Feb 7.

Another approach to #4 might be to store both that subscription start date and the total downloads. You can then calculate allotment ( e.g. total membership timeframe / 30 days ) and usage ( total downloads ). However it will work like Audible credits- they’ll accumulate when unused.