Skip to main content

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 = c'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('@')l1];
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 = t'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('@')p1];
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! ๐Ÿš€

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!


This works, but if people disable javascript they still blow right past it unfortunately.


Trying to get this to work and want to make sure I have it correctly integrated. I switched out the field IDs to match the ones in Unbounce and then inputed this into the Head of the main landing page. For some reason, it is still not working properly. Any insight would be awesome!ย 

ย 


Hey @DougY,ย 

What does the browserโ€™s console throws up as an error?ย 

Probably the script loads before the actual form/page has finished loading.ย 

It would be easier to troubleshoot this for you if you have a test page you can share.ย ย 


Reply