Closed michaelglass closed 11 years ago
It could only do some of these within the current scope of the gem. Without session or cookie support it can communicate what's in the http request headers. However track
is often called not in an HTTP request and we wouldn't want to include this stuff then.
I'd think about exploring an api that makes it easy to add this data if you have/want it. In the meantime you can do stuff like this;
client.track 'cool event' { '$referrer' => ENV['HTTP_REFERER'] }
Referrer is possible. Search engine as it's based upon the referrer is also possible but looking at the code from the js lib, I'm not sure we'd want to maintain a ruby copy.
searchEngine: function(referrer) {
if (referrer.search('https?://(.*)google.([^/?]*)') === 0) {
return 'google';
} else if (referrer.search('https?://(.*)bing.com') === 0) {
return 'bing';
} else if (referrer.search('https?://(.*)yahoo.com') === 0) {
return 'yahoo';
} else if (referrer.search('https?://(.*)duckduckgo.com') === 0) {
return 'duckduckgo';
} else {
return null;
}
Device is based upon user agent, also I'm not sure we'd want to maintain a copy of this. (also this code explains why most of the time this field isn't helpful).
device: function() {
var a = userAgent;
if (/iPhone/.test(a)) {
return 'iPhone';
} else if (/iPad/.test(a)) {
return 'iPad';
} else if (/iPod/.test(a)) {
return 'iPod Touch';
} else if (/(BlackBerry|PlayBook|BB10)/i.test(a)) {
return 'BlackBerry';
} else if (/Windows Phone/i.test(a)) {
return 'Windows Phone';
} else if (/Android/.test(a)) {
return 'Android';
} else {
return '';
}
},
Browser is also another nest of maintenance.
browser: function() {
var ua = userAgent
, vend = navigator.vendor || ''; // vendor is undefined for at least IE9
if (window.opera) {
if (_.includes(ua, "Mini")) {
return "Opera Mini";
}
return "Opera";
} else if (/(BlackBerry|PlayBook|BB10)/i.test(ua)) {
return 'BlackBerry';
} else if (_.includes(ua, "Chrome")) {
return "Chrome";
} else if (_.includes(vend, "Apple")) {
if (_.includes(ua, "Mobile")) {
return "Mobile Safari";
}
return "Safari";
} else if (_.includes(ua, "Android")) {
return "Android Mobile";
} else if (_.includes(ua, "Konqueror")) {
return "Konqueror";
} else if (_.includes(ua, "Firefox")) {
return "Firefox";
} else if (_.includes(ua, "MSIE")) {
return "Internet Explorer";
} else if (_.includes(ua, "Gecko")) {
return "Mozilla";
} else {
return "";
}
},
You can explore more of the JS here http://cdn.mxpnl.com/libs/mixpanel-2.2.js
currently the gem doesn't track these special params but totally could. Someone wanna fix this?
"$os": "Mac OS X", "$browser": "Chrome", "$referrer": "https://www.google.com/", "$referring_domain": "www.google.com", "$initial_referrer": "https://www.google.com/", "$initial_referring_domain": "www.google.com", "$search_engine": "google"