-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: migrate from mixpanel to segment #1005
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
const MIXPANEL_TOKEN = 'e98aa9d6d259d9d78f20cb05cb54f5cb'; | ||
const SEGMENT_WRITE_KEY = 'ePJM5UVxZGUxLP9dH2wGDvUE7hC2MbTX'; | ||
|
||
const Analytics = require('analytics-node'); | ||
const chalk = require('chalk'); // colorize output | ||
const crypto = require('crypto'); | ||
const mixpanel = require('mixpanel').init(MIXPANEL_TOKEN); | ||
const near_cli_version = require('../package.json').version; | ||
const settings = require('./settings'); | ||
const { askYesNoQuestion } = require('./readline'); | ||
const uuid = require('uuid'); | ||
|
||
const analytics = new Analytics(SEGMENT_WRITE_KEY); | ||
|
||
const isGitPod = () => { | ||
return !!process.env.GITPOD_WORKSPACE_URL; | ||
}; | ||
|
@@ -39,7 +41,7 @@ const shouldTrackID = (shellSettings) => { | |
return !!shellSettings.trackingAccountID; | ||
}; | ||
|
||
const getMixpanelID = (shellSettings) => isGitPod() ? getGitPodUserHash() : shellSettings.trackingSessionId; | ||
const getSegmentID = (shellSettings) => isGitPod() ? getGitPodUserHash() : shellSettings.trackingSessionId; | ||
|
||
const track = async (eventType, eventProperties, options) => { | ||
try { | ||
|
@@ -48,19 +50,20 @@ const track = async (eventType, eventProperties, options) => { | |
return; | ||
} | ||
|
||
if (shouldTrackID(shellSettings)) { | ||
if (options.accountId && shouldTrackID(shellSettings)) { | ||
const accountID = options.accountId; | ||
const id = getMixpanelID(shellSettings); | ||
await Promise.all([ | ||
mixpanel.alias(accountID, id), | ||
mixpanel.people.set(id, { account_id: accountID }) | ||
]); | ||
const id = getSegmentID(shellSettings); | ||
analytics.alias({ previousId: accountID, userId: id }); | ||
analytics.identify({ | ||
userId: id, | ||
traits: { account_id: accountID } | ||
}); | ||
} | ||
|
||
const user_country = await getUserCountry(); | ||
|
||
const mixPanelProperties = { | ||
distinct_id: getMixpanelID(shellSettings), | ||
const segmentProperties = { | ||
distinct_id: getSegmentID(shellSettings), | ||
near_cli_version, | ||
user_country, | ||
os: process.platform, | ||
|
@@ -70,13 +73,20 @@ const track = async (eventType, eventProperties, options) => { | |
is_gitpod: isGitPod(), | ||
timestamp: new Date() | ||
}; | ||
Object.assign(mixPanelProperties, eventProperties); | ||
await Promise.all([mixpanel.track(eventType, mixPanelProperties), | ||
mixpanel.people.set(mixPanelProperties.distinct_id, { | ||
Object.assign(segmentProperties, eventProperties); | ||
analytics.track({ | ||
userId: segmentProperties.distinct_id, | ||
event: eventType, | ||
properties: segmentProperties | ||
}); | ||
analytics.identify({ | ||
userId: segmentProperties.distinct_id, | ||
traits: { | ||
deployed_contracts: 0, | ||
network_id: options.networkId, | ||
node_url: options.nodeUrl, | ||
})]); | ||
node_url: options.nodeUrl | ||
} | ||
}); | ||
} catch (e) { | ||
console.warn( | ||
'Warning: problem while sending developer event tracking data. This is not critical. Error: ', | ||
|
@@ -117,8 +127,8 @@ const askForConsentIfNeeded = async (options) => { | |
|
||
const trackDeployedContract = async () => { | ||
const shellSettings = settings.getShellSettings(); | ||
const id = getMixpanelID(shellSettings); | ||
await mixpanel.people.increment(id, 'deployed_contracts'); | ||
const id = getSegmentID(shellSettings); | ||
// TODO: find a way to increment a Segment analytic property | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like there is no persistent analytic properties in segment (or at least a direct replacement). Not sure how much we care about the total amount of deployed contracts as a stored number vs aggregating them by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @itegulov are you planning to work on it now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have spent some time looking for alternatives to no avail, so I think it would make sense to hear @TiffanyGYJ's opinion first before spending even more time on this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Curious to hear your reasoning. Wouldn't aggregating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deployed events might happen multiple times with different contracts, so that might not be an accurate estimate on how many unique contracts each dev deployed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Looking through the code, the current logic does not track unique deployed contracts either, just the number of times when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the total number of deploys per week is the most important metric since we are tracking developer activity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree with this, but a per-user counter does not really help with that, no? Increments do not have a timestamp, so you would have to track how much a counter has changed each week which kind of beats its point. I think we can deduce all that information just from tracking events (by writing a small custom event consumer or building something in Segment itself, not sure if it provides any processing logic).
👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree! |
||
}; | ||
|
||
module.exports = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@itegulov is this change intended?
I think users can avoid tracking even if they do not pass any
accountId
in command.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes,
previousId
is a non-optional field in Segment, so it was throwing runtime errors without this check