This article will show you how to test Memberstack 2.0 while still running your site with Memberstack 1.0. We've created some code to dynamically load the correct version of Memberstack based on the current URL.
Before you start, it's important to note that you need at least 2 domains for this code to work. A production domain (e.g. netflix.com) and a testing domain (e.g. netflix.webflow.io).
1. Add Code.
1. Copy and paste this code into your Header code. Don't hit publish until the end of the article!
<script>
var url = window.location.href
var v2_url_contains = "testing.webflow.io"
var v2_app_id = "app_YOUR_NEW_APP_ID"
var v1_memberstack_id = "YOUR_OLD_APP_ID"
var script = document.createElement("script")
script.setAttribute("type","text/javascript")
if (url.includes(v2_url_contains)) {
script.src = "https://static.memberstack.com/scripts/v1/memberstack.js"
script.setAttribute("data-memberstack-app", v2_app_id)
} else {
script.src = "https://api.memberstack.io/static/memberstack.js?webflow"
script.setAttribute("data-memberstack-id", v1_memberstack_id)
}
document.head.appendChild(script);
</script>
2. Update Code
Next, let's update the code snippet to work for our particular installation. You'll need to update 3 things...
1. In the code, update v1_memberstack_id with your Memberstack 1.0 ID. You can find the ID inside your existing 1.0 header script.
2. In the code, update v2_app_id with your 2.0 app ID. You can find he ID on the Settings page in 2.0.
3. Finally, update v2_url_contains with the domain or subdomain you want to use to test Memberstack 2.0. This could be a subdomain or a test domain.
var v2_url_contains = "testing.webflow.io"
3. Remove Old Code.
Before hitting publish, you need to remove the old Memberstacks install scripts. They look like this...
<!-- Memberstack -->
<script src="https://api.memberstack.io/static/memberstack.js?webflow" data-memberstack-id="888c1db997d6d6e5601e4d3ffc5f0ba9"> </script>
You can do this by commenting out the script, or removing the script altogether. I recommend removing it to keep things clean.
4. Save & Publish your site.
After you publish, your testing domain should load the 2.0 script (and look broken) and your production domain should continue to load the Memberstack 1.0 script.
-
Comments
0 comments
Please sign in to leave a comment.