mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
feat(analytics): Party properties
Adds tracking of the user's party ID and size as user-level analytics properties.
This commit is contained in:
@@ -9,6 +9,7 @@ describe('Analytics Service', function () {
|
||||
user = specHelper.newUser();
|
||||
user.contributor = {};
|
||||
user.purchased = { plan: {} };
|
||||
user.flags.tour = { intro: null };
|
||||
|
||||
module(function($provide) {
|
||||
$provide.value('User', {user: user});
|
||||
@@ -217,7 +218,8 @@ describe('Analytics Service', function () {
|
||||
Level: 24,
|
||||
Mana: 41,
|
||||
contributorLevel: 1,
|
||||
subscription: 'unique-plan-id'
|
||||
subscription: 'unique-plan-id',
|
||||
tutorialComplete: true
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
@@ -230,6 +232,7 @@ describe('Analytics Service', function () {
|
||||
user.stats.mp = 41;
|
||||
user.contributor.level = 1;
|
||||
user.purchased.plan.planId = 'unique-plan-id';
|
||||
user.flags.tour.intro = -2;
|
||||
|
||||
analytics.updateUser();
|
||||
clock.tick();
|
||||
|
||||
@@ -266,6 +266,9 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
}
|
||||
$scope.message.content = '';
|
||||
$scope._sending = false;
|
||||
if (group.type == 'party') {
|
||||
Analytics.updateUser({'partySize':group.memberCount});
|
||||
}
|
||||
if (group.privacy == 'public'){
|
||||
Analytics.track({'hitType':'event','eventCategory':'behavior','eventAction':'group chat','groupType':group.type,'privacy':group.privacy,'groupName':group.name,'message':message});
|
||||
} else {
|
||||
@@ -475,17 +478,19 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
$scope.create = function(group){
|
||||
group.$save(function(){
|
||||
Analytics.track({'hitType':'event','eventCategory':'behavior','eventAction':'join group','owner':true,'groupType':'party','privacy':'private'});
|
||||
Analytics.updateUser({'partyID':group.id,'partySize':1});
|
||||
$rootScope.hardRedirect('/#/options/groups/party');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.join = function(party){
|
||||
var group = new Groups.Group({_id: party.id, name: party.name});
|
||||
group.$join(function(){
|
||||
Analytics.track({'hitType':'event','eventCategory':'behavior','eventAction':'join group','owner':false,'groupType':'party','privacy':'private'});
|
||||
Analytics.updateUser({'partyID':party.id});
|
||||
$rootScope.hardRedirect('/#/options/groups/party');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: refactor guild and party leave into one function
|
||||
$scope.leave = function(keep) {
|
||||
@@ -494,10 +499,11 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
$scope.popoverEl.popover('destroy');
|
||||
} else {
|
||||
Groups.Group.leave({gid: $scope.selectedGroup._id, keep:keep}, undefined, function(){
|
||||
Analytics.updateUser({'partySize':null,'partyID':null});
|
||||
$rootScope.hardRedirect('/#/options/groups/party');
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: refactor guild and party clickLeave into one function
|
||||
$scope.clickLeave = function(group, $event){
|
||||
@@ -547,7 +553,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
|
||||
$scope.questAccept = function(party){
|
||||
Groups.questAccept(party);
|
||||
}
|
||||
};
|
||||
|
||||
$scope.questReject = function(party){
|
||||
Groups.questReject(party);
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
properties.Level = user.stats.lvl;
|
||||
properties.Mana = Math.floor(user.stats.mp);
|
||||
}
|
||||
if (user.flags.tour && user.flags.tour.intro === '-2') properties.tutorialComplete = true;
|
||||
if (user.contributor && user.contributor.level) properties.contributorLevel = user.contributor.level;
|
||||
if (user.purchased && user.purchased.plan.planId) properties.subscription = user.purchased.plan.planId;
|
||||
}
|
||||
|
||||
@@ -64,21 +64,25 @@ function($rootScope, ApiUrl, $resource, $q, $http, User, Challenges, Analytics,
|
||||
},
|
||||
|
||||
questAccept: function(party){
|
||||
Analytics.updateUser({'partySize':party.memberCount,'partyID':party.id});
|
||||
party.$questAccept()
|
||||
.then(syncUser, logError);
|
||||
},
|
||||
|
||||
questReject: function(party){
|
||||
Analytics.updateUser({'partySize':party.memberCount,'partyID':party.id});
|
||||
party.$questReject()
|
||||
.then(syncUser, logError);
|
||||
},
|
||||
|
||||
questCancel: function(party){
|
||||
Analytics.updateUser({'partySize':party.memberCount,'partyID':party.id});
|
||||
party.$questCancel()
|
||||
.then(syncUser, logError);
|
||||
},
|
||||
|
||||
questAbort: function(party){
|
||||
Analytics.updateUser({'partySize':party.memberCount,'partyID':party.id});
|
||||
party.$questAbort()
|
||||
.then(syncUser, logError);
|
||||
},
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
function questsFactory($rootScope,Content,Groups,User,Analytics) {
|
||||
|
||||
var user = User.user;
|
||||
var party = $rootScope.party;
|
||||
|
||||
function lockQuest(quest,ignoreLevel) {
|
||||
if (!ignoreLevel){
|
||||
@@ -86,8 +87,9 @@
|
||||
|
||||
function questInit(){
|
||||
Analytics.track({'hitType':'event','eventCategory':'behavior','eventAction':'quest','owner':true,'response':'accept','questName':$rootScope.selectedQuest.key});
|
||||
$rootScope.party.$questAccept({key:$rootScope.selectedQuest.key}, function(){
|
||||
$rootScope.party.$get();
|
||||
Analytics.updateUser({'partySize':party.memberCount,'partyID':party.id});
|
||||
party.$questAccept({key:$rootScope.selectedQuest.key}, function(){
|
||||
party.$get();
|
||||
$rootScope.$state.go('options.social.party');
|
||||
});
|
||||
closeQuest();
|
||||
|
||||
Reference in New Issue
Block a user