Commit 238a1d2c authored by Sean Roberts's avatar Sean Roberts

Adding group leave, switch, and view activity metrics

parent 4beda4fa
...@@ -64,6 +64,9 @@ function analytics($analytics, $window, settings) { ...@@ -64,6 +64,9 @@ function analytics($analytics, $window, settings) {
ANNOTATION_SHARED: 'annotationShared', ANNOTATION_SHARED: 'annotationShared',
ANNOTATION_UPDATED: 'annotationUpdated', ANNOTATION_UPDATED: 'annotationUpdated',
DOCUMENT_SHARED: 'documentShared', DOCUMENT_SHARED: 'documentShared',
GROUP_LEAVE: 'groupLeave',
GROUP_SWITCH: 'groupSwitch',
GROUP_VIEW_ACTIVITY: 'groupViewActivity',
HIGHLIGHT_CREATED: 'highlightCreated', HIGHLIGHT_CREATED: 'highlightCreated',
HIGHLIGHT_UPDATED: 'highlightUpdated', HIGHLIGHT_UPDATED: 'highlightUpdated',
HIGHLIGHT_DELETED: 'highlightDeleted', HIGHLIGHT_DELETED: 'highlightDeleted',
......
...@@ -4,7 +4,7 @@ var persona = require('../filter/persona'); ...@@ -4,7 +4,7 @@ var persona = require('../filter/persona');
var serviceConfig = require('../service-config'); var serviceConfig = require('../service-config');
// @ngInject // @ngInject
function GroupListController($window, groups, settings, serviceUrl) { function GroupListController($window, analytics, groups, settings, serviceUrl) {
this.groups = groups; this.groups = groups;
this.createNewGroup = function() { this.createNewGroup = function() {
...@@ -20,11 +20,17 @@ function GroupListController($window, groups, settings, serviceUrl) { ...@@ -20,11 +20,17 @@ function GroupListController($window, groups, settings, serviceUrl) {
var message = 'Are you sure you want to leave the group "' + var message = 'Are you sure you want to leave the group "' +
groupName + '"?'; groupName + '"?';
if ($window.confirm(message)) { if ($window.confirm(message)) {
analytics.track(analytics.events.GROUP_LEAVE);
groups.leave(groupId); groups.leave(groupId);
} }
}; };
this.viewGroupActivity = function () {
analytics.track(analytics.events.GROUP_VIEW_ACTIVITY);
};
this.focusGroup = function (groupId) { this.focusGroup = function (groupId) {
analytics.track(analytics.events.GROUP_SWITCH);
groups.focus(groupId); groups.focus(groupId);
}; };
......
...@@ -12,6 +12,7 @@ describe('groupList', function () { ...@@ -12,6 +12,7 @@ describe('groupList', function () {
var groups; var groups;
var fakeGroups; var fakeGroups;
var fakeAnalytics;
var fakeServiceUrl; var fakeServiceUrl;
var fakeSettings; var fakeSettings;
...@@ -24,12 +25,23 @@ describe('groupList', function () { ...@@ -24,12 +25,23 @@ describe('groupList', function () {
}); });
beforeEach(function () { beforeEach(function () {
fakeAnalytics = {
track: sinon.stub(),
events: {
GROUP_LEAVE: 'groupLeave',
GROUP_SWITCH: 'groupSwitch',
GROUP_VIEW_ACTIVITY: 'groupViewActivity',
},
};
fakeServiceUrl = sinon.stub(); fakeServiceUrl = sinon.stub();
fakeSettings = { fakeSettings = {
authDomain: 'example.com', authDomain: 'example.com',
}; };
angular.mock.module('app', { angular.mock.module('app', {
analytics: fakeAnalytics,
serviceUrl: fakeServiceUrl, serviceUrl: fakeServiceUrl,
settings: fakeSettings, settings: fakeSettings,
}); });
...@@ -88,6 +100,13 @@ describe('groupList', function () { ...@@ -88,6 +100,13 @@ describe('groupList', function () {
assert.equal(link[0].href, GROUP_LINK); assert.equal(link[0].href, GROUP_LINK);
}); });
it('should track metrics when a user attempts to view a groups activity', function () {
var element = createGroupList();
var link = element.find('.share-link');
link.click();
assert.calledWith(fakeAnalytics.track, fakeAnalytics.events.GROUP_VIEW_ACTIVITY);
});
function clickLeaveIcon(element, acceptPrompt) { function clickLeaveIcon(element, acceptPrompt) {
var leaveLink = element.find('.h-icon-cancel-outline'); var leaveLink = element.find('.h-icon-cancel-outline');
...@@ -102,18 +121,32 @@ describe('groupList', function () { ...@@ -102,18 +121,32 @@ describe('groupList', function () {
var element = createGroupList(); var element = createGroupList();
clickLeaveIcon(element, true); clickLeaveIcon(element, true);
assert.ok(fakeGroups.leave.calledWith('h-devs')); assert.ok(fakeGroups.leave.calledWith('h-devs'));
assert.calledWith(fakeAnalytics.track, fakeAnalytics.events.GROUP_LEAVE);
}); });
it('should not leave group when confirmation is dismissed', function () { it('should not leave group when confirmation is dismissed', function () {
var element = createGroupList(); var element = createGroupList();
clickLeaveIcon(element, false); clickLeaveIcon(element, false);
assert.notCalled(fakeGroups.leave); assert.notCalled(fakeGroups.leave);
assert.notCalled(fakeAnalytics.track);
}); });
it('should not change the focused group when leaving', function () { it('should not change the focused group when leaving', function () {
var element = createGroupList(); var element = createGroupList();
clickLeaveIcon(element, true); clickLeaveIcon(element, true);
assert.notCalled(fakeGroups.focus); assert.notCalled(fakeGroups.focus);
assert.calledWith(fakeAnalytics.track, fakeAnalytics.events.GROUP_LEAVE);
});
it('should change current group focus when click another group', function () {
var element = createGroupList();
var groupItems = element.find('.group-item');
// click the second group
groupItems[1].click();
assert.calledOnce(fakeGroups.focus);
assert.calledWith(fakeAnalytics.track, fakeAnalytics.events.GROUP_SWITCH);
}); });
it('should open a window when "New Group" is clicked', function () { it('should open a window when "New Group" is clicked', function () {
...@@ -123,6 +156,7 @@ describe('groupList', function () { ...@@ -123,6 +156,7 @@ describe('groupList', function () {
var element = createGroupList(); var element = createGroupList();
$window.open = sinon.stub(); $window.open = sinon.stub();
var newGroupLink = var newGroupLink =
element[0].querySelector('.new-group-btn a'); element[0].querySelector('.new-group-btn a');
angular.element(newGroupLink).click(); angular.element(newGroupLink).click();
......
...@@ -58,7 +58,10 @@ ...@@ -58,7 +58,10 @@
</a> </a>
</div> </div>
<div class="share-link-container" ng-click="$event.stopPropagation()" ng-if="!group.public"> <div class="share-link-container" ng-click="$event.stopPropagation()" ng-if="!group.public">
<a class="share-link" href="{{group.url}}" target="_blank"> <a class="share-link"
href="{{group.url}}"
target="_blank"
ng-click="vm.viewGroupActivity()">
View group activity and invite others View group activity and invite others
</a> </a>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment