Search code examples
javascriptphpwebgoogle-analyticsformstack

How to add a dynamic value from one form to another page in javascript conversion coding?


Please see the page from this link https://genuineemailmarketing.formstack.com/forms/done this ordering from is generated by formstack.com. In the page there is a field named "Total" which is the total amount of ordering. When anyone submit the order they are redirect in a thank-you.php page. In that thank you page i have a javascript google Conversion coding. The coding is given below-

Google Code for Purchase-NEW Conversion Page:

var google_conversion_id = 1000063495;

var google_conversion_language = "en";

var google_conversion_format = "3";

var google_conversion_color = "ffffff";

var google_conversion_label = "EsxZCN3fmWt9mf3s4AM";

var google_conversion_value = 50.00;

var google_conversion_currency = "USD";

var google_remarketing_only = false;

Now in the 6th line "var google_conversion_value = 50.00;" here i need the dynamic value which will be replace in the place of 50.00 and the dynamic value will come from the formstack form's field named "total" which is the total amount of ordering. 50.00 will be dynamic variable.

If anyone know the process how can i do it please give me the solution. And if anyone need any other information or have any confusion about my problem, just ask. THank You


Solution

  • I'm assuming that you are redirecting your users to http://www.genuineemailmarketing.com/thank-you.php after they fill out the form.

    You will need to do the following:

    1. Log into Formstack, goto your form
    2. Under your Form Settings, select Emails & Redirect
    3. Goto the "After the Form is Submitted" section, and add/change the submit action so that the form is redirecting to http://www.genuineemailmarketing.com/thank-you.php
    4. Make Certain that the "Append Submitted Data to the URL" is checked! Note... unfortunately, the last 4 digits of the CC is passed over into the URL in the clear, along with the CSV code and expiration date, not really desirable.
    5. Add the following javascript code to your thank-you.php page (code obtained from How can I get query string values in JavaScript?)
    function getParameterByName(name, url) {
        if (!url) url = window.location.href;
        name = name.replace(/[\[\]]/g, "\\$&");
        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
            results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/\+/g, " "));
    }
    

    Then you can populate your variable google_conversion_value as followed:

    var google_conversion_value = getParameterByName('Total');
    

    I hope this helps!