πŸš€ How to Block Free Email Domains on Your Landing Pages with SmartBuilder β€” Even When They Said It's Impossible!

  • 10 October 2023
  • 2 replies
  • 101 views

Badge

Hey Unbounce Community! πŸš€

I recently faced a challenge where I needed to block submissions from free email domains on my landing pages built with SmartBuilder. The Unbounce tech team said it was not possible... But guess what? I've crafted a script that works like a charm, and today, I’m here to share it with all of you!
Β 

🧠 The Problem

We often need to ensure that leads coming through our landing pages are more likely B2B, and one way to do that is by preventing users from signing up using free email domains (like Gmail, Yahoo, etc.).
Β 

πŸš€ The Solution

Below is a script that allows you to block specified email domains and give visual feedback to users attempting to use them.

Β 

<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
const blockedDomains = ['me.com', 'mac.com', 'icloud.com', 'gmail.com', 'googlemail.com', 'hotmail.com', 'live.com', 'msn.com', 'outlook.com', 'yahoo.com', 'ymail.com', 'aol.com'];

const emailInput = document.querySelector('#emailField');
const submitButton = document.querySelector('#submitButton');
const originalSubmitText = submitButton.textContent;

emailInput.addEventListener('input', function() {
const domain = emailInput.value.split('@')[1];
if (blockedDomains.includes(domain)) {
emailInput.style.border = '2px solid red';
submitButton.disabled = true;
submitButton.textContent = "Please Use Your Work Email";
} else {
emailInput.style.border = '';
submitButton.disabled = false;
submitButton.textContent = originalSubmitText;
}
});
});
</script>


🧐 Script Explanation


1. Selecting Elements:
Β 

const emailInput = document.querySelector('#emailField'); const submitButton = document.querySelector('#submitButton');

  • #emailField: This should be replaced with the ID of your email input field in SmartBuilder.
  • #submitButton: Replace this with the ID of your submit button in SmartBuilder.

Β 

2. Blocked Domains:

const blockedDomains = ['me.com', 'mac.com', 'icloud.com', 'gmail.com', 'googlemail.com', 'hotmail.com', 'live.com', 'msn.com', 'outlook.com', 'yahoo.com', 'ymail.com', 'aol.com'];

Β 

  • This array contains the domains you want to block. Feel free to remove or add domains as per your requirements.

3. Event Listener:

emailInput.addEventListener('input', function() {...});
  • This code listens for user input in the email field and triggers a function each time the input changes.

4. Domain Check and UI Feedback:

const domain = emailInput.value.split('@')[1];
if (blockedDomains.includes(domain)) {
emailInput.style.border = '2px solid red';
submitButton.disabled = true;
submitButton.textContent = "Please Use Your Work Email";
} else {
emailInput.style.border = '';
submitButton.disabled = false;
submitButton.textContent = originalSubmitText;
}
  • Extracts the domain from the entered email and checks against the blocked list.
  • If it's on the list, it highlights the email input in red, disables the submit button, and changes the button text.
  • If not, it resets the UI elements to their original state.

πŸ›  How to Implement

  1. Navigate to Unbounce Dashboard > Your Landing Page > Script Manager.
  2. Click Add a Script > Choose Custom Script.
  3. Copy-paste the above script into the Script area.
  4. Ensure to target the specific pages you want the script to run on.
  5. Save and Publish your page.

That’s it! πŸŽ‰ Now, you've set up a barrier against free email domains on your Unbounce landing page. Feel free to tweak as needed, and do share if you enhance it further!
Β 

Happy converting, Unbouncers! πŸš€


2 replies

Userlevel 1
Badge

Man, you’re a lifesaver. Thank you so much for this!

This is excellent, and I can truly appreicate you’re never give up solution finding spirit!

Reply