-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christian Kellner
authored and
Christian Kellner
committed
Dec 3, 2024
1 parent
13b8701
commit f8f911a
Showing
4 changed files
with
138 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,72 @@ | ||
import Mixpanel from 'mixpanel'; | ||
import {getJobs} from '../storage/jobStorage.js'; | ||
|
||
import {config, inDevMode} from '../../utils.js'; | ||
import { getJobs } from '../storage/jobStorage.js'; | ||
import { getUniqueId } from './uniqueId.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 distinct_id = getUniqueId() || 'N/A'; | ||
|
||
const activeProvider = new Set(); | ||
const activeAdapter = new Set(); | ||
export const track = function () { | ||
//only send tracking information if the user allowed to do so. | ||
if (config.analyticsEnabled && !inDevMode()) { | ||
const activeProvider = new Set(); | ||
const activeAdapter = new Set(); | ||
|
||
const jobs = getJobs(); | ||
const jobs = getJobs(); | ||
|
||
if (jobs != null && jobs.length > 0) { | ||
jobs.forEach(job => { | ||
job.provider.forEach(provider => { | ||
activeProvider.add(provider.id); | ||
}); | ||
job.notificationAdapter.forEach(adapter => { | ||
activeAdapter.add(adapter.id); | ||
}); | ||
}); | ||
if (jobs != null && jobs.length > 0) { | ||
jobs.forEach((job) => { | ||
job.provider.forEach((provider) => { | ||
activeProvider.add(provider.id); | ||
}); | ||
job.notificationAdapter.forEach((adapter) => { | ||
activeAdapter.add(adapter.id); | ||
}); | ||
}); | ||
|
||
mixpanelTracker.track('fredy_tracking', enrichTrackingObject({ | ||
adapter: Array.from(activeAdapter), | ||
provider: Array.from(activeProvider), | ||
})); | ||
} | ||
mixpanelTracker.track( | ||
'fredy_tracking', | ||
enrichTrackingObject({ | ||
adapter: Array.from(activeAdapter), | ||
provider: Array.from(activeProvider), | ||
}), | ||
); | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* 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)); | ||
} | ||
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({})); | ||
} | ||
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'; | ||
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 | ||
}; | ||
return { | ||
...trackingObject, | ||
isDemo: config.demoMode, | ||
platform, | ||
arch, | ||
nodeVersion, | ||
language, | ||
distinct_id, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { hostname, arch, cpus, platform } from 'os'; | ||
import { createHash } from 'crypto'; | ||
|
||
/** | ||
* Don't worry, we are not evil ;) We however need a unique id per running instance | ||
* @returns {string} | ||
*/ | ||
export const getUniqueId = () => { | ||
const systemInfo = { | ||
hostname: hostname(), | ||
architecture: arch(), | ||
cpuCount: cpus().length, | ||
platform: platform(), | ||
}; | ||
|
||
const baseData = JSON.stringify(systemInfo); | ||
|
||
return createHash('sha256').update(baseData).digest('hex'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters