I have an email from email studio go to a group of contacts. The name of the data extension is called "SmartCapture". On the email, when a person clicks the submit button, he or she will then be taken to a cloud page.

I'm wanting to capture the person's email from the email after the button is clicked and then pre-populate the email address field with what was pulled from the button click.

So the process would look like this: Email received -> take survey button clicked on the email -> email address captured -> person lands on cloud page where they see their email already on the landing page.

So far I have the following built but it is not working. May I have help with where I am going wrong?

Below is stored on the email:

    Var @link
    Set @link = Concat('https://fe3715717564047b731274.pub.s11.sfmc-content.com/uujkvwp3qzv/emailaddr=', AttributeValue('emailaddr'))

<a href="%%=RedirectTo(@https://fe3715717564047b731274.pub.s11.sfmc-content.com/uujkvwp3qzv)=%%">CTA Button</a>

Stored on the cloud page:

var queryString = window.location.search;
var params = new URLSearchParams(queryString.substring(1)); // drops the leading "?"
var username = parseInt(params.get('emailaddr'));
  • Your link should look something like this <a href = "%%=RedirectTo(@link)=%%">CTA Button</a> Oct 29 '20 at 16:36
  • Thanks @SwatiMishra. The url is now showing the person's email, which is great. However, the script is not pulling the email into the email field. May I have your opinion on the below. Is there something I'm missing? var queryString = window.location.search; var params = new URLSearchParams(queryString.substring(1)); // drops the leading "?" var emailaddr = parseInt(params.get('emailaddr'));
    – Greg Noble
    Oct 29 '20 at 17:18

First of all, your setting a @link variable and then not using it. In the actual button, you should be redirecting to @link, not @http://... that’s why it seems that the button is working fine, but it’s actually not. This should fix it:

    Var @link
    Set @link = Concat('https://fe3715717564047b731274.pub.s11.sfmc-content.com/uujkvwp3qzv/emailaddr=', AttributeValue('emailaddr'))

<a href="%%=RedirectTo(@link)=%%">CTA Button</a>

Since you’re redirecting the subscriber to a Cloud Page, there’s an easier way to do this by uisng the CloudPagesURL function, which will pass a bunch of parameters automatically.

In the email, use:

<a href="%%=CloudPagesURL(123)=%%">CTA Button</a>

Replace 123 with the Id of the Cloud Page, which can be found in the Properties of the Cloud Page.

Now on the CloudPage you can do the following:

<script runat=server>
     var contactEmail = Platform.Variable.GetAttributeValue('EmailAddr');

Or you can use AMPscript which would be even more straight forward:

set @emailaddr = emailaddr

And display this as a form field value:

<input ... value="%%=v(@emailaddr)=%%”>

Documentation and links:

CloudPagesURL: https://ampscript.guide/cloudpagesurl/ SSJS GetAttributeValue: https://developer.salesforce.com/docs/atlas.en-us.mc-programmatic-content.meta/mc-programmatic-content/ssjs_platformFieldAttributeGetAttributeValue.htm Creating forms on CloudPages with AMPscript: https://sfmarketing.cloud/2019/09/22/create-a-sales-service-cloud-integrated-lead-capture-form-using-ampscript/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.