1

We have a snippet of code that was provided by an optimization platform company we use that provides a real-time personalization to our website.

The user will fill out a form (Gravity Forms) and then be sent to one of our WordPress Thank You pages.

This code will be added to the Thank You page, but needs to be updated to capture the user's email address once the Gravity Form has been completed:

<img src="//dasd65f4ds3e25u.cloudfront.net/pc/p5w6g1jy/?e=[customer's email address]" id="__tms_pc" height="1" width="1" />

Would you be able to help me replace the "customer's email address" text with the appropriate code that will be able to capture each user's email address when they fill out the form?

Is there a PHP string of code that could be used to replace the "customer's email address" text? I have not been able to find a concrete answer while doing some research for this.


Edit append: We need to add the tracking script and form submission image to the thank you page. To do this we added the tracking script in Google Tag Manager.

The next step is to add the tracking image to the confirmation/thank you page. This is the script I put in my original question. This script is a purchase complete tracking script for the form confirmation/thank you page after the form has been filled out. This is to record when a user completes the form and remove the user form abandoned campaigns.

The instructions mention replacing the placeholder text [customer's email address] with the code to merge the user's actual email address in the URL. This code can not be added to Google Tag Manager, so we will need to modify the page's HTML. We use WordPress and I am thinking this mentioned code can be added to the confirmation/thank you page.

I reached out to Gravity Forms about this question, and here is their response: "You can configure your form confirmation to redirect to your thank you page and include the email provided using a query string, example: https://d.pr/i/0jljog

That would pass the actual value for the email provided by the user to your thank you page. But the snippet that the optimization platform company provided you is intended to just display an image with a query string, that's the only thing it can do.

Therefore even if you configure your form to pass the value to the page as explained above, you still need to put some code in the page to get the value form the query string and pass it to the snippet. So you will need to ask the optimization platform company about this."

2
  • 1
    Does the Thank You page have any way to access the Gravity Forms entry that gets created, like an entry ID passed in a GET variable? If so, you should be able to get the entry data using GFAPI::get_entry() and pull the email address from that. – Pat J Dec 22 '20 at 19:47
  • 2
    You could try to configure the redirect to append the email to the URL it is sent to - but in either case - you would need to use the GF API to get the field data from the entry. If the thank you page is the one generated by the form, this will be considerably easier. – Q Studio Dec 22 '20 at 20:52
0

Everything that comes after the "?" in the URL is what's known as a "query string." To use PHP to get the results of a query string, you use $_GET to "get" the value of the variable.

You have two parts, the variable and the value. In the example you gave, "e" is the variable, and what comes after "=" is the value. Like this:

?e=email@example.com

To get that result with PHP, use $_GET like this:

$email = $_GET['e'];

Now, the value contained in the $email variable of your PHP code will contain the value of "e" in the query string.

Be sure to use best practices when getting variables from query strings because they can leave you vulnerable. So make sure that the value is set (using isset()) and sanitize it before using it:

$email = ( isset( $_GET['e'] ) ) ? sanitize_email( $_GET['e'] ) : false;

if ( $email ) {
     // There is an email a value in the "e" query string parameter.
     // You can do whatever you need to do with the email from here.
} else {
     // "e" was empty or did not exist.
}
5
  • Would this code be placed in the functions.php file? $email = ( isset( $_GET['e'] ) ) ? sanitize_email( $_GET['e'] ) : false; if ( $email ) { // There is an email a value in the "e" query string parameter. // You can do whatever you need to do with the email from here. } else { // "e" was empty or did not exist. } – Webman Dec 23 '20 at 20:39
  • Yes, or somewhere in your WP instance that you store custom code - such as a site specific plugin file. (Also, in the comments, just ask the question - don't repeat the code - it's unnecessary and just clutters things up.) – butlerblog Dec 23 '20 at 22:36
  • Trying not to use too much code to reduce comment clutter. I want to make sure I fully understand how the code will look, $email = $_GET['e']; will be place in the [ ] brackets like this? ?e=[$email = $_GET['e'];] – Webman Dec 30 '20 at 20:30
  • Seems like I might have misread your question. You're trying to get the email so you can build query string? I had read it that you were trying to get the value that was in the query string. I'll revise the answer. – butlerblog Jan 1 at 17:34
  • My apologies if I have not been descriptive with this. I honestly have no idea how to get this accomplished. My employer assigned this task to me and I am trying to get everything straightened out. I don't have enough characters in this comment section and will append to my original question. – Webman Jan 3 at 0:16

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.