Keeping Thank You pages on the same CNAME as Marketo LPs

This was a nice catch by user AD on the Community and something I somehow missed before! It has significant effects on tracking and on branding in general.

When you set up Domain Aliases in Marketo (and corresponding CNAMEs in DNS) you can access your Marketo-hosted LPs via a choice of different URLs. The path/page name stays the same, but you can use a different domain.

For example, you can use go.example.com for the bulk of your pages, but publish some pages under get.mymicrositeexample.com for special products. The pages will actually be accessible under any of your Aliases as well as your Primary (i.e. if somebody manually changed the URL in their browser) but by taking care to link to the preferred domain from ads, social, and email, you can keep content/layout/logos/etc. totally different.

If you're an agency, you might even use Domain Aliases to service multiple clients at the same time, the only restriction being you can't use the exact same /pagename but would have to mix it up like /jiffylube_coupons_2017 and /spiffylube_coupons_2017.

Cool concept, so... ?

Problem is, “siloing” Domain Aliases from each other falls apart if you select a Thank You page from the dropdown of Marketo LPs.

What'll happen is Marketo will take the lead to that LP under the Primary Domain, not the current Domain Alias on which the form resides!

Observe the form fillout on a Domain Alias:

But the Thank You automatically loading from the main domain:

This leads to wacky tracking because the lead will be anonymous on the Primary Domain they're now looking at! Yep, the form fillout will associate the lead on the Domain Alias (which is cool, when they finally get back to www.mymicrositeexample.com) but when they click a link on the Thank You page, that won't be tracked to their known lead in Marketo. So you'd have a strange black hole.

And of course it's also bad for branding, since the idea behind Domain Aliases is to keep the URLs separate. You may have competing clients, and you don't want everyone going to the same Thank You URL.*

I missed this problem before because I'm so used to managing Thank You URLs programmatically (using Forms API JS onSuccess). Didn't see how weird the behavior can be when you use the no-code approach.

Solving it

It takes just a tiny bit of Forms API JS**:

MktoForms2.whenReady(function(form){
	form.onSuccess(function(vals,tyURL){
		var tyLoc = document.createElement('a');
        tyLoc.href = tyURL;
		tyLoc.protocol = document.location.protocol;
		tyLoc.hostname = document.location.hostname;
		document.location = tyLoc;
		return false;
	});
});

Then the lead will go to the intended Thank You page (still set via the UI) but will stay on the current Domain Alias:


Notes

* You could check the Referrer on the Thank You page and you'd know where they came from. Then redirect them again or use the Referrer directly to choose the brand. But that's far from straightforward.

** Do be mindful of your Forms API event listeners, i.e. if you have a lot of behaviors they should be consolidated under one (or maybe 2 or 3, no more) whenReady functions. If this is your only special behavior you don't need to worry about it.