Skip to content

Commit

Permalink
adding tracking data for demo
Browse files Browse the repository at this point in the history
  • Loading branch information
orangecoding committed Nov 21, 2024
1 parent b15e064 commit a5d8040
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
6 changes: 6 additions & 0 deletions lib/api/routes/jobRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) => {
Expand Down
7 changes: 7 additions & 0 deletions lib/api/routes/loginRoute.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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);
Expand Down
54 changes: 40 additions & 14 deletions lib/services/tracking/Tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
});
}));
}
}
};
};

/**
* 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
};
}

0 comments on commit a5d8040

Please sign in to comment.