MemberStack.io

Redirect Power Up

Hi there,

I’m trying to work my way through the redirect power up but not sure where I’m supposed to paste the code snippets? Would someone just expand a bit more on how to use this power up please?

(I’m working through Webflow)

2 Likes

Hey @jvaleur! I’m looking into this now… it seems like the code isn’t working correctly anymore. I’ll follow up soon!

1 Like

Alright! Tyler figured it out. The code that’s currently in the dashboard only works if your signup and login redirects are different. Tyler updated the code, and it will go live when we publish again. In the meantime, here’s a quick explainer video and the new code.

Use this code to save the current URL and redirect back after signup/login:

<script>
MemberStack.onReady.then(function(member) {
    if (!member.loggedIn) sessionStorage.setItem('redirect',window.location.href);
})
</script>

Place this on your page after signup/login

<script>
  var redirect = sessionStorage.getItem('redirect')
  sessionStorage.clear();
  if (redirect) window.location.replace(redirect)
</script>
1 Like

Hi Duncan,

Thank you for the video, I’ve tried to do exactly as you showed in the video:
Put the first snippet in the page i want to redirect them to
Put the second home on my home page as it is the one that is defined in the memberstack portal as the redirect when signing in/ up.

However it doesn’t work and makes my site go mad. When I sign up, it goes to the home url, but the page itself doesn’t load, it’s like it keeps trying to load a page but never reaches it.

Did I do anything wrong?

1 Like

Can you share a link to the page with the first code snippet? I’ll do a few tests, and see what’s going on.

Hi Duncan,

With us going live so soon, and the code breaking the site so much I can’t leave it in there unfortunately as we also need to be able to test other pages.

1 Like

I was actually going to recommend the same thing. I’ll do some tests on a demo site and let you know when it’s more stable. You can install it on a test page after launch if it’s important.

Hi @DuncanHamra , I was wondering if you had found a solution for this? Would it be helpful if i duplicate my website so you can do test on that one?

1 Like

Hi @jvaleur! We updated the code and ran a few tests.

You can see it in action on this site.

  1. Scroll to the bottom and click on Free with Paywall
  2. Create an account.
  3. You should get redirected back to the Free with Paywall post.

You can find the updated code on the Power-ups page.

1 Like

Hi @DuncanHamra, I have tried again but the same issue seems to be happening.

I’ve added the first snippet to one of my article template
I’ve added the second snippet to the home page (where users get redirected when they sign up)
I’ve published the changes on the testing site on webflow.

When i tried to open my home page it just keeps reloading and reloading with never doing anything. The page itself is completely blanks. I have recorded a quick video of my screen if that would help, i can send it to you by email?

Ohhh… I think it has something to do with your redirect being the homepage :thinking: I’ll test that…

Is there any chance you added one of those code snippets to the header of your entire site?

Update:
I just checked, and it looks like there’s some old code in the header of your entire site above the MemberStack script! :partying_face: I think that’s causing the issue.

Hey there, I am also having a problem implementing the redirect power up despite following the instructions in the video.

I have 3 protected test pages (with the 1st part of the code included in the header):

I have a page after sign-up (with the 2nd part of the code included in the header):

And a page after login-in (also with the 2nd part of the code included in the header):

  • …/memberstack/page_after_log_in.htm

If I try to visit any of the 3 protected pages I do not get redirected back to that page after signup/login.

1 Like

@belltyler do you think @golfempire’s problem is caused by the .htm at the end each link? I know we’ve had problems with this sort of naming convention before, but I can’t remember why or what the solution was.

@golfempire after reviewing your site, I’m 90% sure it has to do with the links. You actually don’t need the code snippets since you’re linking directing to that hidden content. The above redirect code is only required when you have a partially gated page that you want to redirect users back to after signup. By default, MemberStack will remember which hidden URLs a user clicks on and send them back there after signup/login.

Hi Duncan, ok thanks for the info and getting back to me on a Sunday!

So I have removed the power up redirect code snippets from the pages now. As before I am not taken back to the protected url that I initially clicked on. Good to hear that this should be the default behaviour though.

I’m unable to remove the .htm extension - hopefully there is a solution?

1 Like

Hi @DuncanHamra - That fixed it!! :partying_face:

Sorry i didn’t notice that, but thank you so much for all your help! Works amazingly :slight_smile:

1 Like

@golfempire the .htm extension shouldn’t make a difference.

I think I see what’s happening…

The 1st part of the code relies on MemberStack’s onReady function which doesn’t fire if a redirect occurs. So any user who visits one of those pages that doesn’t have permission, gets immediately redirected and the onReady function never fires.

Like @DuncanHamra said, we do have a built in feature that will redirect back to a hidden page if a user clicked on a link to it. Just not if they try to navigate to it directly.

Do you think that would work for you?

Hi @belltyler

Noted re the .htm extension, that’s good news.

I’m not sure I fully understand the difference (I’m not a professional coder etc…) but the built in feature sounds like it would work fine.

So, are you saying if I visit a public page and then click a link to one of the protected pages I should automatically get taken back to the specific protected page I clicked on, once I have signed up/logged in? If so, that doesn’t seem to work for me.

I have created a public page here: https://www.golfempire.co.uk/memberstack/public_page_1.htm with hyperlinks to the protected pages.

To confirm I have now removed the power up redirect script.

Thanks

Yes, that’s how it’s suppose to work :smile:

Can you try adding those public links to a page that is not contained within your memberstack folder?

So instead of /memberstack/public-page can you do /public-page? This is just for testing purposes. I think if you do that, this will start working.

If that’s the case, then we need to improve how MemberStack handles relative links.

1 Like

Hi @belltyler

I’ve done that - https://www.golfempire.co.uk/public_page_1.htm

But I still get the same results. I just get taken to the “page after sign-up” or “page after login” and not back to the specific protected page url that I tried to visit.

Do I even need a “page after sign-up” or “page after login”? It will not allow me to leave these fields blank in the memberstack dashboard.

I’m sure it is something I have done wrong at my end but I cannot figure out what!

1 Like