Skip to content

Instantly share code, notes, and snippets.

@ashfame ashfame/driver.js
Created Aug 7, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.