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.
1 2 3 4 5 6 7 |
<script> window.onload = function() { if (document.referrer !== "http://example.com/PageWithForm") { document.location.href = "http://example.com/PageWithForm"; }; }; </script> |
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.