Create a Tracking Redirect
When you use third-party pixel trackers or link generators, your visitors may pass through several domains, some of which you may not control. If a visitor is redirected and ends up on a different domain from the one they started on, the SegMetrics first-party pixel can lose track of them.
The redirect script below solves this by loading the SegMetrics pixel on your final domain before sending visitors on to the next step.
When to Use the Redirect Script
Simple rule: Only use this script when your visitor starts on one domain and ends on a completely different domain.
✅ USE the script when:
The main domain changes from start to finish.
- Start domain:
example-landingpage.com - End domain:
example.com(different main domain) - Full path:
example-landingpage.com > linktester.com > example.com
Why you need it: SegMetrics loses track of visitors when they end up on a different main domain from the one they started on.
❌ DON'T use the script when:
The main domain stays the same.
Example 1: Same domain from start to finish
- Start domain:
example.com - End domain:
example.com(same domain) - Full path:
example.com > linktester.com > example.com
Example 2: Different subdomains, same main domain
- Start domain:
lp.example.com - End domain:
example.com(same main domain) - Full path:
lp.example.com > linktester.com > example.com
Why you don't need it: SegMetrics automatically tracks visitors across a main domain and all of its subdomains.
Installing the Redirect Script
- Copy the redirect script code below and save it on your computer as
seg-redirect.html. - In the file, replace
YOUR_SEGMETRICS_PIXELwith your SegMetrics pixel. You can find your pixel on your Snippet settings page. -
Upload the HTML file to your final domain (the domain where visitors end up).
In the example above, you would upload the file so it is available at:
https://example.com/seg-redirect.html
- On your landing page, change the button or link so it points to the redirect URL from step 3. Then add the next destination to the end of that URL as a
?to=query string.
- In the example above, the button would link to:
https://example.com/seg-redirect.html?to=https://linktester.com
Redirect Script Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Redirecting</title>
YOUR_SEGMETRICS_PIXEL
<script>
// 2. If we have a URL, go to the page, otherwise go back
function getParameterByName(name, url = window.location.href) {
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results){ return null; }
if (!results[2]){ return ''; }
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
var url = getParameterByName('to');
if(url){
setTimeout(function(){
window.location = url;
}, 1000);
} else{
window.history.back();
}
</script>
<style>
#container{
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
</style>
</head>
<body>
<div id="container">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
style="margin:auto;display:block;" width="241px" height="241px" viewBox="0 0 100 100"
preserveAspectRatio="xMidYMid">
<circle cx="50" cy="50" r="0" fill="none" stroke="#788287" stroke-width="2">
<animate attributeName="r" repeatCount="indefinite" dur="1.7857142857142856s"
values="0;18" keyTimes="0;1" keySplines="0 0.2 0.8 1" calcMode="spline"
begin="-0.8928571428571428s"></animate>
<animate attributeName="opacity" repeatCount="indefinite" dur="1.7857142857142856s"
values="1;0" keyTimes="0;1" keySplines="0.2 0 0.8 1" calcMode="spline"
begin="-0.8928571428571428s"></animate>
</circle>
<circle cx="50" cy="50" r="0" fill="none" stroke="#838f91" stroke-width="2">
<animate attributeName="r" repeatCount="indefinite" dur="1.7857142857142856s"
values="0;18" keyTimes="0;1" keySplines="0 0.2 0.8 1" calcMode="spline"></animate>
<animate attributeName="opacity" repeatCount="indefinite" dur="1.7857142857142856s"
values="1;0" keyTimes="0;1" keySplines="0.2 0 0.8 1" calcMode="spline"></animate>
</circle>
</svg>
</div>
</body>
</html>
Frequently Asked Questions
Q: When do I need to use this tracking redirect script?
A: You only need this script when the final destination domain is different from the domain where users start. If users start and end on the same main domain (even on different subdomains), you don't need it.
Q: Where should I upload the redirect script file?
A: Upload the seg-redirect.html file to your final destination domain, which is the domain where you want users to end up after the redirect process.
Q: How do I customize the redirect URL?
A: Add the target URL to the end of your redirect script URL as a ?to= query parameter. For example: https://example.com/seg-redirect.html?to=https://linktester.com
Q: What happens if someone visits the redirect page without a target URL?
A: If no target URL is provided, the script automatically sends the visitor back to the previous page using window.history.back() .
Q: Can I customize the loading animation on the redirect page?
A: Yes. You can modify the SVG animation in the script or replace it with your own loading indicator. Keep in mind that the redirect happens after a 1-second delay to give the pixel time to capture the visit.