Created
August 7, 2012 22:05
-
-
Save ashfame/3289834 to your computer and use it in GitHub Desktop.
kissmetrics-property-device
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
(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