Created
November 10, 2014 12:55
-
-
Save akent/dec1b4b7383436b4623e to your computer and use it in GitHub Desktop.
Android referrer code using invite:// intent with fallback to play store link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<div id='fallback-msg' class='hidden'> | |
<p>If you are not redirected shortly, you may not have the app installed.</p> | |
<p><a id='market-link' href="#">Install the app.</a></p> | |
</div> | |
<script type='text/javascript'> | |
var code = 'extract your code here'; | |
if (/Android/i.test(navigator.userAgent)) { | |
var custom = "your-scheme://" + code; | |
var g_intent = "intent://" + code + "/#Intent;scheme=yourscheme;package=com.your.app&referrer=code%3D" + code + ";launchFlags=268435456;end"; | |
var market_link = 'https://play.google.com/store/apps/details?id=com.your.app&referrer=code%3D' + code; | |
var timer; | |
var iframe_timer; | |
function tryIframeApproach() { | |
var iframe = document.createElement("iframe"); | |
iframe.style.border = "none"; | |
iframe.style.width = "1px"; | |
iframe.style.height = "1px"; | |
iframe.onload = function () { | |
document.getElementById('market-link').href = market_link; | |
document.getElementById('fallback-msg').className = 'visible'; | |
}; | |
iframe.src = custom; | |
document.body.appendChild(iframe); | |
} | |
function tryWebkitApproach() { | |
document.location = custom; | |
} | |
function useIntent() { | |
document.location = g_intent; | |
} | |
function launch() { | |
if (navigator.userAgent.match(/Chrome/)) { | |
useIntent(); | |
} else if (navigator.userAgent.match(/Firefox/)) { | |
tryWebkitApproach(); | |
iframe_timer = setTimeout(function () { | |
tryIframeApproach(); | |
}, 1500); | |
} else { | |
tryIframeApproach(); | |
} | |
timer = setTimeout(function () { | |
document.getElementById('market-link').href = market_link; | |
document.getElementById('fallback-msg').className = 'visible'; | |
}, 2500); | |
} | |
window.onload = function(){launch();}; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment