From ee4e60a7de9ceda6eb2ab6de5f66b2232ac52de8 Mon Sep 17 00:00:00 2001 From: garikbesson Date: Thu, 26 Sep 2024 19:23:09 +0200 Subject: [PATCH] migrated tracking to posthog --- package.json | 5 +- src/messages.ts | 10 +-- src/tracking.ts | 49 ++++++++---- src/types.ts | 17 +++- src/user-input.ts | 4 +- .../contracts/{ts => javascript}/README.md | 0 .../contracts/{ts => javascript}/package.json | 0 .../sandbox-test/main.ava.js | 0 .../{ts => javascript}/src/contract.ts | 0 .../{ts => javascript}/tsconfig.json | 0 .../contracts/{ts => javascript}/yarn.lock | 0 templates/contracts/{rs => rust}/Cargo.lock | 0 templates/contracts/{rs => rust}/Cargo.toml | 0 templates/contracts/{rs => rust}/README.md | 0 .../{rs => rust}/rust-toolchain.toml | 0 templates/contracts/{rs => rust}/src/lib.rs | 0 .../{rs => rust}/tests/test_basics.rs | 0 yarn.lock | 77 +++++++++++++------ 18 files changed, 114 insertions(+), 48 deletions(-) rename templates/contracts/{ts => javascript}/README.md (100%) rename templates/contracts/{ts => javascript}/package.json (100%) rename templates/contracts/{ts => javascript}/sandbox-test/main.ava.js (100%) rename templates/contracts/{ts => javascript}/src/contract.ts (100%) rename templates/contracts/{ts => javascript}/tsconfig.json (100%) rename templates/contracts/{ts => javascript}/yarn.lock (100%) rename templates/contracts/{rs => rust}/Cargo.lock (100%) rename templates/contracts/{rs => rust}/Cargo.toml (100%) rename templates/contracts/{rs => rust}/README.md (100%) rename templates/contracts/{rs => rust}/rust-toolchain.toml (100%) rename templates/contracts/{rs => rust}/src/lib.rs (100%) rename templates/contracts/{rs => rust}/tests/test_basics.rs (100%) diff --git a/package.json b/package.json index e9e750fd..53c192cf 100644 --- a/package.json +++ b/package.json @@ -27,16 +27,15 @@ "chalk": "^4.1.2", "commander": "^11.0.0", "cross-spawn": "^7.0.3", - "mixpanel": "^0.18.0", "ncp": "^2.0.0", "prompts": "^2.4.2", "semver": "^7.5.3" }, "devDependencies": { - "@babel/eslint-parser": "^7.22.5", "@babel/core": "^7.23.2", - "@babel/plugin-transform-react-jsx": "^7.22.15", + "@babel/eslint-parser": "^7.22.5", "@babel/plugin-syntax-flow": "^7.22.5", + "@babel/plugin-transform-react-jsx": "^7.22.15", "@commitlint/cli": "^17.6.6", "@commitlint/config-conventional": "^17.6.6", "@release-it/conventional-changelog": "^5.1.1", diff --git a/src/messages.ts b/src/messages.ts index 4865c7df..c09c3a7f 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -27,7 +27,7 @@ export const successContractToText = (contract: Contract) => contract === 'none' ? '' : chalk`a smart contract in {bold ${ - contract === 'rs' ? 'Rust' : 'Typescript' + contract === 'rust' ? 'Rust' : 'Typescript' }}`; const frontendTemplates: FrontendMessage = { @@ -52,7 +52,7 @@ export const setupSuccess = ( contract )}${successFrontendToText(frontend)}. ${ - contract === 'rs' + contract === 'rust' ? chalk`🦀 If you are new to Rust please visit {bold {green https://www.rust-lang.org }}\n` : '' } @@ -74,20 +74,20 @@ export const contractInstructions = ( - {inverse Navigate to your project}: {blue cd {bold ${projectName}}} ${ - contract === 'ts' && !install + contract === 'javascript' && !install ? chalk` - {inverse Install all dependencies} {blue npm {bold install}}` : 'Then:' } - {inverse Build your contract}: ${ - contract === 'ts' + contract === 'javascript' ? chalk`{blue npm {bold run build}}` : chalk`{blue {bold cargo near build}}` } - {inverse Test your contract} in the Sandbox: ${ - contract === 'ts' + contract === 'javascript' ? chalk`{blue npm {bold run test}}` : chalk`{blue {bold cargo test}}` } diff --git a/src/tracking.ts b/src/tracking.ts index b93a5f10..b4d96ce2 100644 --- a/src/tracking.ts +++ b/src/tracking.ts @@ -1,10 +1,9 @@ -import {Contract, Frontend} from './types'; import chalk from 'chalk'; -import mixpanel from 'mixpanel'; +import {Contract, Frontend, TrackingEventPayload} from './types'; -const MIXPANEL_TOKEN = '24177ef1ec09ffea5cb6f68909c66a61'; +const POSTHOG_API_KEY = 'phc_bMxqEAiInwlq3FMyZvuFPZ8qdYuVwh9L5YfqRpeFk0I'; +const POSTHOG_API_URL = 'https://eu.i.posthog.com/capture'; -const tracker = mixpanel.init(MIXPANEL_TOKEN); export const trackingMessage = chalk.italic('Near collects anonymous information on the commands used. No personal information that could identify you is shared'); @@ -12,18 +11,42 @@ export const trackingMessage = chalk.italic('Near collects anonymous information export const trackUsage = async (frontend: Frontend, contract: Contract) => { // prevents logging from CI if (process.env.NEAR_ENV === 'ci' || process.env.NODE_ENV === 'ci') { - console.log('Mixpanel logging is skipped in CI env'); + console.log('PostHog logging is skipped in CI env'); return; } - try { - const mixPanelProperties = { - frontend, - contract, + + const payload: TrackingEventPayload = { + distinct_id: 'create-near-app', + event: 'error', + properties: { + engine: process.versions.node, os: process.platform, - nodeVersion: process.versions.node, - timestamp: new Date().toString() - }; - tracker.track('CNA', mixPanelProperties); + }, + timestamp: new Date(), + }; + + if (contract !== 'none') { + payload.event = 'contract'; + payload.properties.language = contract; + } + + if (frontend !== 'none') { + payload.event = 'frontend'; + payload.properties.framework = frontend; + } + + const headers = new Headers(); + headers.append('Content-Type', 'application/json'); + + try { + await fetch(POSTHOG_API_URL, { + method: 'POST', + body: JSON.stringify({ + api_key: POSTHOG_API_KEY, + ...payload, + }), + headers, + }); } catch (e) { console.error( 'Warning: problem while sending tracking data. Error: ', diff --git a/src/types.ts b/src/types.ts index 51fda33e..216ec261 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,5 @@ -export type Contract = 'ts' | 'rs' | 'none'; -export const CONTRACTS: Contract[] = ['ts', 'rs', 'none']; +export type Contract = 'javascript' | 'rust' | 'none'; +export const CONTRACTS: Contract[] = ['javascript', 'rust', 'none']; export type Frontend = 'next-app' | 'next-page' | 'none'; export const FRONTENDS: Frontend[] = ['next-app' , 'next-page', 'none']; @@ -31,4 +31,17 @@ export type CreateGatewayParams = { export type FrontendMessage = { [key in Exclude]: string; +}; + +export type TrackingEventName = 'contract' | 'frontend' | 'error'; +export type TrackingEventPayload = { + distinct_id: string, + event: TrackingEventName, + properties: { + engine: string, + os: string, + language?: string, + framework?: string + }, + timestamp: Date, }; \ No newline at end of file diff --git a/src/user-input.ts b/src/user-input.ts index 39e9136b..758c749e 100644 --- a/src/user-input.ts +++ b/src/user-input.ts @@ -39,8 +39,8 @@ const appChoices: Choices = [ }, ]; const contractChoices: Choices = [ - { title: 'JS/TS Contract', description: 'A Near contract written in javascript/typescript', value: 'ts' }, - { title: 'Rust Contract', description: 'A Near contract written in Rust', value: 'rs' }, + { title: 'JS/TS Contract', description: 'A Near contract written in javascript/typescript', value: 'javascript' }, + { title: 'Rust Contract', description: 'A Near contract written in Rust', value: 'rust' }, ]; const frontendChoices: Choices = [ diff --git a/templates/contracts/ts/README.md b/templates/contracts/javascript/README.md similarity index 100% rename from templates/contracts/ts/README.md rename to templates/contracts/javascript/README.md diff --git a/templates/contracts/ts/package.json b/templates/contracts/javascript/package.json similarity index 100% rename from templates/contracts/ts/package.json rename to templates/contracts/javascript/package.json diff --git a/templates/contracts/ts/sandbox-test/main.ava.js b/templates/contracts/javascript/sandbox-test/main.ava.js similarity index 100% rename from templates/contracts/ts/sandbox-test/main.ava.js rename to templates/contracts/javascript/sandbox-test/main.ava.js diff --git a/templates/contracts/ts/src/contract.ts b/templates/contracts/javascript/src/contract.ts similarity index 100% rename from templates/contracts/ts/src/contract.ts rename to templates/contracts/javascript/src/contract.ts diff --git a/templates/contracts/ts/tsconfig.json b/templates/contracts/javascript/tsconfig.json similarity index 100% rename from templates/contracts/ts/tsconfig.json rename to templates/contracts/javascript/tsconfig.json diff --git a/templates/contracts/ts/yarn.lock b/templates/contracts/javascript/yarn.lock similarity index 100% rename from templates/contracts/ts/yarn.lock rename to templates/contracts/javascript/yarn.lock diff --git a/templates/contracts/rs/Cargo.lock b/templates/contracts/rust/Cargo.lock similarity index 100% rename from templates/contracts/rs/Cargo.lock rename to templates/contracts/rust/Cargo.lock diff --git a/templates/contracts/rs/Cargo.toml b/templates/contracts/rust/Cargo.toml similarity index 100% rename from templates/contracts/rs/Cargo.toml rename to templates/contracts/rust/Cargo.toml diff --git a/templates/contracts/rs/README.md b/templates/contracts/rust/README.md similarity index 100% rename from templates/contracts/rs/README.md rename to templates/contracts/rust/README.md diff --git a/templates/contracts/rs/rust-toolchain.toml b/templates/contracts/rust/rust-toolchain.toml similarity index 100% rename from templates/contracts/rs/rust-toolchain.toml rename to templates/contracts/rust/rust-toolchain.toml diff --git a/templates/contracts/rs/src/lib.rs b/templates/contracts/rust/src/lib.rs similarity index 100% rename from templates/contracts/rs/src/lib.rs rename to templates/contracts/rust/src/lib.rs diff --git a/templates/contracts/rs/tests/test_basics.rs b/templates/contracts/rust/tests/test_basics.rs similarity index 100% rename from templates/contracts/rs/tests/test_basics.rs rename to templates/contracts/rust/tests/test_basics.rs diff --git a/yarn.lock b/yarn.lock index 4a6693af..d71e1226 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2112,13 +2112,6 @@ add-stream@^1.0.0: resolved "https://registry.npmjs.org/add-stream/-/add-stream-1.0.0.tgz" integrity sha512-qQLMr+8o0WC4FZGQTcJiKBVC59JylcPSrTtk6usvmIDFUOCKegapy1VHQwRbFMOFyb/inzUVqHs+eMYKDM1YeQ== -agent-base@6: - version "6.0.2" - resolved "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz" - integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ== - dependencies: - debug "4" - agent-base@^7.0.2, agent-base@^7.1.0, agent-base@^7.1.1: version "7.1.1" resolved "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz" @@ -2371,6 +2364,11 @@ async-retry@1.3.3: dependencies: retry "0.13.1" +asynckit@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" + integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q== + available-typed-arrays@^1.0.7: version "1.0.7" resolved "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz" @@ -2383,6 +2381,15 @@ axe-core@=4.7.0: resolved "https://registry.npmjs.org/axe-core/-/axe-core-4.7.0.tgz" integrity sha512-M0JtH+hlOL5pLQwHOLNYZaXuhqmvS8oExsqB1SBYgA4Dk7u/xx+YdGHXaK5pyUfed5mYXdlYiphWq3G8cRi5JQ== +axios@^1.7.4: + version "1.7.7" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.7.tgz#2f554296f9892a72ac8d8e4c5b79c14a91d0a47f" + integrity sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q== + dependencies: + follow-redirects "^1.15.6" + form-data "^4.0.0" + proxy-from-env "^1.1.0" + axobject-query@^3.2.1: version "3.2.1" resolved "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz" @@ -2837,6 +2844,13 @@ color-name@~1.1.4: resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== +combined-stream@^1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" + integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== + dependencies: + delayed-stream "~1.0.0" + commander@^11.0.0: version "11.1.0" resolved "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz" @@ -3327,6 +3341,11 @@ degenerator@^4.0.4: esprima "^4.0.1" vm2 "^3.9.19" +delayed-stream@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" + integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ== + deprecation@^2.0.0: version "2.3.1" resolved "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz" @@ -4019,6 +4038,11 @@ flatted@^3.2.9: resolved "https://registry.npmjs.org/flatted/-/flatted-3.3.1.tgz" integrity sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw== +follow-redirects@^1.15.6: + version "1.15.9" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1" + integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ== + for-each@^0.3.3: version "0.3.3" resolved "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz" @@ -4031,6 +4055,15 @@ form-data-encoder@^2.1.2: resolved "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-2.1.4.tgz" integrity sha512-yDYSgNMraqvnxiEXO4hi88+YZxaHC6QKzb5N84iRCTDeRO7ZALpir/lVmf/uXUhnwUr2O4HU8s/n6x+yNjQkHw== +form-data@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" + integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + formdata-polyfill@^4.0.10: version "4.0.10" resolved "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz" @@ -4413,14 +4446,6 @@ http2-wrapper@^2.1.10: quick-lru "^5.1.1" resolve-alpn "^1.2.0" -https-proxy-agent@5.0.0: - version "5.0.0" - resolved "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz" - integrity sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA== - dependencies: - agent-base "6" - debug "4" - https-proxy-agent@^7.0.0: version "7.0.4" resolved "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.4.tgz" @@ -5741,7 +5766,7 @@ mime-db@1.52.0: resolved "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz" integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== -mime-types@2.1.35: +mime-types@2.1.35, mime-types@^2.1.12: version "2.1.35" resolved "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz" integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw== @@ -5794,13 +5819,6 @@ minimist@^1.2.0, minimist@^1.2.5, minimist@^1.2.6: resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz" integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== -mixpanel@^0.18.0: - version "0.18.0" - resolved "https://registry.npmjs.org/mixpanel/-/mixpanel-0.18.0.tgz" - integrity sha512-VyUoiLB/S/7abYYHGD5x0LijeuJCUabG8Hb+FvYU3Y99xHf1Qh+s4/pH9lt50fRitAHncWbU1FE01EknUfVVjQ== - dependencies: - https-proxy-agent "5.0.0" - modify-values@^1.0.0: version "1.0.1" resolved "https://registry.npmjs.org/modify-values/-/modify-values-1.0.1.tgz" @@ -6306,6 +6324,14 @@ possible-typed-array-names@^1.0.0: resolved "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz" integrity sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q== +posthog-node@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/posthog-node/-/posthog-node-4.2.0.tgz#b7213200e12535ce60c9aaa26e8bd0470852ba19" + integrity sha512-hgyCYMyzMvuF3qWMw6JvS8gT55v7Mtp5wKWcnDrw+nu39D0Tk9BXD7I0LOBp0lGlHEPaXCEVYUtviNKrhMALGA== + dependencies: + axios "^1.7.4" + rusha "^0.8.14" + prelude-ls@^1.2.1: version "1.2.1" resolved "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz" @@ -6752,6 +6778,11 @@ run-parallel@^1.1.9: dependencies: queue-microtask "^1.2.2" +rusha@^0.8.14: + version "0.8.14" + resolved "https://registry.yarnpkg.com/rusha/-/rusha-0.8.14.tgz#a977d0de9428406138b7bb90d3de5dcd024e2f68" + integrity sha512-cLgakCUf6PedEu15t8kbsjnwIFFR2D4RfL+W3iWFJ4iac7z4B0ZI8fxy4R3J956kAI68HclCFGL8MPoUVC3qVA== + rxjs@^7.8.1: version "7.8.1" resolved "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz"