Skip to content

Commit

Permalink
mixpanel tracking login working
Browse files Browse the repository at this point in the history
  • Loading branch information
etweisberg committed Sep 10, 2024
1 parent c318d0e commit 1065c7d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
1 change: 0 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"googleapis": "^108.0.0",
"jsonwebtoken": "^8.5.1",
"mixpanel": "^0.18.0",
"mixpanel-browser": "^2.49.0",
"mongodb-memory-server": "^8.2.0",
"mongoose": "^6.1.10",
"passport": "^0.6.0",
Expand Down
9 changes: 9 additions & 0 deletions server/src/config/configMixpanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Mixpanel from 'mixpanel';

const token = process.env.MIXPANEL_TOKEN || 'DEFAULT_TOKEN';
const mixpanel = Mixpanel.init(token);

console.log('Mixpanel initialized with token:', token);
console.log('Mixpanel:', mixpanel.people);

export default mixpanel;
8 changes: 2 additions & 6 deletions server/src/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* user's authentication such as login, logout, and registration.
*/
import express from 'express';
import mixpanel from 'mixpanel-browser';
import passport from 'passport';
import crypto from 'crypto';
import { hash } from 'bcrypt';
Expand All @@ -26,9 +25,7 @@ import {
removeInviteByToken,
} from '../services/invite.service.ts';
import { IInvite } from '../models/invite.model.ts';

const mixpanelToken = process.env.MIXPANEL_TOKEN || 'DEFAULT_TOKEN';
mixpanel.init(mixpanelToken);
import mixpanel from '../config/configMixpanel.ts';

/**
* A controller function to login a user and create a session with Passport.
Expand Down Expand Up @@ -69,8 +66,7 @@ const login = async (
next(ApiError.internal('Failed to log in user'));
return;
}
console.log('Mixpanel tracking login');
mixpanel.track('User Logged In', {
mixpanel.track('Login', {
distinct_id: user._id,
email: user.email,
});
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8019,11 +8019,6 @@ minizlib@^2.1.1:
minipass "^3.0.0"
yallist "^4.0.0"

mixpanel-browser@^2.49.0:
version "2.49.0"
resolved "https://registry.yarnpkg.com/mixpanel-browser/-/mixpanel-browser-2.49.0.tgz#de3f4f2d0f3a32b4babf6d827ef983a9fd48a711"
integrity sha512-RZJCO7XXuuHBAWG5fd9Mavz994M7v7W3Qiaq8NzmN631pa4BQ0vNZQtRFqKcCCOBn4xqOZbX2GkuC7ZkQoL4cQ==

mixpanel@^0.18.0:
version "0.18.0"
resolved "https://registry.yarnpkg.com/mixpanel/-/mixpanel-0.18.0.tgz#f010f2622902d0d4b434de238446ec8e5966ee32"
Expand Down

0 comments on commit 1065c7d

Please sign in to comment.