3 const _
= require('lodash');
4 var env
= require('gitter-web-env');
7 var emailAddressService
= require('gitter-web-email-addresses');
8 var gaCookieParser
= require('./ga-cookie-parser');
10 // Use this whenever a user first signs up.
11 module
.exports
= function trackNewUser(req
, user
, provider
) {
12 // NOTE: tracking a signup after an invite is separate to this
13 emailAddressService(user
).then(function(email
) {
14 const emailList
= user
.emails
|| [];
15 emailList
.unshift(email
);
16 // We are sanitizing the data a bit here so the database
17 // doesn't store `null` and duplicate case different emails
18 const lowerCaseEmailList
= emailList
.filter(email
=> !!email
).map(email
=> email
.toLowerCase());
19 user
.emails
= _
.uniq(lowerCaseEmailList
);
22 Object
.assign({}, user
, {
23 // this is only set because stats.userUpdate requires it
28 // NOTE: other stats calls also pass in properties
29 stats
.event('new_user', {
32 method
: provider
+ '_oauth',
33 username
: user
.username
,
34 source
: req
.session
.source
,
35 googleAnalyticsUniqueId
: gaCookieParser(req
)
38 // Persist the new emails