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

release #688

Merged
merged 11 commits into from
Feb 13, 2024
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ TURNSTILE_SITEKEY=example_turnstile_sitekey
NX_AIRDROP_ENDPOINT=airdrop.local

INDEXER_ENDPOINT=indexer.local

NEXT_PUBLIC_POSTHOG_KEY=ph_project_api_key
NEXT_PUBLIC_POSTHOG_HOST=ph_instance_address
122 changes: 62 additions & 60 deletions apps/islamic-website/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import { Footer } from '../../components/footer/footer';
import Header, { MobileHeader } from '../../components/header/header';
import { DEPLOY_URL, VERCEL_ENV } from '../../constants';
import { alexandriaFont, handjetFont, vcrFont } from '../../fonts';
import { PHProvider } from '../../providers/posthog';
import { SOCIAL_LINKS } from '../../social-links';
import { PostHogPageView } from '../../utils/posthog-page-view';
import 'swiper/css';
import 'swiper/css/navigation';
import '../../styles/global.css';
Expand Down Expand Up @@ -88,35 +90,34 @@ export default async function LocaleLayout({
vcrFont.variable,
)}
>
<body className="bg-islamic-bg-black font-alexandria flex min-h-screen flex-col text-white antialiased">
{isScamBannerShow && <ScamBanner />}

{isMobileUserAgent ? (
<MobileHeader
locale={locale}
isBannerVisible={isScamBannerShow}
isBuyButtonVisible={!isRestrictedByGeo}
/>
) : (
<Header
locale={locale}
isBannerVisible={isScamBannerShow}
isBuyButtonVisible={!isRestrictedByGeo}
/>
)}

<main className="flex-1">{children}</main>
<Footer socialLinks={SOCIAL_LINKS} />

{VERCEL_ENV === 'production' && (
<>
<Script
async={true}
defer={true}
id="fb-pixel"
data-cookiecategory="analytics"
dangerouslySetInnerHTML={{
__html: `
<PHProvider>
<body className="bg-islamic-bg-black font-alexandria flex min-h-screen flex-col text-white antialiased">
<PostHogPageView />
{isScamBannerShow && <ScamBanner />}
{isMobileUserAgent ? (
<MobileHeader
locale={locale}
isBannerVisible={isScamBannerShow}
isBuyButtonVisible={!isRestrictedByGeo}
/>
) : (
<Header
locale={locale}
isBannerVisible={isScamBannerShow}
isBuyButtonVisible={!isRestrictedByGeo}
/>
)}
<main className="flex-1">{children}</main>
<Footer socialLinks={SOCIAL_LINKS} />
{VERCEL_ENV === 'production' && (
<>
<Script
async={true}
defer={true}
id="fb-pixel"
data-cookiecategory="analytics"
dangerouslySetInnerHTML={{
__html: `
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
Expand All @@ -128,46 +129,47 @@ export default async function LocaleLayout({
fbq('init', '873030480371387');
fbq('track', 'PageView');
`,
}}
/>
<Script
async={true}
defer={true}
id="gtm"
data-cookiecategory="analytics"
dangerouslySetInnerHTML={{
__html: `
}}
/>
<Script
async={true}
defer={true}
id="gtm"
data-cookiecategory="analytics"
dangerouslySetInnerHTML={{
__html: `
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-5H2ZFCN');
`,
}}
/>
<Script
async={true}
src="https://www.googletagmanager.com/gtag/js?id=G-5FLBNV5M30"
id="gtm-haqq"
data-cookiecategory="analytics"
/>
<Script
defer={true}
id="gtm-haqq-2"
data-cookiecategory="analytics"
dangerouslySetInnerHTML={{
__html: `
}}
/>
<Script
async={true}
src="https://www.googletagmanager.com/gtag/js?id=G-5FLBNV5M30"
id="gtm-haqq"
data-cookiecategory="analytics"
/>
<Script
defer={true}
id="gtm-haqq-2"
data-cookiecategory="analytics"
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'G-5FLBNV5M30');
`,
}}
/>
}}
/>

<CookieConsentModal />
<Analytics mode="auto" />
<SpeedInsights />
</>
)}
</body>
<CookieConsentModal />
<Analytics mode="auto" />
<SpeedInsights />
</>
)}
</body>
</PHProvider>
</html>
</NextIntlClientProvider>
);
Expand Down
14 changes: 14 additions & 0 deletions apps/islamic-website/providers/posthog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client';
Dismissed Show dismissed Hide dismissed
import posthog from 'posthog-js';
import { PostHogProvider } from 'posthog-js/react';

if (typeof window !== 'undefined') {
posthog.init(process.env['NEXT_PUBLIC_POSTHOG_KEY']!, {
api_host: process.env['NEXT_PUBLIC_POSTHOG_HOST'],
capture_pageview: false,
});
}

export function PHProvider({ children }: { children: React.ReactNode }) {
return <PostHogProvider client={posthog}>{children}</PostHogProvider>;
}
26 changes: 26 additions & 0 deletions apps/islamic-website/utils/posthog-page-view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client';

import { useEffect } from 'react';
import { usePathname, useSearchParams } from 'next/navigation';
import { usePostHog } from 'posthog-js/react';

export function PostHogPageView() {
const pathname = usePathname();
const searchParams = useSearchParams();
const posthog = usePostHog();

// Track pageviews
useEffect(() => {
if (pathname && posthog) {
let url = window.origin + pathname;
if (searchParams.toString()) {
url = url + `?${searchParams.toString()}`;
}
posthog.capture('$pageview', {
$current_url: url,
});
}
}, [pathname, searchParams, posthog]);

return null;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"nanoid": "5.0.4",
"next": "14.0.4",
"next-intl": "3.4.2",
"posthog-js": "1.105.6",
"qrcode.react": "3.1.0",
"react": "18.2.0",
"react-countdown": "2.3.5",
Expand Down
25 changes: 25 additions & 0 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading