Skip to content

Instantly share code, notes, and snippets.

@andershaig
Last active December 18, 2015 05:29
Show Gist options
  • Save andershaig/5732604 to your computer and use it in GitHub Desktop.
Save andershaig/5732604 to your computer and use it in GitHub Desktop.
Redirect users with support for referral tracking
{% plugin rawtext fanpage_url %}
<script type="text/javascript">
if (!document.body.className.match('page_preview')) {
var redir;
if (window.location.search) {
// Triggered if there's already a social referrer being tracked
var ref_search = window.location.search;
var ref = ref_search.split('=');
var ref_id = ref[1];
redir = '{{ fanpage_url }}' + '&app_data' + encodeURIComponent('[social_referrer]=' + ref_id);
} else {
// Also supports URLs without social referrer
redir = '{{ fanpage_url }}';
}
// Redirects as soon as possible
setInterval( function () {
top.location.replace(redir);
},100);
}
</script>
{% plugin rawtext mobile_url %}
<script type="text/javascript">
if (!document.body.className.match('page_preview')) {
var redir;
if (window.location.search) {
// Triggered if there's already a social referrer being tracked
redir = '{{ mobile_url }}' + window.location.search;
} else {
// Also supports URLs without social referrer
redir = '{{ mobile_url }}';
}
// Redirects as soon as possible
setInterval( function () {
top.location.replace(redir);
},100);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment