Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
9d639fea
Commit
9d639fea
authored
Jan 23, 2017
by
Sean Roberts
Committed by
GitHub
Jan 23, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #194 from hypothesis/client-metrics-tracking
Add analytics tracking
parents
547c01cb
42015a5e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
133 additions
and
2 deletions
+133
-2
analytics.js
src/sidebar/analytics.js
+59
-0
app.js
src/sidebar/app.js
+1
-0
analytics-test.js
src/sidebar/test/analytics-test.js
+62
-0
widget-controller-test.js
src/sidebar/test/widget-controller-test.js
+6
-0
widget-controller.js
src/sidebar/widget-controller.js
+5
-2
No files found.
src/sidebar/analytics.js
0 → 100644
View file @
9d639fea
'use strict'
;
var
VIA_REFERRER
=
/^https:
\/\/(
qa-
)?
via.hypothes.is
\/
/
;
var
globalGAOptions
=
function
(
win
,
settings
){
settings
=
settings
||
{};
var
globalOpts
=
{
category
:
''
,
};
var
validTypes
=
[
'chrome-extension'
,
'embed'
,
'bookmarklet'
,
'via'
];
// The preferred method for deciding what type of app is running is
// through the setting of the appType to one of the valid types above.
// However, we also want to capture app types where we were not given
// the appType setting explicitly - these are the app types that were
// added before we added the analytics logic
if
(
validTypes
.
indexOf
((
settings
.
appType
||
''
).
toLowerCase
())
>
-
1
){
globalOpts
.
category
=
settings
.
appType
.
toLowerCase
();
}
else
if
(
win
.
location
.
protocol
===
'chrome-extension:'
){
globalOpts
.
category
=
'chrome-extension'
;
}
else
if
(
VIA_REFERRER
.
test
(
win
.
document
.
referrer
)){
globalOpts
.
category
=
'via'
;
}
else
{
globalOpts
.
category
=
'embed'
;
}
return
globalOpts
;
};
/**
* Analytics API to simplify and standardize the values that we
* pass to the Angulartics service.
*
* These analytics are based on google analytics and need to conform to its
* requirements. Specifically, we are required to send the event and a category.
*
* We will standardize the category to be the appType of the client settings
*/
// @ngInject
function
analytics
(
$analytics
,
$window
,
settings
)
{
var
options
=
globalGAOptions
(
$window
,
settings
);
return
{
/**
* @param {string} event This is the event name that we are capturing
* in our analytics. Example: 'sidebarOpened'. Use camelCase to track multiple
* words.
*/
track
:
function
(
event
){
$analytics
.
eventTrack
(
event
,
options
);
},
};
}
module
.
exports
=
analytics
;
src/sidebar/app.js
View file @
9d639fea
...
...
@@ -164,6 +164,7 @@ module.exports = angular.module('h', [
.
directive
(
'topBar'
,
require
(
'./directive/top-bar'
))
.
directive
(
'windowScroll'
,
require
(
'./directive/window-scroll'
))
.
service
(
'analytics'
,
require
(
'./analytics'
))
.
service
(
'annotationMapper'
,
require
(
'./annotation-mapper'
))
.
service
(
'annotationUI'
,
require
(
'./annotation-ui'
))
.
service
(
'auth'
,
require
(
'./auth'
).
service
)
...
...
src/sidebar/test/analytics-test.js
0 → 100644
View file @
9d639fea
'use strict'
;
var
analyticsService
=
require
(
'../analytics'
);
describe
(
'analytics'
,
function
()
{
var
$analyticsStub
;
var
$windowStub
;
var
eventTrackStub
;
beforeEach
(
function
()
{
$analyticsStub
=
{
eventTrack
:
sinon
.
stub
(),
};
eventTrackStub
=
$analyticsStub
.
eventTrack
;
$windowStub
=
{
location
:
{
href
:
''
,
protocol
:
'https:'
,
},
document
:
{
referrer
:
''
,
},
};
});
describe
(
'applying global category based on environment contexts'
,
function
()
{
it
(
'sets the category to match the appType setting value'
,
function
(){
var
validTypes
=
[
'chrome-extension'
,
'embed'
,
'bookmarklet'
,
'via'
];
validTypes
.
forEach
(
function
(
appType
,
index
){
analyticsService
(
$analyticsStub
,
$windowStub
,
{
appType
:
appType
}).
track
(
'event'
+
index
);
assert
.
deepEqual
(
eventTrackStub
.
args
[
index
],
[
'event'
+
index
,
{
category
:
appType
}]);
});
});
it
(
'sets category as embed if no other matches can be made'
,
function
()
{
analyticsService
(
$analyticsStub
,
$windowStub
).
track
(
'eventA'
);
assert
.
deepEqual
(
eventTrackStub
.
args
[
0
],
[
'eventA'
,
{
category
:
'embed'
}]);
});
it
(
'sets category as via if url matches the via uri pattern'
,
function
()
{
$windowStub
.
document
.
referrer
=
'https://via.hypothes.is/'
;
analyticsService
(
$analyticsStub
,
$windowStub
).
track
(
'eventA'
);
assert
.
deepEqual
(
eventTrackStub
.
args
[
0
],
[
'eventA'
,
{
category
:
'via'
}]);
// match staging as well
$windowStub
.
document
.
referrer
=
'https://qa-via.hypothes.is/'
;
analyticsService
(
$analyticsStub
,
$windowStub
).
track
(
'eventB'
);
assert
.
deepEqual
(
eventTrackStub
.
args
[
1
],
[
'eventB'
,
{
category
:
'via'
}]);
});
it
(
'sets category as chrome-extension if protocol matches chrome-extension:'
,
function
()
{
$windowStub
.
location
.
protocol
=
'chrome-extension:'
;
analyticsService
(
$analyticsStub
,
$windowStub
).
track
(
'eventA'
);
assert
.
deepEqual
(
eventTrackStub
.
args
[
0
],
[
'eventA'
,
{
category
:
'chrome-extension'
}]);
});
});
});
src/sidebar/test/widget-controller-test.js
View file @
9d639fea
...
...
@@ -40,6 +40,7 @@ describe('WidgetController', function () {
var
$rootScope
;
var
$scope
;
var
annotationUI
;
var
fakeAnalytics
;
var
fakeAnnotationMapper
;
var
fakeDrafts
;
var
fakeFeatures
;
...
...
@@ -69,6 +70,10 @@ describe('WidgetController', function () {
searchClients
=
[];
sandbox
=
sinon
.
sandbox
.
create
();
fakeAnalytics
=
{
track
:
sandbox
.
spy
(),
};
fakeAnnotationMapper
=
{
loadAnnotations
:
sandbox
.
spy
(),
unloadAnnotations
:
sandbox
.
spy
(),
...
...
@@ -112,6 +117,7 @@ describe('WidgetController', function () {
search
:
sinon
.
stub
(),
};
$provide
.
value
(
'analytics'
,
fakeAnalytics
);
$provide
.
value
(
'annotationMapper'
,
fakeAnnotationMapper
);
$provide
.
value
(
'drafts'
,
fakeDrafts
);
$provide
.
value
(
'features'
,
fakeFeatures
);
...
...
src/sidebar/widget-controller.js
View file @
9d639fea
...
...
@@ -32,8 +32,8 @@ function groupIDFromSelection(selection, results) {
// @ngInject
module
.
exports
=
function
WidgetController
(
$scope
,
an
notationUI
,
annotationMapper
,
drafts
,
features
,
frameSync
,
groups
,
rootThread
,
settings
,
streamer
,
streamFilter
,
store
$scope
,
an
alytics
,
annotationUI
,
annotationMapper
,
drafts
,
features
,
frameSync
,
groups
,
rootThread
,
settings
,
streamer
,
streamFilter
,
store
)
{
function
thread
()
{
return
rootThread
.
thread
(
annotationUI
.
getState
());
...
...
@@ -201,6 +201,9 @@ module.exports = function WidgetController(
}
$scope
.
$on
(
'sidebarOpened'
,
function
()
{
analytics
.
track
(
'sidebarOpened'
);
streamer
.
connect
();
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment