diff --git a/lib/api/routes/jobRouter.js b/lib/api/routes/jobRouter.js index 37ac1f5..35f3aac 100644 --- a/lib/api/routes/jobRouter.js +++ b/lib/api/routes/jobRouter.js @@ -6,6 +6,7 @@ import * as immoscoutProvider from '../../provider/immoscout.js'; import { config } from '../../utils.js'; import { isAdmin } from '../security.js'; import {isScrapingAntApiKeySet} from '../../services/scrapingAnt.js'; +import {trackDemoJobCreated} from '../../services/tracking/Tracker.js'; const service = restana(); const jobRouter = service.newRouter(); function doesJobBelongsToUser(job, req) { @@ -68,6 +69,11 @@ jobRouter.post('/', async (req, res) => { res.send(new Error(error)); console.error(error); } + trackDemoJobCreated({ + name, + provider, + adapter: notificationAdapter + }); res.send(); }); jobRouter.delete('', async (req, res) => { diff --git a/lib/api/routes/loginRoute.js b/lib/api/routes/loginRoute.js index c41240b..7234021 100644 --- a/lib/api/routes/loginRoute.js +++ b/lib/api/routes/loginRoute.js @@ -1,6 +1,8 @@ import restana from 'restana'; import * as userStorage from '../../services/storage/userStorage.js'; import * as hasher from '../../services/security/hash.js'; +import {config} from '../../utils.js'; +import {trackDemoAccessed} from '../../services/tracking/Tracker.js'; const service = restana(); const loginRouter = service.newRouter(); loginRouter.get('/user', async (req, res) => { @@ -24,6 +26,11 @@ loginRouter.post('/', async (req, res) => { return; } if (user.password === hasher.hash(password)) { + + if(config.demoMode){ + trackDemoAccessed(); + } + req.session.currentUser = user.id; userStorage.setLastLoginToNow({ userId: user.id }); res.send(200); diff --git a/lib/services/tracking/Tracker.js b/lib/services/tracking/Tracker.js index 676c674..8b96df3 100644 --- a/lib/services/tracking/Tracker.js +++ b/lib/services/tracking/Tracker.js @@ -3,18 +3,14 @@ import {getJobs} from '../storage/jobStorage.js'; import {config, inDevMode} from '../../utils.js'; +const mixpanelTracker = Mixpanel.init('718670ef1c58c0208256c1e408a3d75e'); + export const track = function () { //only send tracking information if the user allowed to do so. if (config.analyticsEnabled && !inDevMode()) { - const mixpanelTracker = Mixpanel.init('718670ef1c58c0208256c1e408a3d75e'); - const activeProvider = new Set(); const activeAdapter = new Set(); - const platform = process.platform; - const arch = process.arch; - const language = process.env.LANG || 'en'; - const nodeVersion = process.version || 'N/A'; const jobs = getJobs(); @@ -28,15 +24,45 @@ export const track = function () { }); }); - mixpanelTracker.track('fredy_tracking', { + mixpanelTracker.track('fredy_tracking', enrichTrackingObject({ adapter: Array.from(activeAdapter), provider: Array.from(activeProvider), - isDemo: config.demoMode, - platform, - arch, - nodeVersion, - language - }); + })); } } -}; \ No newline at end of file +}; + +/** + * Note, this will only be used when Fredy runs in demo mode + */ +export function trackDemoJobCreated(jobData) { + if (config.analyticsEnabled && !inDevMode() && config.demoMode) { + mixpanelTracker.track('demoJobCreated', enrichTrackingObject(jobData)); + } +} + +/** + * Note, this will only be used when Fredy runs in demo mode + */ +export function trackDemoAccessed() { + if (config.analyticsEnabled && !inDevMode() && config.demoMode) { + mixpanelTracker.track('demoAccessed', enrichTrackingObject({})); + } +} + + +function enrichTrackingObject(trackingObject) { + const platform = process.platform; + const arch = process.arch; + const language = process.env.LANG || 'en'; + const nodeVersion = process.version || 'N/A'; + + return { + ...trackingObject, + isDemo: config.demoMode, + platform, + arch, + nodeVersion, + language + }; +}