Redirect to Thank You page and append query variables to the URL | Community
Skip to main content
mounica_tunugun
Level 2
November 13, 2019
Question

Redirect to Thank You page and append query variables to the URL

  • November 13, 2019
  • 1 reply
  • 7167 views

Hi There,

I have 2 assets and i'm using same form for both assets after submit i'm redirecting them to same thank you page. So i'm getting difficulty in analyzing the traffic from which asset most number of forms submitting. So for this i'm thinking to add asset name in the thank you page URL as a query string. So For suppose consider A & B are asset page if I submit form from A URL should be websitename.com/thankyou/a like this is it possible OR any other way? 

1 reply

SanfordWhiteman
Level 10
November 13, 2019

A URL should be websitename.com/thankyou/a

To be clear, this URL does not have a query string. You probably mean

   example.com/thankyou?a

(please don't use real private domain names in examples, you should use the officially standardized domain example.com)

You can append the asset page to the Thank You URL with this JavaScript;:

MktoForms2.whenReady(function(form) {
form.onSuccess(function(vals, tyURL) {
var tyLoc = document.createElement("a");

tyLoc.href = tyURL;
tyLoc.search += "&fromURL=" + encodeURIComponent(document.location.href);
document.location = tyLoc;

return false;
});
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This will attach the source page's URL to the Thank You URL as the query param fromURL.

mounica_tunugun
Level 2
November 13, 2019

Thanks for the reply.

Do i need to change any parameter values like thank you page URL or any other values
or directly copy paste code will work?

mounica_tunugun
Level 2
November 13, 2019

It's working fine. But i want to display category name (asset name) instead of from url is it possible.