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

chore: deps update, tune posthog #16

Merged
merged 3 commits into from
Aug 23, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
- uses: nrwl/nx-set-shas@v4
- run: pnpm exec nx affected --parallel 3 --target lint test build
- run: pnpm exec nx build haqq-website
- run: pnpm exec nx affected --parallel 1 --target e2e-ci
- run: pnpm exec nx affected --parallel 1 --target e2e
6 changes: 6 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const config: StorybookConfig = {
name: '@storybook/nextjs',
options: {},
},

docs: {},

typescript: {
reactDocgen: 'react-docgen-typescript',
},
};

export default config;
Expand Down
2 changes: 2 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const preview: Preview = {
appDirectory: true,
},
},

tags: ['autodocs'],
};

export default preview;
5 changes: 5 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,10 @@
"linter": "eslint"
}
}
},
"targetDefaults": {
"e2e-ci--**/*": {
"dependsOn": ["^build"]
}
}
}
47 changes: 24 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@hookform/resolvers": "3.6.0",
"@intercom/messenger-js-sdk": "0.0.11",
"@react-spring/web": "9.7.3",
"@storybook/theming": "^8.1.10",
"@storybook/theming": "^8.2.9",
"@t3-oss/env-nextjs": "0.10.1",
"@vercel/edge": "1.1.1",
"@vercel/speed-insights": "1.0.12",
Expand All @@ -47,23 +47,24 @@
"zod": "3.23.8"
},
"devDependencies": {
"@nx/cypress": "19.3.1",
"@nx/eslint": "19.3.1",
"@nx/eslint-plugin": "19.3.1",
"@nx/jest": "19.3.1",
"@nx/js": "19.3.1",
"@nx/next": "19.3.1",
"@nx/react": "19.3.1",
"@nx/storybook": "19.3.1",
"@nx/web": "19.3.1",
"@nx/workspace": "19.3.1",
"@storybook/addon-essentials": "8.1.10",
"@storybook/addon-interactions": "8.1.10",
"@storybook/cli": "8.1.10",
"@storybook/core-server": "8.1.10",
"@storybook/nextjs": "8.1.10",
"@storybook/react": "8.1.10",
"@storybook/test": "8.1.10",
"@nx/cypress": "19.6.2",
"@nx/eslint": "19.6.2",
"@nx/eslint-plugin": "19.6.2",
"@nx/jest": "19.6.2",
"@nx/js": "19.6.2",
"@nx/next": "19.6.2",
"@nx/react": "19.6.2",
"@nx/storybook": "19.6.2",
"@nx/web": "19.6.2",
"@nx/workspace": "19.6.2",
"@storybook/addon-essentials": "^8.2.9",
"@storybook/addon-interactions": "^8.2.9",
"@storybook/cli": "^8.2.9",
"@storybook/core-server": "^8.2.9",
"@storybook/manager-api": "^8.2.9",
"@storybook/nextjs": "^8.2.9",
"@storybook/react": "^8.2.9",
"@storybook/test": "^8.2.9",
"@swc-node/register": "1.9.2",
"@swc/core": "1.6.5",
"@swc/helpers": "0.5.11",
Expand All @@ -76,9 +77,9 @@
"@types/node": "20.14.8",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"@typescript-eslint/eslint-plugin": "7.14.1",
"@typescript-eslint/parser": "7.14.1",
"cypress": "13.12.0",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
"cypress": "13.13.3",
"eslint": "8.57.0",
"eslint-config-next": "14.2.4",
"eslint-config-prettier": "9.1.0",
Expand All @@ -90,13 +91,13 @@
"eslint-plugin-react-hooks": "4.6.2",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"nx": "19.3.1",
"nx": "19.6.2",
"postcss": "8.4.38",
"postcss-import": "16.1.0",
"postcss-preset-env": "9.5.14",
"prettier": "3.3.2",
"prettier-plugin-tailwindcss": "0.6.5",
"storybook": "8.1.10",
"storybook": "^8.2.9",
"tailwindcss": "3.4.4",
"ts-jest": "29.1.5",
"ts-node": "10.9.2",
Expand Down
3,141 changes: 1,188 additions & 1,953 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions src/components/identify-wallet-users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ export function IdentifyWalletUsers() {
const isHaqqWallet = Boolean(window.ethereum?.isHaqqWallet);

if (isHaqqWallet) {
const distinctId =
window.__HAQQWALLET__?.POSTHOG_DISTINCT_ID ??
posthog.get_distinct_id();
const walletDistinctId = window.__HAQQWALLET__?.POSTHOG_DISTINCT_ID;
console.log('IdentifyWalletUsers', { walletDistinctId });

posthog.identify(distinctId);
posthog.identify(walletDistinctId ?? posthog.get_distinct_id());
}
}
}, [posthog]);
Expand Down
40 changes: 12 additions & 28 deletions src/components/posthog-page-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,21 @@ export function PostHogPageView() {
const posthog = usePostHog();

useEffect(() => {
const trackPageView = () => {
if (pathname && posthog) {
let url = window.origin + pathname;
if (searchParams.toString()) {
url += `?${searchParams.toString()}`;
}
posthog.capture('$pageview', {
$current_url: url,
$set: {
$browser_language: window.navigator.language,
},
});
}
};

const trackPageLeave = () => {
if (posthog) {
posthog.capture('$pageleave', {});
}
};

// Track pageviews
trackPageView();
if (pathname && posthog) {
let url = window.origin + pathname;

// Add event listener to track page leave
window.addEventListener('beforeunload', trackPageLeave);
if (searchParams.toString()) {
url = url + `?${searchParams.toString()}`;
}

// Cleanup the event listener when the component unmounts
return () => {
window.removeEventListener('beforeunload', trackPageLeave);
};
posthog.capture('$pageview', {
$current_url: url,
$set: {
$browser_language: window.navigator.language,
},
});
}
}, [pathname, searchParams, posthog]);

return null;
Expand Down
5 changes: 4 additions & 1 deletion src/providers/posthog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { PropsWithChildren, useMemo } from 'react';
import posthog from 'posthog-js';
import { PostHogProvider } from 'posthog-js/react';
import { env } from '@/env/client';
import { env } from '../env/client';

export function PHProvider({ children }: PropsWithChildren) {
const postHogInstance = useMemo(() => {
Expand All @@ -13,10 +13,13 @@ export function PHProvider({ children }: PropsWithChildren) {
) {
return undefined;
}

const phInstance = posthog.init(env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: '/api/ingest',
ui_host: env.NEXT_PUBLIC_POSTHOG_HOST,
capture_pageview: false,
capture_pageleave: true,
persistence: 'localStorage+cookie',
});

if (!phInstance) {
Expand Down