feat(04-cookie-notice-bugfix): fix CookieNoticePro injectScripts error

Phase 4 complete:

- remove undefined injectScripts calls from CookieNoticePro

- preserve Consent Mode v2 and GTM integration

- add PAUL plan, summary, and changelog
This commit is contained in:
2026-05-08 23:42:46 +02:00
parent f71a1711bb
commit df1c1f4a7d
7 changed files with 357 additions and 68 deletions

View File

@@ -0,0 +1,130 @@
---
phase: 04-cookie-notice-bugfix
plan: 01
type: execute
wave: 1
depends_on: []
files_modified:
- libraries/CookieNoticePro/cookienoticepro.script.js
autonomous: true
delegation: off
---
<objective>
## Goal
Naprawic blad JavaScript `Uncaught ReferenceError: injectScripts is not defined` w CookieNoticePro.
## Purpose
Baner cookies musi dzialac bez bledow konsoli, bo kontroluje zgody RODO i Google Consent Mode v2 przed uruchamianiem analityki.
## Output
Zmodyfikowany `libraries/CookieNoticePro/cookienoticepro.script.js` bez wywolan nieistniejacej funkcji `injectScripts()`.
</objective>
<context>
<clarifications>
- No clarifications needed - blad jest jednoznaczny: `injectScripts()` jest wywolywane w `cookienoticepro.script.js`, ale nie jest zdefiniowane w tej kopii biblioteki.
</clarifications>
## Project Context
@.paul/PROJECT.md
@.paul/ROADMAP.md
@.paul/STATE.md
## Prior Work
@.paul/phases/03-cookie-consent/03-01-SUMMARY.md
## Source Files
@libraries/CookieNoticePro/cookienoticepro.script.js
@templates/site/layout-logged.php
</context>
<acceptance_criteria>
## AC-1: Brak ReferenceError przy akceptacji cookies
```gherkin
Given strona laduje CookieNoticePro i baner jest widoczny
When uzytkownik klika "Akceptuj"
Then konsola przegladarki nie pokazuje `ReferenceError: injectScripts is not defined`
```
## AC-2: Brak ReferenceError przy zapisanych zgodach
```gherkin
Given przegladarka ma zapisane cookies `cnp_consent` i `cnp_prefs`
When strona inicjalizuje `cookieNoticePro.init()`
Then konsola przegladarki nie pokazuje `ReferenceError: injectScripts is not defined`
```
## AC-3: Consent Mode pozostaje aktywny
```gherkin
Given uzytkownik akceptuje lub aktualizuje preferencje cookies
When CookieNoticePro zapisuje preferencje
Then `googleConsentModeHandler()` nadal aktualizuje `analytics_storage` oraz zgody reklamowe zgodnie z preferencjami
```
</acceptance_criteria>
<tasks>
<task type="auto">
<name>Task 1: Usun wywolania nieistniejacego injectScripts</name>
<files>libraries/CookieNoticePro/cookienoticepro.script.js</files>
<action>
Usun lub zastap bezpiecznie dwa wywolania `injectScripts()`:
- w handlerze klikniecia `#cookieAccept`
- w galezi dla juz zapisanej zgody
Zachowaj wywolania `config.onConsentAccept.call(this)` i `googleConsentModeHandler()`.
Nie dodawaj pustej globalnej funkcji jako obejscia, bo maskowaloby to blad integracji biblioteki bez rzeczywistej potrzeby w projekcie.
</action>
<verify>rg -n "injectScripts" libraries/CookieNoticePro/cookienoticepro.script.js zwraca brak wynikow</verify>
<done>AC-1 i AC-2 satisfied: CookieNoticePro nie odwoluje sie do niezdefiniowanej funkcji.</done>
</task>
<task type="auto">
<name>Task 2: Zweryfikuj skladnie i sciezke inicjalizacji</name>
<files>libraries/CookieNoticePro/cookienoticepro.script.js, templates/site/layout-logged.php</files>
<action>
Sprawdz, ze po zmianie plik JavaScript nadal jest parsowalny, a `templates/site/layout-logged.php` dalej laduje biblioteke i wywoluje `cookieNoticePro.init()`.
Nie zmieniaj snippetow GTM ani domyslnych ustawien Consent Mode v2 w layoutcie.
</action>
<verify>node --check libraries/CookieNoticePro/cookienoticepro.script.js; rg -n "cookieNoticePro.init|Google Consent Mode v2|GTM-TW9WCD9J" templates/site/layout-logged.php</verify>
<done>AC-3 satisfied: mechanizm zgody pozostaje podlaczony, a plik JS przechodzi walidacje skladni.</done>
</task>
</tasks>
<boundaries>
## DO NOT CHANGE
- `templates/site/layout-logged.php` poza ewentualna weryfikacja; nie zmieniac GTM ani Consent Mode v2.
- `libraries/CookieNoticePro/cookienoticepro.style.css`.
- Checkout, order flow, data layer purchase i integracja Przelewy24.
- Baza danych i konfiguracja serwera.
## SCOPE LIMITS
- Plan dotyczy tylko bledu `injectScripts is not defined`.
- Nie aktualizowac calej biblioteki CookieNoticePro.
- Nie dodawac nowych zaleznosci frontendowych.
</boundaries>
<verification>
Before declaring plan complete:
- [ ] `rg -n "injectScripts" libraries/CookieNoticePro/cookienoticepro.script.js` returns no results.
- [ ] `node --check libraries/CookieNoticePro/cookienoticepro.script.js` passes.
- [ ] `rg -n "cookieNoticePro.init|Google Consent Mode v2|GTM-TW9WCD9J" templates/site/layout-logged.php` confirms existing integration remains present.
- [ ] Browser console has no `ReferenceError: injectScripts is not defined` after accepting cookies and after reload with saved consent.
- [ ] All acceptance criteria met.
</verification>
<success_criteria>
- CookieNoticePro does not call undefined functions.
- Consent Mode v2 updates still run after preference changes.
- No unrelated files or flows are modified.
- Summary created after apply.
</success_criteria>
<output>
After completion, create `.paul/phases/04-cookie-notice-bugfix/04-01-SUMMARY.md`.
</output>

View File

@@ -0,0 +1,113 @@
---
phase: 04-cookie-notice-bugfix
plan: 01
subsystem: ui
tags: [cookies, gdpr, consent-mode-v2, cookienoticepro, javascript]
requires:
- phase: 03-cookie-consent
provides: CookieNoticePro integrated with Google Consent Mode v2
provides:
- CookieNoticePro no longer calls undefined `injectScripts()`
- Browser console hotfix for cookie acceptance and saved-consent initialization
affects: [cookies, analytics, consent-mode-v2]
tech-stack:
added: []
patterns: [keep CookieNoticePro integration minimal, preserve Consent Mode v2 flow]
key-files:
created: []
modified:
- libraries/CookieNoticePro/cookienoticepro.script.js
key-decisions:
- "Removed undefined `injectScripts()` calls instead of adding an empty compatibility stub."
- "Preserved `googleConsentModeHandler()` and existing layout integration unchanged."
patterns-established:
- "CookieNoticePro fixes stay scoped to the vendor copy unless project integration requires layout changes."
duration: 15min
started: 2026-05-08T00:00:00Z
completed: 2026-05-08T00:00:00Z
---
# Phase 4 Plan 01: Cookie Notice Bugfix Summary
**CookieNoticePro no longer throws `ReferenceError: injectScripts is not defined` during cookie acceptance or initialization with saved consent.**
## Performance
| Metric | Value |
|--------|-------|
| Duration | ~15 min |
| Started | 2026-05-08 |
| Completed | 2026-05-08 |
| Tasks | 2 completed |
| Files modified | 1 source file + PAUL docs |
## Acceptance Criteria Results
| Criterion | Status | Notes |
|-----------|--------|-------|
| AC-1: Brak ReferenceError przy akceptacji cookies | Pass | `injectScripts()` call removed from `#cookieAccept` handler. |
| AC-2: Brak ReferenceError przy zapisanych zgodach | Pass | `injectScripts()` call removed from saved-consent initialization path. |
| AC-3: Consent Mode pozostaje aktywny | Pass | `googleConsentModeHandler()` remains in both relevant consent paths; layout still contains Consent Mode v2, GTM, and `cookieNoticePro.init()`. |
## Accomplishments
- Removed both calls to undefined `injectScripts()` from `libraries/CookieNoticePro/cookienoticepro.script.js`.
- Preserved the existing callback and Google Consent Mode update flow.
- Confirmed the layout integration still loads CookieNoticePro and GTM/Consent Mode v2.
## Verification Results
| Check | Result |
|-------|--------|
| `rg -n "injectScripts" libraries/CookieNoticePro/cookienoticepro.script.js` | Pass - no matches |
| `node --check libraries/CookieNoticePro/cookienoticepro.script.js` | Pass |
| `rg -n "cookieNoticePro.init|Google Consent Mode v2|GTM-TW9WCD9J" templates/site/layout-logged.php` | Pass - all integration points present |
## Files Created/Modified
| File | Change | Purpose |
|------|--------|---------|
| `libraries/CookieNoticePro/cookienoticepro.script.js` | Modified | Removed undefined `injectScripts()` calls. |
| `.paul/phases/04-cookie-notice-bugfix/04-01-PLAN.md` | Created | Execution plan for the hotfix. |
| `.paul/phases/04-cookie-notice-bugfix/04-01-SUMMARY.md` | Created | Completion record for the hotfix. |
| `.paul/STATE.md` | Modified | Updated PAUL loop state for plan/apply/unify. |
| `.paul/ROADMAP.md` | Modified | Added and closed the v0.3 hotfix phase. |
## Decisions Made
| Decision | Rationale | Impact |
|----------|-----------|--------|
| Remove undefined calls instead of adding a no-op `injectScripts()` | The project does not use CookieNoticePro's script injection hook, and a no-op would hide unused behavior. | Smaller, clearer fix with no global compatibility shim. |
| Leave layout and GTM snippets unchanged | The reported bug was inside the CookieNoticePro script, not the integration layer. | Lower blast radius; existing Consent Mode v2 behavior preserved. |
## Deviations from Plan
None - plan executed as written.
## Issues Encountered
| Issue | Resolution |
|-------|------------|
| Existing PAUL files contained mixed/garbled character encoding from prior content. | New hotfix PAUL entries were written in ASCII to avoid additional encoding churn. |
## Next Phase Readiness
**Ready:**
- v0.3 hotfix is complete.
- CookieNoticePro can be manually checked in the browser without the known `injectScripts` ReferenceError.
**Concerns:**
- Browser console verification on production/staging should still be performed after deployment because local CLI checks cannot execute full browser interaction.
**Blockers:**
- None.
---
*Phase: 04-cookie-notice-bugfix, Plan: 01*
*Completed: 2026-05-08*