-
-
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
1 parent
214e714
commit 3b8279c
Showing
3 changed files
with
75 additions
and
47 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,75 +1,90 @@ | ||
import Mixpanel from 'mixpanel'; | ||
import { getJobs } from '../storage/jobStorage.js'; | ||
import { getUniqueId } from './uniqueId.js'; | ||
import { config, inDevMode } from '../../utils.js'; | ||
import {getJobs} from '../storage/jobStorage.js'; | ||
import {getUniqueId} from './uniqueId.js'; | ||
import {config, inDevMode} from '../../utils.js'; | ||
import os from 'os'; | ||
import {readFileSync} from 'fs'; | ||
import {packageUp} from 'package-up'; | ||
|
||
const mixpanelTracker = Mixpanel.init('718670ef1c58c0208256c1e408a3d75e'); | ||
|
||
const distinct_id = getUniqueId() || 'N/A'; | ||
const version = await getPackageVersion(); | ||
|
||
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(); | ||
//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 operating_system = os.platform(); | ||
const os_version = os.release(); | ||
const arch = process.arch; | ||
const language = process.env.LANG || 'en'; | ||
const nodeVersion = process.version || 'N/A'; | ||
const operating_system = os.platform(); | ||
const os_version = os.release(); | ||
const arch = process.arch; | ||
const language = process.env.LANG || 'en'; | ||
const nodeVersion = process.version || 'N/A'; | ||
|
||
return { | ||
...trackingObject, | ||
isDemo: config.demoMode, | ||
operating_system, | ||
os_version, | ||
arch, | ||
nodeVersion, | ||
language, | ||
distinct_id, | ||
}; | ||
return { | ||
...trackingObject, | ||
isDemo: config.demoMode, | ||
operating_system, | ||
os_version, | ||
arch, | ||
nodeVersion, | ||
language, | ||
distinct_id, | ||
fredy_version: version | ||
}; | ||
} | ||
|
||
async function getPackageVersion() { | ||
try { | ||
const packagePath = await packageUp(); | ||
const packageJson = readFileSync(packagePath, 'utf8'); | ||
const json = JSON.parse(packageJson); | ||
return json.version; | ||
} catch (error) { | ||
console.error('Error reading version from package.json', error); | ||
} | ||
return 'N/A'; | ||
} |
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