Skip to content

Commit

Permalink
📈 fix: improve plausible analytics ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Oct 30, 2023
1 parent 07c4f23 commit aa851d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/components/Analytics/Plausible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import { memo } from 'react';

import { getClientConfig } from '@/config/client';

const { PLAUSIBLE_DOMAIN } = getClientConfig();
const { PLAUSIBLE_DOMAIN, PLAUSIBLE_SCRIPT_BASE_URL } = getClientConfig();

const PlausibleAnalytics = memo(() => {
return (
const PlausibleAnalytics = memo(
() =>
PLAUSIBLE_DOMAIN && (
<Script data-domain={PLAUSIBLE_DOMAIN} defer src="https://plausible.io/js/script.js" />
)
);
});
<Script
data-domain={PLAUSIBLE_DOMAIN}
defer
src={`${PLAUSIBLE_SCRIPT_BASE_URL}/js/script.js`}
/>
),
);

export default PlausibleAnalytics;
3 changes: 3 additions & 0 deletions src/config/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare global {

NEXT_PUBLIC_ANALYTICS_PLAUSIBLE?: string;
NEXT_PUBLIC_PLAUSIBLE_DOMAIN?: string;
NEXT_PUBLIC_PLAUSIBLE_SCRIPT_BASE_URL?: string;

NEXT_PUBLIC_ANALYTICS_POSTHOG: string;
NEXT_PUBLIC_POSTHOG_KEY: string;
Expand All @@ -40,6 +41,8 @@ export const getClientConfig = () => ({
// Plausible Analytics
ANALYTICS_PLAUSIBLE: process.env.NEXT_PUBLIC_ANALYTICS_PLAUSIBLE === '1',
PLAUSIBLE_DOMAIN: process.env.NEXT_PUBLIC_PLAUSIBLE_DOMAIN,
PLAUSIBLE_SCRIPT_BASE_URL:
process.env.NEXT_PUBLIC_PLAUSIBLE_SCRIPT_BASE_URL || 'https://plausible.io',

// Posthog Analytics
ANALYTICS_POSTHOG: process.env.NEXT_PUBLIC_ANALYTICS_POSTHOG === '1',
Expand Down

0 comments on commit aa851d4

Please sign in to comment.