From 9fcc9cb530347d6a4b1219eeac22a944e11e3d62 Mon Sep 17 00:00:00 2001 From: Yifang Ma Date: Thu, 8 Oct 2020 17:15:24 -0700 Subject: [PATCH] set up property --- index.js | 7 +++++++ utils/eventtracking.js | 27 ++++++++++++++++----------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 90652ef5..de5bb18c 100644 --- a/index.js +++ b/index.js @@ -36,12 +36,15 @@ exports.deploy = async function (options) { const near = await connect(options); const account = await near.account(options.accountId); + let prevState = await account.state(); + let prevCodeHash = prevState.code_hash; // Deploy with init function and args const txs = [transactions.deployContract(fs.readFileSync(options.wasmFile))]; if (options.initFunction) { if (!options.initArgs) { console.error('Must add initialization arguments.\nExample: near deploy --accountId near.testnet --initFunction "new" --initArgs \'{"key": "value"}\''); + await eventtracking.track(eventtracking.EVENT_ID_DEPLOY_END, { success: false }, options); process.exit(1); } txs.push(transactions.functionCall( @@ -54,6 +57,10 @@ exports.deploy = async function (options) { const result = await account.signAndSendTransaction(options.accountId, txs); inspectResponse.prettyPrintResponse(result, options); + let state = await account.state(); + let codeHash = state.code_hash; + await eventtracking.track(eventtracking.EVENT_ID_DEPLOY_END, { success: true, code_hash: codeHash, is_same_contract: prevCodeHash === codeHash, contract_id: options.accountId }, options); + eventtracking.trackDeployedContract(); console.log(`Done deploying ${options.initFunction ? 'and initializing' : 'to'} ${options.accountId}`); }; diff --git a/utils/eventtracking.js b/utils/eventtracking.js index f99ccdec..a233e947 100644 --- a/utils/eventtracking.js +++ b/utils/eventtracking.js @@ -56,9 +56,17 @@ const track = async (eventType, eventProperties, options) => { node_url: options.nodeUrl, wallet_url: options.walletUrl, is_gitpod: isGitPod(), + timestamp: new Date() }; Object.assign(mixPanelProperties, eventProperties); - await mixpanel.track(eventType, mixPanelProperties); + await Promise.all([mixpanel.track(eventType, mixPanelProperties), + mixpanel.people.set_once({ + distinct_id: isGitPod() + ? getGitPodUserHash() + : shellSettings[TRACKING_SESSION_ID_KEY], + network_id: options.networkId, + node_url: options.nodeUrl, + })]); } catch (e) { console.log( 'Warning: problem while sending developer event tracking data. This is not critical. Error: ', @@ -114,27 +122,24 @@ const askForConsentIfNeeded = async (options) => { : undefined; settings.saveShellSettings(shellSettings); if (shellSettings[TRACKING_ENABLED_KEY]) { - await Promise.all([ - track(module.exports.EVENT_ID_TRACKING_OPT_IN, {}, options), - mixpanel.people.set({ - distinct_id: isGitPod() - ? getGitPodUserHash() - : shellSettings[TRACKING_SESSION_ID_KEY], - network_id: options.networkId, - node_url: options.nodeUrl, - }), - ]); + await track(module.exports.EVENT_ID_TRACKING_OPT_IN, {}, options); } } }; +const trackDeployedContract = async () => { + await mixpanel.people.increment({deployed_contracts: 1}); +}; + module.exports = { track, askForConsentIfNeeded, + trackDeployedContract, // Some of the event ids are auto-generated runtime with the naming convention event_id_shell_{command}_start EVENT_ID_CREATE_ACCOUNT_END: 'event_id_shell_create-account_end', EVENT_ID_TRACKING_OPT_IN: 'event_id_tracking_opt_in', EVENT_ID_LOGIN_END: 'event_id_shell_login_end', + EVENT_ID_DEPLOY_END: 'event_id_shell_deploy_end', EVENT_ID_ERROR: 'event_id_shell_error', };