Commit 721feed5 authored by Eric Eastwood's avatar Eric Eastwood

Merge branch 'fix-new-user-stat-tracking' into 'develop'

Fix new_user stat not being pushed out and tracked

See merge request gitlab-org/gitter/webapp!1216
parents a78159ff 106ebec9
......@@ -2,6 +2,10 @@
- Remove rooms that now 404 from the homepage, https://gitlab.com/gitlab-org/gitter/webapp/merge_requests/1215
Developer facing:
- Fix `new_user` stat not being pushed out and tracked, https://gitlab.com/gitlab-org/gitter/webapp/merge_requests/1216
# 19.13.0 - 2018-7-27
......
......@@ -11,7 +11,7 @@ var mixpanel = require('../../web/mixpanelUtils');
* @return Boolean - the result of the check
*/
function isRelativeURL(url) {
var relativeUrl = new RegExp('^\/[^/]');
var relativeUrl = new RegExp('^/[^/]');
return relativeUrl.test(url);
}
......@@ -31,7 +31,6 @@ module.exports = function trackLoginForProvider(provider) {
//send data to stats service
if (query.action) {
stats.event(query.action + "_clicked", {
distinctId: mixpanel.getMixpanelDistinctId(req.cookies),
method: provider+'_oauth',
button: query.source
});
......
......@@ -9,7 +9,6 @@ var logger = env.logger;
var moment = require('moment');
var GitHubStrategy = require('@gitterhq/passport-github').Strategy;
var TokenStateProvider = require('@gitterhq/passport-oauth2').TokenStateProvider;
var mixpanel = require('../../web/mixpanelUtils');
var extractGravatarVersion = require('gitter-web-avatars/server/extract-gravatar-version');
var gaCookieParser = require('../ga-cookie-parser');
var userService = require('gitter-web-users');
......@@ -40,17 +39,12 @@ function ageInHours(date) {
function updateUser(req, accessToken, user, githubUserProfile) {
// If the user was in the DB already but was invited, notify stats services
if (user.isInvited()) {
// IMPORTANT: The alias can only happen ONCE. Do not remove.
stats.alias(mixpanel.getMixpanelDistinctId(req.cookies), user.id, function(err) {
if (err) logger.error('Error aliasing user:', { exception: err });
stats.event("new_user", {
userId: user.id,
method: 'github_oauth',
username: user.username,
source: 'invited',
googleAnalyticsUniqueId: gaCookieParser(req)
});
stats.event("new_user", {
userId: user.id,
method: 'github_oauth',
username: user.username,
source: 'invited',
googleAnalyticsUniqueId: gaCookieParser(req)
});
}
......@@ -106,23 +100,18 @@ function addUser(req, accessToken, githubUserProfile) {
updateUserLocale(req, user);
// IMPORTANT: The alias can only happen ONCE. Do not remove.
stats.alias(mixpanel.getMixpanelDistinctId(req.cookies), user.id, function(err) {
if (err) logger.error('Error aliasing user:', { exception: err });
trackNewUser(req, user, 'github');
// Flag the user as a new github user if they've created their account
// in the last two hours
// NOTE: this relies on the fact that undefined is not smaller than 2..
if (ageInHours(githubUserProfile.created_at) < 2) {
stats.event("new_github_user", {
userId: user.id,
username: user.username,
googleAnalyticsUniqueId: gaCookieParser(req)
});
}
});
trackNewUser(req, user, 'github');
// Flag the user as a new github user if they've created their account
// in the last two hours
// NOTE: this relies on the fact that undefined is not smaller than 2..
if (ageInHours(githubUserProfile.created_at) < 2) {
stats.event("new_github_user", {
userId: user.id,
username: user.username,
googleAnalyticsUniqueId: gaCookieParser(req)
});
}
return passportLogin(req, user);
});
......
"use strict";
var env = require('gitter-web-env');
var stats = env.stats;
var logger = env.logger;
var trackNewUser = require('./track-new-user');
var trackUserLogin = require('./track-user-login');
var mixpanel = require('./mixpanelUtils');
module.exports = function trackSignupOrLogin(req, user, isNewUser, provider) {
if (isNewUser) {
stats.alias(mixpanel.getMixpanelDistinctId(req.cookies), user.id, function(err) {
if (err) logger.error('Error aliasing user:', { exception: err });
trackNewUser(req, user, provider);
});
trackNewUser(req, user, provider);
} else {
trackUserLogin(req, user, provider);
}
......
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