Skip to main content
Act-On Software

Using Form Customization Script to Convert URL Query Strings into Form Inputs

 

In some cases, relevant information is passed through the query string in a web address URL. If you would like to capture this in an Act-On form signup list so that you can track information on leads when they hit your page that contains this special URL, this is possible with the script below.
Note: These are advanced steps.
This customization is not necessary for the majority of Act-On users, but is provided here as a solution for those who can make use of it.
  1. Navigate to Content > Forms and click Edit on an existing form, or New Form.
  2. Copy the script below into any section of your Act-On form where valid JavaScript can run. 
    • For example, you may paste this into the External Web Analytics Text Area in your form's settings. Please see the article Using JavaScript in Email Messages, Forms, and Landing Pages for more information on other sections of the platform where scripts may be run. The following script needs to be placed in your form editor, rather than in the landing page editor.
  3. Create an input in your Act-On form. This can be a standard One Line Text input or a Hidden inputYou will most likely want to use a Hidden input, since you would not need your form submitters to see that you are storing this information in a form input.
  4. Next, you will be prompted to name your input. The Data Field Name in the input in the Act-On form needs to match the field name of the query string you are hoping to capture.
    • If your new visitors are coming in with the query string referrer=adNetworkName, for instance, your field name is referrer. 
    • In a query string, the field name is typically static and the field value is dynamic and contains the important information. For example, the value for field referrer= in your query string could be adNetworkA, adNetworkB, adNetworkC (which would look like http://examplecustomerdomain.com?referrer=adNetworkB)
    • In this example, your form's signup list will now have a field called referrer in the list. This field will have data automatically populated by the script and filled into your form (so the field value that is automatically populated into your list in this case would be adNetworkA, adNetworkB, adNetworkC).
  5. Script to copy:


<script>
var urlParams;
var query = (window.location != window.parent.location) ? document.referrer.split('?')[1] || '' : window.location.search.split('?')[1]|| '';
(window.onpopstate = function () {
var match, search = /([^&=]+)=?([^&]*)/g;
urlParams = {};
while (match = search.exec(query))
urlParams[encodeURIComponent(match[1])] = match[2];
}
)();
for (i in urlParams) {
var urlParamsArray = urlParams[i];
try {
document.getElementsByName(i)[0].value=decodeURIComponent(urlParamsArray);
}
catch(err) {
}
};
</script>

 

Notes:

  • This will read the query string from the URL for your Act-On form (if appended to your Act-On form's public URL) or it will read the URL from the parent page your form is located on if you are Iframing your Act-On form. See the article Embedding Forms on a Website for further information.
  • This works well with query strings that contain multiple field=value pairs
  • You will need to have a matching input for each query string field name you hope to capture. If there is a query string field name that does not have a matching Act-On form input, the script will skip it and it will not be saved.
  • If your form is embedded within an iframe but you do not want to read the URL from the parent page (instead you want to read a query-string from the iframed form's URL):
    • Replace the line above at the top of the screen where you see this:
var query = (window.location != window.parent.location) ? document.referrer.split('?')[1] || '' : window.location.search.split('?')[1]|| '';

With this line:

var query = window.location.search.split('?')[1]|| '';

Here is an example use-case where query string capturing would be useful:

  • You have purchased ads on a network with which Act-On is not directly integrated
  • The referral information to attribute where the link came from is expressed in a query string
  • For example, your link to examplecustomerdomain.com has ?referrer=adNetworkName 
    • Your complete URL is http://examplecustomerdomain.com?referrer=adNetworkName. This URL takes the clicker of the ad to http://examplecustomerdomain.com. The additional URL query string components of ?referrer=adNetworkName are for reporting only in your visitor referral data.
  • Checking how many hits come from these specific URLs with the query string allows you to evaluate the success of your ad campaign 
  • With this script, you will be able to easily see which form submissions contained this query string in a way that is easily searchable and 'query-able' since the query string values will be in separate columns

This script can also be adapted to work on non-Act-On web pages with external forms. See the article Posting External Forms to Act-On for further information.

 

  • Was this article helpful?
Support

Have a question about this topic?

Ask the community!