feat(analytics): Mixpanel implementation WIP

This commit is contained in:
Sabe Jones
2015-05-27 12:44:38 -05:00
parent 39cb9bfb99
commit 726a8f1acb
15 changed files with 84 additions and 8 deletions

View File

@@ -46,6 +46,16 @@ angular.module('habitrpg')
if($rootScope.selectedLanguage) url = url + '?lang=' + $rootScope.selectedLanguage.code;
$http.post(url, scope.registerVals).success(function(data, status, headers, config) {
runAuth(data.id, data.apiToken);
if (status == 200) {
mixpanel.alias(data._id);
if (data.auth.facebook) {
mixpanel.register({'authType':'facebook','email':data.auth.facebook._json.email})
} else {
mixpanel.register({'authType':'email','email':data.auth.local.email})
}
mixpanel.register({'UUID':data._id,'language':data.preferences.language});
mixpanel.track('Registration');
}
}).error(errorAlert);
};
@@ -57,6 +67,11 @@ angular.module('habitrpg')
$http.post(ApiUrl.get() + "/api/v2/user/auth/local", data)
.success(function(data, status, headers, config) {
runAuth(data.id, data.token);
if (status == 200) {
mixpanel.identify(data.id);
mixpanel.register({'UUID':data._id});
mixpanel.track('Login');
}
}).error(errorAlert);
};
@@ -121,13 +136,18 @@ angular.module('habitrpg')
// ------ Social ----------
hello.init({
facebook : window.env.FACEBOOK_KEY,
facebook : window.env.FACEBOOK_KEY
});
$scope.socialLogin = function(network){
hello(network).login({scope:'email'}).then(function(auth){
$http.post(ApiUrl.get() + "/api/v2/user/auth/social", auth)
.success(function(data, status, headers, config) {
if (status == 200) {
mixpanel.identify(data.id);
mixpanel.register({'UUID':data._id});
mixpanel.track('Login');
}
runAuth(data.id, data.token);
}).error(errorAlert);
}, function( e ){

View File

@@ -320,6 +320,11 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
}
$scope.message.content = '';
$scope._sending = false;
if (group.privacy == 'public'){
mixpanel.track('Group Chat',{'groupType':group.type,'privacy':group.privacy,'groupName':group.name,'message':message})
} else {
mixpanel.track('Group Chat',{'groupType':group.type,'privacy':group.privacy})
}
}, function(err){
$scope._sending = false;
});
@@ -431,6 +436,8 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
if (confirm(window.env.t('confirmGuild'))) {
group.$save(function(saved){
if (saved.privacy == 'public') {mixpanel.track('Join Group',{'owner':true,'groupType':'guild','privacy':saved.privacy,'groupName':saved.name})}
else {mixpanel.track('Join Group',{'owner':true,'groupType':'guild','privacy':saved.privacy})}
$rootScope.hardRedirect('/#/options/groups/guilds/' + saved._id);
});
}
@@ -445,6 +452,8 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
}
group.$join(function(joined){
if (joined.privacy == 'public') {mixpanel.track('Join Group',{'owner':false,'groupType':'guild','privacy':joined.privacy,'groupName':joined.name})}
else {mixpanel.track('Join Group',{'owner':false,'groupType':'guild','privacy':joined.privacy})}
$rootScope.hardRedirect('/#/options/groups/guilds/' + joined._id);
})
}
@@ -510,6 +519,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
$scope.create = function(group){
group.$save(function(){
mixpanel.track('Join Group',{'owner':true,'groupType':'party','privacy':'private'});
$rootScope.hardRedirect('/#/options/groups/party');
});
}
@@ -517,6 +527,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
$scope.join = function(party){
var group = new Groups.Group({_id: party.id, name: party.name});
group.$join(function(){
mixpanel.track('Join Group',{'owner':false,'groupType':'party','privacy':'private'});
$rootScope.hardRedirect('/#/options/groups/party');
});
}

View File

@@ -180,6 +180,7 @@ habitrpg.controller("InventoryCtrl",
$rootScope.selectedQuest = undefined;
}
$scope.questInit = function(){
mixpanel.track("Quest",{"owner":true,"response":"accept","questName":$scope.selectedQuest.key});
$rootScope.party.$questAccept({key:$scope.selectedQuest.key}, function(){
$rootScope.party.$get();
});

View File

@@ -87,6 +87,7 @@ habitrpg.controller('NotificationCtrl',
Notification.drop(User.user._tmp.drop.dialog);
}
$rootScope.playSound('Item_Drop');
mixpanel.track("Acquire Item",{'itemName':after.key,'acquireMethod':'Drop'})
});
$rootScope.$watch('user.achievements.streak', function(after, before){

View File

@@ -21,7 +21,9 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
if (direction === 'down') $rootScope.playSound('Minus_Habit');
else if (direction === 'up') $rootScope.playSound('Plus_Habit');
}
User.user.ops.score({params:{id: task.id, direction:direction}})
User.user.ops.score({params:{id: task.id, direction:direction}});
mixpanel.register({'Gold':Math.floor(User.user.stats.gp),'Health':Math.ceil(User.user.stats.hp),'Experience':Math.floor(User.user.stats.exp),'Level':User.user.stats.lvl,'Mana':Math.floor(User.user.stats.mp),'Class':User.user.stats.class,'subscription':User.user.purchased.plan.planId,'contributorLevel':User.user.contributor.level,'UUID':User.user._id});
mixpanel.track('Score Task',{'taskType':task.type,'direction':direction});
};
function addTask(addTo, listDef, task) {