Create A Tracking Redirect

⌘K
  1. Home
  2. Docs
  3. Create A Tracking Redirect

Create A Tracking Redirect

Create a Tracking Redirect

When using 3rd party pixel trackers or link generators, you may need to send users through multiple domains that may or may not be under your control. This can cause the SegMetrics first-party pixel to lose track of a user if they’re redirected and end up on a domain that is different than the original domain.

The script below can be used to allow SegMetrics to track users through every step of the process.

In this article

  • When to Use the Redirect Script
  • Installing The Redirect Script
  • Redirect Script Code
  • Frequently Asked Questions

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 when the visitor ends up on a different main domain than where they started.

❌ DON’T use the script when:

The main domain stays the same

Example 1: Same domain, same subdomain

  • 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 can track visitors across the same main domain and its subdomains automatically.

Installing The Redirect Script

  1. Copy the Redirect Script below, and save it to your computer as seg-redirect.html
  2. In the file, replace YOUR_SEGMETRICS_PIXEL with your SegMetrics Pixel (https://app.segmetrics.io/a/settings/snippet).
  3. Upload the html file to your FINAL domain.In the example above, we would upload the file to it to https://example.com/seg-redirect.html
  4. From your landing page, change the button or link to point to the redirection URL (in step 3), and add the redirection target to the end of the URL as a ?to= query string.In the example above, we would link to to https://example.com/seg-redirect.html?to=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 to use this script when the final destination domain is different from the original domain where users start. If users start and end on the same domain (even with different subdomains), you don’t need this script.

Q: Where should I upload the redirect script file?

A: Upload the seg-redirect.html file to your FINAL destination domain – the domain where you want users to end up after going through the redirect process.

Q: How do I customize the redirect URL?

A: Add the target URL as a query parameter using ?to= at the end of your redirect script URL. For example: https://example.com/seg-redirect.html?to=linktester.com

Q: What happens if someone visits the redirect page without a target URL?

A: The script will automatically send them back to the previous page using window.history.back() if no target URL is provided.

Q: Can I customize the loading animation on the redirect page?

A: Yes, you can modify the SVG animation code in the script or replace it with your own loading indicator. The redirect happens after a 1-second delay to ensure tracking is captured.

How can we help?