Basic redirection scripts and approaches
You sometimes need to redirect a visitor without a button that points straight at an action URL.
These are redirection approaches for action links, and the cases they fit.
PHP redirection
Section titled “PHP redirection”A PHP file with a Location header is the most direct way to send a visitor from one URL to another.
- Point links at a file such as
redirect.php. You can change that file later without changing the links that already point at it. - You can script inside the file, including reading and changing the query string, and use that to choose the destination.
- The redirect is server-side. The browser does not have to run anything. It is sent to the next URL.
- You can send the visitor to an internal URL first, and have that URL redirect externally.
For example, send them to
mydomain.com/out/and put anindex.phpin that folder that redirects to a FunnelFlux action link. In most cases the referrer and cookies pass through, so the redirect works. It may not work with Fluxify (reverse proxy) when you use Fluxify Advanced Settings.
This PHP file sends the visitor to an action link:
<?phpheader("Location: https://mydomain.com/?flux_action=1");?>Create a text file, paste that code in, and rename the file so it ends in .php.
Use a code editor with syntax highlighting, such as Visual Studio Code or Sublime Text, so a missing semicolon is obvious.
To rotate equally between several links:
<?php$redirect[0] = 'https://url-1.com';$redirect[1] = 'https://url-2.com';$redirect[2] = 'https://url-3.com';
$number = mt_rand(0, 2);
header("Location: $redirect[$number]");?>To redirect to a URL and pass the current query string through, which is what you want when the previous page puts those parameters on the link:
<?phpheader("Location: https://mydomain.com/?" . $_SERVER['QUERY_STRING']);?>Masking action links with an internal PHP URL
Section titled “Masking action links with an internal PHP URL”Sometimes the lander should not use an action link directly.
You do not want the button to point at some-domain.com/?flux_action=1.
You want an internal page such as my-lander-domain.com/out/.
In some cases the button should have no href at all.
PHP and JavaScript both do that. Each method has tradeoffs.
Why use an internal PHP URL
Section titled “Why use an internal PHP URL”An internal URL stays stable, so you can change what it redirects to later without editing the lander. That still helps if the lander was built before you had a tracker, or if you change tracker, and you need to point the lander at a tracking link without editing the lander itself. Some automated reviewers, including Google and Facebook bots, treat a large number of external links as a signal. You may also need server-side work the tracker does not do, such as logging request data in PHP. FunnelFlux PHP nodes can cover some of that.
Example setup
Section titled “Example setup”- The lander is at
https://mydomain.com/lander.html. - The lander can use the FunnelFlux Universal tracking script, or you can send traffic to it with a tracking link. Either works.
- The tracking domain is
https://trackerdomain.com. - On the lander, avoid links like
https://trackerdomain.com/?flux_action=1. Use a relative link such as/out/or/go/. Those resolve tohttps://mydomain.com/out/andhttps://mydomain.com/go/.
How to set it up
Section titled “How to set it up”-
Change the action links to a relative path, for example
<a href="/out/">My Link</a>.Relative links are sensitive to the page URL.
mydomain.com,mydomain.com/, andmydomain.com/index.htmldo not all resolveout,/out, and/out/the same way. Test the links you create, and use one form consistently. -
If the relative path is unclear, use an absolute link to the internal page, such as
https://mydomain.com/out/. -
On the server, create an
/outfolder and anindex.phpinside it. You can put/outnext to one lander’s files, so only that lander uses it. Or put/outin the web root, so every lander can use it. The web-root folder is the one to use when every lander shares the same tracking domain and action URLs. -
In
index.php, send aLocationheader to the FunnelFlux action link:
<?phpif (isset($_GET['a'])) { $action = $_GET['a'];} else { $action = "1";}
header("Location: https://trackerdomain.com/?flux_action=" . $action . "&" . $_SERVER['QUERY_STRING']);?>Change trackerdomain.com to your tracking domain.
Set up a test funnel, send traffic to a lander that uses these /out/ links, and confirm the redirect before you rely on it.
Changing the action and passing data
Section titled “Changing the action and passing data”The script does not always send people to one static link. It can change the action number and pass the query string through.
- Add
?a=Xto the out link to choose the action./out/?a=3redirects toflux_action=3. - Any query string on the
/outlink is appended to the FunnelFlux action link./out/?a=2&b=3&c=4redirects tohttps://trackerdomain.com/?flux_action=2&a=2&b=3&c=4.a=2is repeated because the script used it to pick the action and then appended the original query string. FunnelFlux ignores parameters the current traffic source does not expect. - Parameters added to a FunnelFlux link go into the accumulated URL parameter buffer. Later lander and offer nodes receive them if you turn on Pass accumulated URL parameters in the node’s Advanced Settings.
- Because of that,
a=2can be passed on to later landers, so you can see which action sent the visitor there.
Caveats
Section titled “Caveats”- A lander to PHP script to action link path is not guaranteed to work in every configuration.
- The domain in the tracking link, or in the on-page JavaScript, must match the domain in the outgoing action link. Cookies depend on that.
- Do not go from HTTPS to HTTP. If the tracking link or the on-page JavaScript is HTTPS, the PHP script (when you use an absolute link) and the action link inside it should be HTTPS too.
- This approach may not work if the lander uses Fluxify (reverse proxy).
JavaScript click redirection
Section titled “JavaScript click redirection”JavaScript can redirect a page, including on a timer. It can also handle outgoing clicks.
- You can fire other JavaScript events before the redirect. One use is a Facebook JavaScript event on click-through. A JavaScript node in FunnelFlux can do the same job. Doing it on the page is faster, and it is more work to set up.
- Client-side script can control the outgoing links, so the page files can live on a CDN and you do not need PHP on that server.
- The call-to-action markup does not have to contain an external tracker URL, if you do not want those URLs in the page source.
This takes more setup than a PHP redirect, and it can do more. You can fire events for Facebook, Google Analytics, and similar tools before the redirect. If the visitor is blocking JavaScript, this does not run.
Tradeoffs
Section titled “Tradeoffs”- The redirect goes straight to the action link, so there is one less hop for cookies and referrers. It is faster than the PHP method when the visitor’s connection to your server is slow, because it skips that extra redirect and the second PHP file.
- The links and the handlers live in one file.
- The external action URLs are still in the page script. If you are masking links so a reviewer does not see external URLs, this does not help.
- Bots that do not run JavaScript will not follow these links. That can matter for SEO.
- You cannot do server-side work here the way an intermediate PHP script can.
Basic redirection with JavaScript
Section titled “Basic redirection with JavaScript”This listener redirects when the visitor clicks a button. It is plain JavaScript and needs no library.
Give the button a class of CTA1.
Leave out href, or use a <button>, so the element itself goes nowhere:
<a class="CTA1" role="button">Action Link 1</a>Put this before </body>:
<script>document.querySelectorAll('.CTA1').forEach(function (el) { el.addEventListener('click', function () { window.location.href = 'https://mydomain.com/?flux_action=1'; });});</script>A full page:
<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>
<a class="CTA1" role="button">Action Link 1</a>
<script>document.querySelectorAll('.CTA1').forEach(function (el) { el.addEventListener('click', function () { window.location.href = 'https://mydomain.com/?flux_action=1'; });});</script>
</body></html>Several buttons
Section titled “Several buttons”Use classes CTA1, CTA2, and so on.
Map each class to its action number:
<script>var actions = { CTA1: 1, CTA2: 2, CTA3: 3 };
Object.keys(actions).forEach(function (cls) { document.querySelectorAll('.' + cls).forEach(function (el) { el.addEventListener('click', function () { window.location.href = 'https://mydomain.com/?flux_action=' + actions[cls]; }); });});</script>Other JavaScript events, including Facebook
Section titled “Other JavaScript events, including Facebook”To fire a Facebook event as well, call it inside the click handler, then redirect after a short delay.
500 ms is enough.
The Facebook base pixel code must already be on the page, or fbq() is not defined.
This fires AddToCart and then redirects:
<script>document.querySelectorAll('.CTA1').forEach(function (el) { el.addEventListener('click', function () { fbq('track', 'AddToCart'); setTimeout(function () { window.location.href = 'https://mydomain.com/?flux_action=1'; }, 500); });});</script>You can put other JavaScript events in that handler. Check the syntax, and test it live before you rely on it.
For different buttons, add the class and its action number as in the previous example.
See how to fire FB pixel events when visitors click through on your landers.
Passing query-string values into the action link
Section titled “Passing query-string values into the action link”This page reads dog, cat, and bird from the current URL and appends them to the action links.
Each button sends a different set of values.
<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>
<a class="CTA1" role="button">Action Link 1</a><a class="CTA2" role="button">Action Link 2</a><a class="CTA3" role="button">Action Link 3</a>
<script>var params = new URLSearchParams(window.location.search);
function go(action, names) { var out = new URLSearchParams({ flux_action: action }); names.forEach(function (name) { out.set(name, params.get(name) || ''); }); window.location.href = 'https://mydomain.com/?' + out.toString();}
document.querySelector('.CTA1').addEventListener('click', function () { go(1, ['dog']); });document.querySelector('.CTA2').addEventListener('click', function () { go(2, ['dog', 'cat']); });document.querySelector('.CTA3').addEventListener('click', function () { go(3, ['dog', 'cat', 'bird']); });</script>
</body></html>Meta refresh
Section titled “Meta refresh”A meta refresh sits in the <head>.
It is a basic HTML bounce to another URL, for when you cannot use PHP, the tracker, or a faster redirect.
<html><head><meta http-equiv="refresh" content="0; url=https://somedomain.com"></head><body><p>Redirecting…</p></body></html>This version uses a meta refresh when JavaScript is disabled, and JavaScript otherwise. Both delays are 1.5 seconds.
<html><head>
<noscript><meta http-equiv="refresh" content="1.5; url=https://somedomain.com"></noscript>
<script>var targetURL = 'https://somedomain.com';window.addEventListener('load', function () { setTimeout(function () { window.location.href = targetURL; }, 1500);});</script>
</head>
<body>
</body></html>Put JavaScript in the <body> if you need it to run, then let the page redirect.
A JavaScript node in FunnelFlux does the same thing: your code runs on an HTML page, and you can set a delay before the redirect. A JavaScript node does not require you to upload a page.

