Skip to content
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

Tracking migration #2159

Merged
merged 6 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/test-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ jobs:
- name: Create Frontend No Components
run: npm run start -- hello-near --frontend next-page
- name: Install
run: cd hello-near && npm install
- name: Install
run: cd hello-components && npm install
run: cd hello-near && npm install
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
50 changes: 37 additions & 13 deletions src/tracking.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
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_95PGQnbyatmj2TBRPWYfhbHfqB6wgZj5QRL8WY9gW20';
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');

// TODO: track different failures & install usage
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: ',
Expand Down
13 changes: 13 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,17 @@ export type CreateGatewayParams = {

export type FrontendMessage = {
[key in Exclude<Frontend, 'none'>]: 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,
};
8 changes: 4 additions & 4 deletions test/__snapshots__/make.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1054,11 +1054,11 @@ import { useEffect, useState } from 'react';
import '@/app/globals.css';
import { NearContext } from '@/context';
import { Navigation } from '@/components/navigation';
import { NetworkId, HelloNearContract } from '@/config';
import { NetworkId } from '@/config';

import { Wallet } from '@/wallets/near';

const wallet = new Wallet({ networkId: NetworkId, createAccessKeyFor: HelloNearContract });
const wallet = new Wallet({ networkId: NetworkId });

// Layout Component
export default function RootLayout({ children }) {
Expand Down Expand Up @@ -1773,9 +1773,9 @@ import { NearContext } from '@/context';
import { Navigation } from '@/components/navigation';

import { Wallet } from '@/wallets/near';
import { NetworkId, HelloNearContract } from '@/config';
import { NetworkId } from '@/config';

const wallet = new Wallet({ createAccessKeyFor: HelloNearContract, networkId: NetworkId });
const wallet = new Wallet({ networkId: NetworkId });

export default function MyApp({ Component, pageProps }) {
const [signedAccountId, setSignedAccountId] = useState('');
Expand Down
77 changes: 54 additions & 23 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -2371,6 +2364,11 @@ [email protected]:
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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -4413,14 +4446,6 @@ http2-wrapper@^2.1.10:
quick-lru "^5.1.1"
resolve-alpn "^1.2.0"

[email protected]:
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"
Expand Down Expand Up @@ -5741,7 +5766,7 @@ [email protected]:
resolved "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz"
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==

[email protected]:
[email protected], 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==
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading