Skip to content

Instantly share code, notes, and snippets.

@akent
Created November 10, 2014 12:55
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akent/dec1b4b7383436b4623e to your computer and use it in GitHub Desktop.
Save akent/dec1b4b7383436b4623e to your computer and use it in GitHub Desktop.
Android referrer code using invite:// intent with fallback to play store link
<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