Skip to main content

Prefill Logic Snippet for UGC Surveys (Auto-Fill Email from URL Parameter)

Allows you to automatically pre-fill the email field in your UGC Surveys.

Christoph Schleifer avatar
Written by Christoph Schleifer
Updated over 3 weeks ago

It works by reading the email parameter from the page URL and inserting it into the email input field.

This is useful if:

  • You want to send survey links by email and auto-fill the email address for the user.

  • You want to simplify form completion for supporters.

How It Works

When a visitor opens the survey page with a URL like this:

The snippet automatically:

  1. Detects the email parameter in the URL.

  2. Finds the email input field in the survey form.

  3. Inserts the email into that field.

  4. Triggers the necessary input events for the platform to recognize it.

The Code Snippet

Here is the complete JavaScript snippet:

<script>
(function() {
const params = new URLSearchParams(window.location.search);
const email = params.get("email");

if (email) {
const waitForInput = () => {
const emailInput = document.querySelector('input[type="email"]');
if (emailInput) {
emailInput.value = email;
emailInput.dispatchEvent(new Event('input', {
bubbles: true
}));
} else {
setTimeout(waitForInput, 300);
}
};

waitForInput();
}
})();
</script>

How to Use It

  1. Add this script to your survey’s page or landing page.

  2. Send out your survey link with the email parameter attached:

If you are sending the survey via a CamBuildr email campaign, you need to use the CamBuildr email placeholder so the system inserts each recipient’s email address automatically.

Here’s how:

https://your-page-url.com?email={{ person.email }}

{{ person.email }} will automatically be replaced with the recipient’s email address when the email is sent. Every supporter will then see their own email pre-filled in the survey.

Did this answer your question?