Redirect Page based on Referrer

November 18, 2014 | by

Let’s say you would like to prevent direct traffic to a Marketo landing page. Imagine this page has downloadable content like a PDF that you would like a user to first fill out a form before receiving. You could solve this by checking if the user came from a certain page. In this case, it would be the page where the user has to fill out a form. If the user is not coming from that page, you can then redirect the user to the form fill out page.

To accomplish this, you will have to check if the referrer page to the landing page with content is the form fillout page.

Step One: Replace both instances of “http://example.com/PageWithForm” in the snippet below with a link to the page you want to the user to come from. This could be the form fill out page.

Step Two: Include the customized JavaScript snippet before the closing tag on your Marketo landing page with content.

If the user is not sent to the landing page with content from the form fill out page, the user will now be redirected to the form fill out page.