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) {
ANNOTATION_SHARED: 'annotationShared',
ANNOTATION_UPDATED: 'annotationUpdated',
DOCUMENT_SHARED: 'documentShared',
GROUP_LEAVE: 'groupLeave',
GROUP_SWITCH: 'groupSwitch',
GROUP_VIEW_ACTIVITY: 'groupViewActivity',
HIGHLIGHT_CREATED: 'highlightCreated',
HIGHLIGHT_UPDATED: 'highlightUpdated',
HIGHLIGHT_DELETED: 'highlightDeleted',
......
......@@ -4,7 +4,7 @@ var persona = require('../filter/persona');
var serviceConfig = require('../service-config');
// @ngInject
function GroupListController($window, groups, settings, serviceUrl) {
function GroupListController($window, analytics, groups, settings, serviceUrl) {
this.groups = groups;
this.createNewGroup = function() {
......@@ -20,11 +20,17 @@ function GroupListController($window, groups, settings, serviceUrl) {
var message = 'Are you sure you want to leave the group "' +
groupName + '"?';
if ($window.confirm(message)) {
analytics.track(analytics.events.GROUP_LEAVE);
groups.leave(groupId);
}
};
this.viewGroupActivity = function () {
analytics.track(analytics.events.GROUP_VIEW_ACTIVITY);
};
this.focusGroup = function (groupId) {
analytics.track(analytics.events.GROUP_SWITCH);
groups.focus(groupId);
};
......
......@@ -12,6 +12,7 @@ describe('groupList', function () {
var groups;
var fakeGroups;
var fakeAnalytics;
var fakeServiceUrl;
var fakeSettings;
......@@ -24,12 +25,23 @@ describe('groupList', function () {
});
beforeEach(function () {
fakeAnalytics = {
track: sinon.stub(),
events: {
GROUP_LEAVE: 'groupLeave',
GROUP_SWITCH: 'groupSwitch',
GROUP_VIEW_ACTIVITY: 'groupViewActivity',
},
};
fakeServiceUrl = sinon.stub();
fakeSettings = {
authDomain: 'example.com',
};
angular.mock.module('app', {
analytics: fakeAnalytics,
serviceUrl: fakeServiceUrl,
settings: fakeSettings,
});
......@@ -88,6 +100,13 @@ describe('groupList', function () {
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) {
var leaveLink = element.find('.h-icon-cancel-outline');
......@@ -102,18 +121,32 @@ describe('groupList', function () {
var element = createGroupList();
clickLeaveIcon(element, true);
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 () {
var element = createGroupList();
clickLeaveIcon(element, false);
assert.notCalled(fakeGroups.leave);
assert.notCalled(fakeAnalytics.track);
});
it('should not change the focused group when leaving', function () {
var element = createGroupList();
clickLeaveIcon(element, true);
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 () {
......@@ -123,6 +156,7 @@ describe('groupList', function () {
var element = createGroupList();
$window.open = sinon.stub();
var newGroupLink =
element[0].querySelector('.new-group-btn a');
angular.element(newGroupLink).click();
......
......@@ -58,7 +58,10 @@
</a>
</div>
<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
</a>
</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