Creating, Using, and Managing Redirect Codes

Redirect Codes are a unique feature that allows you to attach any piece of Javascript to your Terminus.app short URLs. When a user clicks your link, your script fires during the brief redirect, sending data to your analytics or advertising platforms.

Additionally, you can capture UTM and other data from your URLs and pass them into your JavaScript. This enables you to:

  • Create customizable retargeting and remarketing campaigns that deliver tailored ads to people based on the exact campaigns they’ve interacted with.
  • Track PDF downloads in Google Analytics or any other analytics service.
  • Send real-time click events from your short URLs to any analytics service.
  • Track clicks to third-party websites where you can't place your own tracking codes.

1. How to Create a Redirect Code?

  1. In your project, navigate to Tools > Redirect Codes.
  2. Click Create a New Redirect Code.

  1. Fill in the details:
    • Name: Give your code a descriptive name. This is what you'll see in the URL builder dropdown (e.g., Facebook Retargeting Pixel).
    • Javascript: Paste your full Javascript code, ensuring it is wrapped in <script> and </script> tags.
    • (Optional) Always apply: Check this box to make this code a default that is automatically added to every new short URL created in the project.

When writing your Javascript code, you'll be able to use Terminus dynamic tags that can be inserted in your code. Here's an example of what that looks like:

Example dynamic codes. Some of these will be different based on your own configuration

The real power of this feature comes from dynamic tags. You can pull data directly from your tracked link (like UTM parameters) and inject it into your script. This allows you to send precise, campaign-specific data to your other tools.

2. How to Use Redirect Codes?

  1. When building or editing a URL, go to the Redirect Codes section.
  2. Select one or more codes from the dropdown menu. You can attach multiple codes to a single link (e.g., a Facebook pixel and a Google Analytics event).
  3. Click Save. Now, when someone clicks your short URL, these scripts will fire.

NOTE: The redirect codes are only available when using Terminus shortener. They cannot be used when using third-party shorteners like Bitly.

Code Examples

To give you some ideas on how to use the redirect code feature, here are some examples.

Note: These examples are not guaranteed to work since the underlying services like Facebook, Google, etc. can change their interfaces.

1. Facebook Retargeting Pixel

This script adds users to a Facebook retargeting list and uses a dynamic tag to tell Facebook which campaign they belong to, enabling highly specific ad targeting.

<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');

fbq('init', 12345');

var fbTrack = function() { 
fbq('track', "ShortUrlRedirect", {campaign: _tu.utm.campaign.tag})
}
setTimeout(fbTrack, 1000);

</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=12345&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->

2. Track PDF Downloads in Google Analytics

This script treats a click on a short URL (e.g., one pointing to a PDF) as a "virtual pageview" in Google Analytics, complete with all the associated UTM campaign data.

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-12345678-1', 'auto'); // Replace with your GA Property ID

ga('set', 'campaignName', _tu.utm.campaign.tag);
ga('set', 'campaignMedium', _tu.utm.medium.tag);
ga('set', 'campaignSource', _tu.utm.source.tag);
ga('set', 'campaignContent', _tu.utm.content.tag);
ga('set', 'campaignKeyword', _tu.utm.term.tag);
ga('set', 'page', _tu.url);
ga('set', 'title', 'File Download');
ga('send', 'event', 'Download', 'File download', _tu.url);
ga('send', 'pageview', {'sessionControl': 'start'});
</script>

3. Send Short URL Clicks to Google Analytics

This script sends a simple event to Google Analytics every time a short URL is clicked, allowing you to track this activity alongside your website data.

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-12345678-1', 'auto'); // Replace with your GA Property ID
ga('send', 'event', 'Short Url', 'Visit', _tu.utm.campaign.tag);
</script>

3. Managing Your Redirect Codes

You can edit or delete your codes at any time from the main Redirect Codes screen.

  1. Navigate to Tools > Redirect Codes.
  2. Find the code you wish to manage in the list.

  • To Edit a code, click the pencil icon, make your changes, and click Save.
  • To Delete a code, click the trash can icon and confirm the action.

Warning: Deleting a Redirect Code is permanent. It will no longer fire for any existing short URLs that used it.

Best Practices

  • Use 'Always Apply' for Global Tracking: If you have a primary analytics script that needs to fire on every single link, use the Always apply option to ensure it's never forgotten.
  • Test Your Scripts: Before applying a code to an important campaign, create a test link and click it. Then, check your ad platform or analytics tool to verify that the data was received correctly.
  • Combine Codes for Power: Remember you can attach multiple codes to a single URL (e.g., a Facebook Pixel and a GA event) to send data to multiple platforms from one click.

Still need help? Contact Us Contact Us