Of course, you are correct.
I've come to realize that not only is it harder, but the whole idea of it goes away if I want to do it with a tokenized thank you page. I'd either need to update where the form goes for each program or create another abomination.
So it's going to your initial suggestion with controlling what happens on success of the submission. Upon form submission we'll need to take the user directly to the download (let's say it's a .pdf) without going through a thank you page to save them 1 more click. Can you help with this?
You can do it like this:
<script src="https://pages.example.com/rs/aaa-bbb-ccc/form-thank-you-urls.js"></script>
<script>
MktoForms2.whenReady(function(mktoForm){
mktoForm.onSuccess(function(values,originalThankYouURL){
const originalThankYouLoc = document.createElement("a"),
finalThankYouLoc = document.createElement("a");
originalThankYouLoc.href = finalThankYouLoc.href = originalThankYouURL;
if (window.thankYouURLMap) {
window.thankYouURLMap.some(function(rule){
if(document.location.href.indexOf(rule.formBaseURL) == 0) {
finalThankYouLoc.href = rule.thankYouURL;
finalThankYouLoc.search += finalThankYouLoc.search ? "&" : "";
finalThankYouLoc.search += originalThankYouLoc.search;
return true;
}
});
}
document.location = finalThankYouLoc;
return false;
});
});
</script>
Where the file https://pages.example.com/rs/aaa-bbb-ccc/form-thank-you-urls.js is a file uploaded to your Design Studio with a set of rules like this:
window.thankYouURLMap = [
{
"formBaseURL" : "https://www.example.com/path/to/landingpage1.html",
"thankYouURL" : "https://www.example.com/document1.pdf"
},
{
"formBaseURL" : "https://www.example.com/path/to/landingpage2.html",
"thankYouURL" : "https://www.example.com/document2.pdf"
}
];
Include the scripts after the embed code.
Note the code does a simple prefix match between the rules and the current URL. In other words, if the current URL is https://www.example.com/path/to/landingpage2.html?utm_medium=whatever&someothervalue=whateverelse then it matches the second rule. In my own work I would support more robust pattern matching.