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

feat: integrate PostHog #70

Merged
merged 4 commits into from
Apr 18, 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/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ body:
- type: markdown
attributes:
value: |
By submitting this bug report, I agree to follow the [code of conduct](https://inventory.fix.security/code-of-conduct).
By submitting this bug report, I agree to follow the [code of conduct](https://fix.security/code-of-conduct).
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/enhancement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ body:
- type: markdown
attributes:
value: |
By submitting this feature request, I agree to follow the [code of conduct](https://inventory.fix.security/code-of-conduct).
By submitting this feature request, I agree to follow the [code of conduct](https://fix.security/code-of-conduct).
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@

# Code of Conduct

By submitting this pull request, I agree to follow the [code of conduct](https://inventory.fix.security/code-of-conduct).
By submitting this pull request, I agree to follow the [code of conduct](https://fix.security/code-of-conduct).
10 changes: 8 additions & 2 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import versions from './versions.json';

const isDev = process.env.NODE_ENV === 'development';
const isBuildFast = isDev || !!process.env.BUILD_FAST;
const isProd =
!isDev && !!process.env.NETLIFY && process.env.CONTEXT !== 'deploy-preview';
const isNetlify = !!process.env.NETLIFY;
const isProd = isNetlify && process.env.CONTEXT === 'production';

const config: Config = {
title: 'Fix Inventory by Some Engineering Inc.',
Expand All @@ -27,6 +27,12 @@ const config: Config = {
favicon: 'img/favicon.ico',
trailingSlash: false,
noIndex: !isProd,
customFields: {
isDev,
isNetlify,
isProd,
posthogProjectApiKey: process.env.POSTHOG_PROJECT_API_KEY,
},
stylesheets: [
'https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,200..800;1,200..800&display=swap',
],
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
"docusaurus-plugin-openapi-docs": "3.0.0-beta.10",
"docusaurus-theme-openapi-docs": "3.0.0-beta.10",
"github-slugger": "2.0.0",
"js-cookie": "3.0.5",
"lodash": "4.17.21",
"netlify-plugin-cache": "1.0.3",
"posthog-js": "1.128.1",
"prism-react-renderer": "2.3.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand All @@ -58,6 +60,7 @@
"@docusaurus/module-type-aliases": "3.2.1",
"@docusaurus/tsconfig": "3.2.1",
"@docusaurus/types": "3.2.1",
"@types/js-cookie": "3.0.6",
"@typescript-eslint/eslint-plugin": "7.7.0",
"@typescript-eslint/parser": "7.7.0",
"commitizen": "4.3.0",
Expand Down
107 changes: 107 additions & 0 deletions src/components/CookieConsent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import Link from '@docusaurus/Link';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import Cookies from 'js-cookie';
import { usePostHog } from 'posthog-js/react';
import { useEffect, useState } from 'react';

export default function CookieConsent() {
const {
siteConfig: {
customFields: { isDev, isProd, posthogProjectApiKey },
},
} = useDocusaurusContext();
const posthog = usePostHog();
const [showConsent, setShowConsent] = useState(false);

useEffect(() => {
if (posthog.has_opted_in_capturing()) {
setShowConsent(false);
} else {
setShowConsent(Cookies.get('cookie_consent') !== 'false');
}

if (
posthog.has_opted_in_capturing() ||
Cookies.get('cookie_consent') !== 'false'
) {
Cookies.remove('cookie_consent', {
domain: isProd ? '.fix.security' : undefined,
secure: !isDev,
});
}
}, [isDev, isProd, posthog]);

if (!posthogProjectApiKey || !showConsent) {
return null;
}

return (
<div
style={{
pointerEvents: 'none',
position: 'fixed',
left: '0px',
right: '0px',
bottom: '0px',
padding: '0 1.5rem 1.5rem',
}}
>
<div
style={{
pointerEvents: 'auto',
marginLeft: 'auto',
maxWidth: '36rem',
borderRadius: '0.75rem',
backgroundColor: 'white',
padding: '1.5rem',
boxShadow: '0 0 0 1px var(--ifm-color-secondary)',
}}
>
<p
style={{
fontSize: '1rem',
lineHeight: '1.5rem',
}}
>
We use cookies and other tracking technologies to analyze site usage
and assist in marketing efforts. For details, see our{' '}
<Link href="https://fix.security/cookie-policy">cookie policy</Link>.
</p>
<div
style={{
marginTop: '1rem',
display: 'flex',
alignItems: 'center',
columnGap: '1.25rem',
}}
>
<button
className="button button--primary"
onClick={(e) => {
e.preventDefault();
setShowConsent(false);
posthog.opt_in_capturing({ enable_persistence: true });
}}
>
Accept
</button>
<button
className="button button--primary button--outline"
onClick={(e) => {
e.preventDefault();
setShowConsent(false);
Cookies.set('cookie_consent', 'false', {
expires: isProd ? 30 : undefined,
domain: isProd ? '.fix.security' : undefined,
secure: !isDev,
});
posthog.opt_out_capturing();
}}
>
Reject
</button>
</div>
</div>
</div>
);
}
78 changes: 0 additions & 78 deletions src/components/PlausibleToggle.tsx

This file was deleted.

26 changes: 26 additions & 0 deletions src/components/PosthogPageView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useLocation } from '@docusaurus/router';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import { usePostHog } from 'posthog-js/react';
import { useEffect } from 'react';

export default function PosthogPageView() {
const {
siteConfig: {
customFields: { posthogProjectApiKey },
},
} = useDocusaurusContext();
const { pathname, search } = useLocation();
const posthog = usePostHog();

useEffect(() => {
if (posthogProjectApiKey && pathname) {
const url = `${window.origin}${pathname}${search}`;

posthog.capture('$pageview', {
$current_url: url,
});
}
}, [posthogProjectApiKey, pathname, search, posthog]);

return null;
}
83 changes: 0 additions & 83 deletions src/pages/code-of-conduct.mdx

This file was deleted.

Binary file removed src/pages/img/bg-dark.webp
Binary file not shown.
Binary file removed src/pages/img/bg-light.webp
Binary file not shown.
Binary file removed src/pages/img/hero/automate.webp
Binary file not shown.
Binary file removed src/pages/img/hero/discover.webp
Binary file not shown.
Binary file removed src/pages/img/hero/monitor.webp
Binary file not shown.
Binary file removed src/pages/img/hero/placeholder.webp
Binary file not shown.
Binary file removed src/pages/img/hero/remediate.webp
Binary file not shown.
1 change: 0 additions & 1 deletion src/pages/img/icons/arrow-dark.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/pages/img/icons/arrow-filled.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/pages/img/icons/arrow-light.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/pages/img/icons/arrow-outline.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/pages/img/icons/docs-dark.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/pages/img/icons/docs-light.svg

This file was deleted.

Loading