Skip to content

Commit 1479b6f

Browse files
author
Ives van Hoorne
committed
Tracking of sign ins
1 parent 0bc02be commit 1479b6f

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

src/app/pages/Sandbox/Editor/Content/Header/Action.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default ({
100100
}
101101

102102
return (
103-
<ActionLink highlight={highlight} to={href}>
103+
<ActionLink to={href}>
104104
<IconContainer>
105105
<Icon />
106106
</IconContainer> {title}

src/app/store/user/actions.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @flow
22
import { signInUrl } from 'app/utils/url-generator';
3+
import { identify } from 'app/utils/analytics';
34

45
import { createAPIActions, doRequest } from '../api/actions';
56
import notifActions from '../notifications/actions';
@@ -40,11 +41,7 @@ const getCurrentUser = () => async (dispatch: Function, getState: Function) => {
4041
doRequest(GET_CURRENT_USER_API, `users/current`)
4142
);
4243

43-
Raven.setUserContext({
44-
email: data.email,
45-
id: data.id,
46-
username: data.username,
47-
});
44+
identify(data);
4845

4946
dispatch({ type: SET_CURRENT_USER, data });
5047
} catch (e) {

src/app/utils/analytics.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// @flow
2+
import _debug from 'app/utils/debug';
3+
import type { CurrentUser } from 'common/types';
4+
5+
const debug = _debug('cs:analytics');
6+
7+
const heapAvailable = () => typeof window.heap === 'function';
8+
const sentryAvailable = () => typeof window.Raven === 'object';
9+
10+
export default function track(event: string, data: Object) {
11+
if (!heapAvailable()) return;
12+
13+
debug(`Tracking event ${event} with data`, data);
14+
if (process.env.NODE_ENV === 'production') {
15+
window.heap.track(event, data);
16+
}
17+
}
18+
19+
function identifyHeap(user: CurrentUser) {
20+
if (!heapAvailable()) return;
21+
22+
if (process.env.NODE_ENV === 'production') {
23+
window.heap.identify(user.username);
24+
window.heap.addUserProperties({
25+
id: user.id,
26+
name: user.name,
27+
email: user.email,
28+
});
29+
}
30+
}
31+
32+
function identifySentry(user: CurrentUser) {
33+
if (!sentryAvailable()) return;
34+
35+
window.Raven.setUserContext({
36+
email: user.email,
37+
id: user.id,
38+
username: user.username,
39+
});
40+
}
41+
42+
export function identify(user: CurrentUser) {
43+
debug(`Identified ${user.username}`);
44+
identifyHeap(user);
45+
identifySentry(user);
46+
}

0 commit comments

Comments
 (0)