Skip to content

Instantly share code, notes, and snippets.

@ashfame
Created August 7, 2012 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashfame/3289834 to your computer and use it in GitHub Desktop.
Save ashfame/3289834 to your computer and use it in GitHub Desktop.
kissmetrics-property-device
(function(){
var isFirstVisit = false;
if ( document.referrer == '' ) {
isFirstVisit = true;
} else {
// If referrer is not the site itself
if ( ! ( document.referrer.match( window.location.host ) ) )
isFirstVisit = true;
}
if ( isFirstVisit ) {
// If visit is from a mobile device
if ( (/iPhone|iPod|BlackBerry/).test(navigator.userAgent) || ( (/Android/).test(navigator.userAgent ) ) && (/Mobile|mobile/).test(navigator.userAgent ) )
_kmq.push(['set', {'Device':'Mobile'}]);
// If visit is from a tablet device
if ( (/iPad/).test(navigator.userAgent) || ( (/Android/).test(navigator.userAgent ) ) && ! (/Mobile|mobile/).test(navigator.userAgent ) )
_kmq.push(['set', {'Device':'Tablet'}]);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment