Baner się nie wyświetla

Problem

  • Baner dotyczący plików cookie nie wyświetla się po załadowaniu strony.
  • Użytkownicy nie widzą prośby o zgodę.

Kroki diagnostyczne

Krok 1: Sprawdź, czy wtyczka TermsFeed Cookie Consent została załadowana

// Open browser console and type:
console.log(typeof cookieconsent);

// Should output: "object"
// If "undefined", script didn't load

Krok 2: Sprawdź, czy występują błędy JavaScript

  1. Otwórz DevTools (F12)
  2. Przejdź do zakładki Konsola
  3. Poszukaj błędów

Typowe błędy to:

  1. cookieconsent is not defined
  2. Uncaught ReferenceError
  3. Failed to load resource

Krok 3: Sprawdź umieszczenie skryptu zgody na pliki cookie TermsFeed

<!-- ❌ WRONG - Script in <head> without async -->
<head>
    <script src="//www.termsfeed.com/public/cookie-consent/4.2.0/cookie-consent.js"></script>
    <script>
        cookieconsent.run({ / config / });
    </script>
</head>

<!-- ✅ CORRECT - Script before </body> with DOMContentLoaded -->
<body>
    <!-- content -->

    <script src="//www.termsfeed.com/public/cookie-consent/4.2.0/cookie-consent.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            cookieconsent.run({ / config / });
        });
    </script>
</body>

Typowe przyczyny i rozwiązania

Przyczyna 1: Użytkownik już wyraził zgodę

// Check if user has cookie
console.log(document.cookie);
// Look for: cookie_consent_level=...

// To test banner, clear cookie:
document.cookie = 'cookie_consent_level=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
// Then reload page

Przyczyna 2: Program blokujący reklamy blokuje TermsFeed Cookie Consent

Rozwiązaniem jest zintegrowanie serwera proxy w celu obsługi TermsFeed Cookie Consent.

Przyczyna 3: Polityka bezpieczeństwa treści blokuje ładowanie

Błąd w Narzędziach programisty > Konsola może brzmieć Refused to load the script ... violates the following Content Security Policy directive

Rozwiązaniem jest aktualizacja nagłówków CSP:

Content-Security-Policy: script-src 'self' www.termsfeed.com 'unsafe-inline'

Przyczyna 4: Nieprawidłowa konfiguracja

Typowe błędy konfiguracyjne:


// 1. Missing quotes
cookieconsent.run({
    consent_type: express  // ❌ Missing quotes
});

// 2. Trailing comma (IE issue)
cookieconsent.run({
    "consent_type": "express",  // ❌ Trailing comma
});

// 3. Missing DOMContentLoaded
cookieconsent.run({ / config / });  // ❌ Runs before DOM ready

// ✅ CORRECT:
document.addEventListener('DOMContentLoaded', function () {
    cookieconsent.run({
        "consent_type": "express",
        "website_name": "My Site",
        "language": "en"
    });
});

Przyczyna 5: Konflikt skryptów

Inny skrypt może uniemożliwiać wyświetlenie banera zgody na pliki cookie TermsFeed.

Rozwiązaniem jest sprawdzenie kolejności ładowania skryptów.

// Test isolation
// Temporarily remove ALL other scripts
// Keep ONLY cookie consent
// If banner shows, you have a conflict

// Common conflicts:
// - Other cookie consent tools
// - Privacy plugins
// - Ad blockers (client-side)

Tryb debugowania

Włącz rejestrowanie debugowania:

cookieconsent.run({
    "consent_type": "express",
    "website_name": "My Site",
    "debug": true  // Enable debug logging
});

// Check console for debug messages:
// [CookieConsent] Banner initialized
// [CookieConsent] User has no consent
// [CookieConsent] Showing banner

Skrypty nie są blokowane

Problem

„Oznaczyłem mój skrypt Google Analytics tagiem data-cookie-consent='tracking', ale nadal uruchamia się on, zanim użytkownik zaakceptuje pliki cookie!”

Kroki diagnostyczne

Krok 1: Sprawdź oznaczenie skryptu

<!-- ❌ WRONG -->
<script type="text/javascript" data-cookie-consent="tracking">
  // GA code
</script>

<!-- ✅ CORRECT -->
<script type="text/plain" data-cookie-consent="tracking">
  // GA code
</script>

<!-- Key difference: type="text/plain" NOT type="text/javascript" -->

Krok 2: Sprawdź kartę Sieć

  1. Otwórz DevTools → zakładka Sieć
  2. Wyczyść pliki cookie
  3. Odśwież stronę (przed wyrażeniem zgody)
  4. Filtruj skrypty śledzące
  5. Skrypty z tagami NIE powinny pojawiać się w zakładce Sieć

Krok 3: Sprawdź, czy pliki cookie są ustawiane

  1. DevTools → Aplikacja → Pliki cookie
  2. Przed akceptacją: brak plików cookie Google Analytics
  3. Po zaakceptowaniu: pojawiają się pliki cookie _ga, _gid

Typowe przyczyny i rozwiązania

Przyczyna 1: Skrypt załadowany przed wyrażeniem zgody na pliki cookie

<!-- ❌ WRONG ORDER -->
<script type="text/plain" data-cookie-consent="tracking">
  // GA code
</script>
<script src="//www.termsfeed.com/public/cookie-consent/4.2.0/cookie-consent.js"></script>

<!-- ✅ CORRECT ORDER -->
<script src="//www.termsfeed.com/public/cookie-consent/4.2.0/cookie-consent.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
    cookieconsent.run({ / config / });
});
</script>

<!-- NOW tag scripts below -->
<script type="text/plain" data-cookie-consent="tracking">
  // GA code
</script>

Przyczyna 2: Skrypt zewnętrzny nie jest zablokowany

<!-- ❌ External scripts need different approach -->
<script src="https://www.googletagmanager.com/gtag/js?id=G-XXX" data-cookie-consent="tracking"></script>

<!-- ✅ CORRECT - wrap in type="text/plain" -->
<script type="text/plain" data-cookie-consent="tracking">
  var script = document.createElement('script');
  script.src = 'https://www.googletagmanager.com/gtag/js?id=G-XXX';
  script.async = true;
  document.head.appendChild(script);

  script.onload = function() {
    // Initialize GA
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'G-XXX');
  };
</script>

Przyczyna 3: Korzystanie z Google Tag Manager

Częstym problemem jest sytuacja, w której GTM ładuje się przed wyrażeniem zgody.

Rozwiązaniem jest nieoznaczanie samego kontenera GTM. Zamiast tego:

  1. Załaduj GTM normalnie (bez tagowania)
  2. Skonfiguruj tagi W GTM tak, aby uruchamiały się tylko po uzyskaniu zgody
  3. Użyj wbudowanego trybu zgody lub niestandardowych wyzwalaczy
<!-- Don't tag the GTM container -->
<script>(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-XXXX');</script>

<!-- Instead, push consent state to dataLayer -->
<script>
document.addEventListener('DOMContentLoaded', function () {
    cookieconsent.run({
        // ... config ...
        "callbacks": {
            "scripts_specific_loaded": (level) => {
                // Push to dataLayer
                window.dataLayer = window.dataLayer || [];
                window.dataLayer.push({
                    'event': 'cookie_consent_update',
                    'consent_level': level
                });
            }
        }
    });
});
</script>

<!-- Then in GTM, create trigger:
   Event: cookie_consent_update
   Condition: consent_level equals tracking
-->

Przyczyna 4: Pliki cookie są ustawiane przez serwer

Jeśli serwer zaplecza ustawia pliki cookie przed uruchomieniem JavaScript, rozwiązaniem jest napisanie więcej kodu po stronie serwera.

<?php
// Check if user has consented (server-side)
$hasConsent = false;
if (isset($_COOKIE['cookie_consent_level'])) {
    $consentLevel = json_decode(urldecode($_COOKIE['cookie_consent_level']), true);
    $hasConsent = in_array('tracking', $consentLevel);
}

// Only set analytics cookies if user consented
if ($hasConsent) {
    setcookie('analytics_id', $user_id, time() + 86400, '/');
}
?>

Zgoda nie jest trwała

Problem

„Użytkownik akceptuje pliki cookie, ale po przejściu na inną stronę lub odświeżeniu strony baner pojawia się ponownie!”

Kroki diagnostyczne

Krok 1: Sprawdź, czy plik cookie jest ustawiany

// After accepting, open console and run:
console.log(document.cookie);

// Should see something like:
// cookie_consent_level=%5B%22strictly-necessary%22%2C%22tracking%22%5D

Krok 2: Sprawdź właściwości pliku cookie

// DevTools → Application → Cookies
// Look for: cookie_consent_level

// Check:
// ✓ Domain: Should match your domain
// ✓ Path: Should be /
// ✓ Expires: Should be future date (1 year)
// ✓ HttpOnly: Should be unchecked (JavaScript needs access)
// ✓ Secure: Depends on your settings
// ✓ SameSite: Strict or Lax

Typowe przyczyny i rozwiązania

Przyczyna 1: Niezgodność ścieżki pliku cookie

Problem

Plik cookie został ustawiony dla /subdir, ale strona znajduje się pod adresem /

Rozwiązanie

Upewnij się, że plik cookie używa ścieżki głównej.

// Cookie should be set for path=/
// This happens automatically, but verify in DevTools

// If using cookie_domain parameter, DON'T include path:
cookieconsent.run({
    "cookie_domain": ".example.com",  // ✅ No path needed
    // Other config...
});

Przyczyna 2: Przeglądarka blokuje pliki cookie

Problem

Ustawienia prywatności przeglądarki uniemożliwiają przechowywanie plików cookie.

Rozwiązanie

Użytkownik musi dostosować ustawienia przeglądarki.

// Detect if cookies are blocked
function areCookiesEnabled() {
    try {
        document.cookie = 'test=test; SameSite=Strict';
        const enabled = document.cookie.indexOf('test=') !== -1;
        document.cookie = 'test=; expires=Thu, 01 Jan 1970 00:00:00 UTC';
        return enabled;
    } catch (e) {
        return false;
    }
}

// Show warning if cookies disabled
if (!areCookiesEnabled()) {
    alert('Cookies are disabled in your browser. Please enable them to save your preferences.');
}

Przyczyna 3: Konflikt przy usuwaniu plików cookie

Problem

Inny skrypt lub rozszerzenie przeglądarki usuwa pliki cookie.

Rozwiązanie

Sprawdź, co usuwa pliki cookie

// Check what's deleting cookies
// Add console log on page load:
console.log('Cookies on load:', document.cookie);

// If consent cookie is missing, something deleted it
// Common culprits:
// - Privacy extensions (Privacy Badger, uBlock)
// - Browser auto-delete (Firefox Enhanced Tracking Protection)
// - Another script calling document.cookie clear

Przyczyna 4: Problemy z subdomenami

Problem

Plik cookie ustawiony na www.example.com nie działa na example.com

Rozwiązanie

Użyj parametru cookie_domain.

cookieconsent.run({
    "cookie_domain": ".example.com",  // Note the leading dot!
    // This makes cookie valid for ALL subdomains
    // Other config...
});

Przyczyna 5: Niezgodność HTTPS/HTTP

Problem:

Plik cookie ustawiony z flagą Secure w protokole HTTPS, ale strona przełącza się na HTTP.

Rozwiązanie:

Upewnij się, że protokół jest spójny LUB usuń flagę bezpieczeństwa na czas testów.

cookieconsent.run({
    "cookie_secure": false,  // Set to true ONLY if site is always HTTPS
    // Other config...
});

// For production HTTPS sites:
cookieconsent.run({
    "cookie_secure": true,  // ✅ Recommended for HTTPS
    // Other config...
});

Tryb zgody Google nie działa

Problem

„Wdrożyłem tryb zgody Google V2, ale Google Analytics nadal pokazuje 0 zdarzeń, nawet gdy użytkownicy akceptują pliki cookie”.

Kroki diagnostyczne

Krok 1: Sprawdź, czy funkcja gtag istnieje

// Open console:
console.log(typeof gtag);
// Should output: "function"

// If "undefined", gtag didn't load

Krok 2: Sprawdź warstwę danych

// Check dataLayer contents:
console.log(window.dataLayer);

// Should see consent events:
// [{event: "consent", ...}, {event: "config", ...}]

Krok 3: Użyj Google Tag Assistant

  1. Zainstaluj: rozszerzenie Tag Assistant dla przeglądarki Chrome
  2. Włącz debugowanie
  3. Odśwież stronę
  4. Sprawdź zdarzenia w trybie zgody

Typowe przyczyny i rozwiązania

Przyczyna 1: Niewłaściwa kolejność implementacji

<!-- ❌ WRONG ORDER -->
<script src="//www.termsfeed.com/public/cookie-consent/4.2.0/cookie-consent.js"></script>
<script>
gtag('consent', 'default', {'analytics_storage': 'denied'});
</script>

<!-- ✅ CORRECT ORDER -->
<!-- 1. Set default consent FIRST -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
    'ad_storage': 'denied',
    'analytics_storage': 'denied'
});
</script>

<!-- 2. THEN load Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXX');
</script>

<!-- 3. THEN Cookie Consent -->
<script src="//www.termsfeed.com/public/cookie-consent/4.2.0/cookie-consent.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
    cookieconsent.run({
        // ... config with callbacks ...
    });
});
</script>

Przyczyna 2: Brak parametru callbacks_force

// ❌ Without callbacks_force, callbacks won't fire for Consent Mode
cookieconsent.run({
    "callbacks": {
        "scripts_specific_loaded": (level) => {
            gtag('consent', 'update', {'analytics_storage': 'granted'});
        }
    }
    // Missing: "callbacks_force": true
});

// ✅ CORRECT
cookieconsent.run({
    "callbacks": {
        "scripts_specific_loaded": (level) => {
            gtag('consent', 'update', {'analytics_storage': 'granted'});
        }
    },
    "callbacks_force": true  // Required for Consent Mode!
});

Przyczyna 3: Literówka w typach zgody

// ❌ Common typos:
gtag('consent', 'update', {
    'analytic_storage': 'granted'  // ❌ Missing 's'
});

gtag('consent', 'update', {
    'ad_store': 'granted'  // ❌ Should be 'ad_storage'
});

// ✅ CORRECT spellings:
gtag('consent', 'update', {
    'analytics_storage': 'granted',  // ✅
    'ad_storage': 'granted',         // ✅
    'ad_user_data': 'granted',       // ✅
    'ad_personalization': 'granted'  // ✅
});

Przyczyna 4: Nieprawidłowe mapowanie kategorii

// Make sure you're mapping correct categories
"callbacks": {
    "scripts_specific_loaded": (level) => {
        switch (level) {
            case 'tracking':  // ✅ Analytics
                gtag('consent', 'update', {
                    'analytics_storage': 'granted'
                });
                break;
            case 'targeting':  // ✅ Advertising
                gtag('consent', 'update', {
                    'ad_storage': 'granted',
                    'ad_user_data': 'granted',
                    'ad_personalization': 'granted'
                });
                break;
        }
    }
}

Testowanie trybu zgody

// After accepting cookies, check consent state:
console.log(google_tag_manager['GTM-XXXX'].dataLayer.get('consent'));

// Should show:
// {
//   ad_storage: "granted",
//   analytics_storage: "granted",
//   ...
// }

Problemy międzydomenowe

Problem

„Ustawiłem cookie_domain na „.example.com”, ale baner nadal wyświetla się w każdej subdomenie. Użytkownicy są zirytowani!”

Kroki diagnostyczne

Krok 1: Sprawdź domenę plików cookie

// DevTools → Application → Cookies
// Look for: cookie_consent_level
// Domain column should show: .example.com (with leading dot)

// If it shows: www.example.com (no dot)
// Then cookie_domain parameter isn't working

Krok 2: Sprawdź pliki cookie z subdomeny

// On www.example.com:
console.log(document.cookie);
// Should include: cookie_consent_level=...

// Then navigate to shop.example.com:
console.log(document.cookie);
// Should STILL include the same cookie

Krok 3: Przetestuj w trybie incognito

  1. Otwórz okno incognito
  2. Odwiedź stronę www.example.com
  3. Zaakceptuj pliki cookie
  4. Zapisz wartość pliku cookie
  5. Odwiedź stronę shop.example.com
  6. Sprawdź, czy ten sam plik cookie istnieje

Typowe przyczyny i rozwiązania

Przyczyna 1: Brakujący kropka na początku

// www.example.com has:
cookieconsent.run({
    "website_name": "Main Site",
    "cookie_domain": ".example.com"
});

// shop.example.com has:
cookieconsent.run({
    "website_name": "Shop",  // ❌ Different config
    "cookie_domain": ".example.com"
});

Rozwiązanie

Użyj IDENTYCZNEJ konfiguracji we wszystkich domenach.

// ✅ SOLUTION: Use IDENTICAL configuration on all domains
const SHARED_CONFIG = {
    "notice_banner_type": "headline",
    "consent_type": "express",
    "website_name": "Example",  // Same everywhere
    "cookie_domain": ".example.com",
    // ... rest of config
};

// Use on ALL domains
cookieconsent.run(SHARED_CONFIG);

Przyczyna 3: Przeglądarka blokuje pliki cookie stron trzecich

Problem

Safari, Firefox i Brave domyślnie blokują pliki cookie między witrynami.

Rozwiązanie

Dotyczy to RÓŻNYCH domen, a nie subdomen.

  • Poddomeny (.example.com) = pliki cookie pierwszej kategorii ✅ Powinno działać
  • Różne TLD (example.com vs example.co.uk) = Pliki zewnętrzne ❌ Nie będzie działać
// For actual cross-domain (different TLDs), use backend sync:
"callbacks": {
    "user_consent_saved": () => {
        // Sync to backend
        fetch('https://api.example.com/sync-consent', {
            method: 'POST',
            body: JSON.stringify({
                consent: getConsentState(),
                user_id: getUserId()
            })
        });
    }
}

Przyczyna 4: Plik cookie niewidoczny z powodu ścieżki

// Cookie might be set for specific path
// Check: DevTools → Application → Cookies → Path column

  // Should be: /
// If not, cookie won't work across site

// Force root path (this should be default):
// Note: TermsFeed Cookie Consent should handle this automatically
// But if you're manually setting cookies:
document.cookie = 'cookie_consent_level=...; path=/; domain=.example.com';

Problemy z kodowaniem znaków

Problem

„Znaki specjalne w tekście mojego banera wyświetlają się jako �� lub dziwne symbole”

Rozwiązanie

Upewnij się, że używasz kodowania UTF-8.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">  <!-- ✅ Must have this -->
    <title>My Site</title>
</head>
<body>
    <script src="//www.termsfeed.com/public/cookie-consent/4.2.0/cookie-consent.js" charset="UTF-8"></script>
    <!-- ✅ charset="UTF-8" in script tag -->
</body>
</html>

W przypadku tekstu niestandardowego:

cookieconsent.run({
    "website_name": "Café Français",  // ✅ UTF-8 characters work
    "language": "fr"  // Use appropriate language
});