This commit is contained in:
Timo Knuth
2026-01-26 16:47:57 +01:00
9 changed files with 112 additions and 1 deletions

View File

@@ -3,6 +3,8 @@
import { useEffect, useState, useRef } from 'react';
import { useSession } from 'next-auth/react';
import { usePathname } from 'next/navigation';
interface AdBannerProps {
dataAdSlot: string;
dataAdFormat?: string;
@@ -17,9 +19,30 @@ export default function AdBanner({
className = '',
}: AdBannerProps) {
const { data: session, status } = useSession();
const pathname = usePathname();
const adRef = useRef<HTMLModElement>(null);
const [adFilled, setAdFilled] = useState(false);
// Paths where ads should NOT be shown
const excludedPaths = [
'/', // English Home
'/de', // German Home
'/qr-code-erstellen', // German Landing
'/contact', // Contact
'/about', // About
'/legal', // Legal pages
'/privacy',
'/terms',
'/cookie-policy',
'/impressum',
];
// Check if current path matches strictly or starts with excluded path (for nested legal/blog pages if needed, though mostly exact matches here)
const shouldExclude = excludedPaths.some(path => {
if (path === '/') return pathname === '/';
return pathname === path || pathname?.startsWith(`${path}/`);
});
// Check if user has a paid plan
const isPaidUser = session?.user && (
session.user.plan === 'PRO' ||
@@ -27,6 +50,8 @@ export default function AdBanner({
session.user.plan === 'LIFETIME'
);
if (shouldExclude) return null;
useEffect(() => {
// Don't load if loading session or if user is paid
if (status === 'loading' || isPaidUser) return;

View File

@@ -0,0 +1,38 @@
'use client';
import { useEffect, useState } from 'react';
import { usePathname, useSearchParams } from 'next/navigation';
export default function FacebookPixel() {
const [loaded, setLoaded] = useState(false);
const pathname = usePathname();
const searchParams = useSearchParams();
useEffect(() => {
// Only load if ID is present
const pixelId = process.env.NEXT_PUBLIC_FACEBOOK_PIXEL_ID;
if (!pixelId) return;
// Check consent
const cookieConsent = localStorage.getItem('cookieConsent');
if (cookieConsent !== 'accepted') return;
if (!loaded) {
import('react-facebook-pixel')
.then((x) => x.default)
.then((ReactPixel) => {
ReactPixel.init(pixelId);
ReactPixel.pageView();
setLoaded(true);
});
} else {
import('react-facebook-pixel')
.then((x) => x.default)
.then((ReactPixel) => {
ReactPixel.pageView();
});
}
}, [pathname, searchParams, loaded]);
return null;
}