How to show gated content for non members Planned

Post author
Josh

Hey Duncan ,

I have this scenario where I need to execute this script after some logic before it :

 

function getAccess() {
    if (getCookie('org')) {
      const elementsWithDataMSContent = document.querySelectorAll('[data-ms-content]');
      elementsWithDataMSContent.forEach(element => {
        const currentValue = element.getAttribute('data-ms-content');
        if (currentValue === 'members') {
          element.setAttribute('data-ms-content', '!members');
        } else if (currentValue === '!members') {
          element.setAttribute('data-ms-content', 'members');
        }
      });
    }
  }

it basically reverses the attribute from members to !members and vise versa , but the problem is that the content for members is not visible to non members , and I want it so when I execute this code it shows me the gated content for members.
 
how to do so , because the gated content isn't rendered for the logged out session ? 
thanks

Comments

3 comments

  • Comment author
    Duncan from Memberstack

    Hi Josh 👋 Thanks for posting. 

    When Memberstack detects at data-ms-content attribute that isn't allowed for a member, it deletes the entire element from the page. Meaning, there is no way to invert the functionality in the way you've described. 

    Can you explain why you need this feature, and I'll do my best to help you find another solution 👍 

    0
  • Comment author
    Josh

    Hi Duncan ,

    Thanks for your response,

    I want people who land on my homepage with a specific parameter to store a cookie in their browser which gives them access to my gated content without them having to log in.

    0
  • Comment author
    Duncan from Memberstack

    Okay, gotcha. I'm afraid there's no way to display the content once it's been removed 🤔 Hmmm... idea. Maybe you could create a generic member and automatically log-in the user as that member when the link parameters are present? I believe this could be done with some custom code and the DOM package. 

    https://developers.memberstack.com/docs/dom-front-end-package.

    But you'd need to make sure the member isn't able to update the profile and they understand they are logged in. And concurrent logins would need to be enabled. 

    0

Please sign in to leave a comment.