← Назад к задаче

ANALYTICS_501.md

ANALYTICS_501 — GA initialization, consent mode, contact-form paths, privacy behavior

Scope: source review of the dev mirror /var/www/git/lit-website (HEAD bef231b; the analytics/consent/contact files are unmodified in the working tree). Patches and tests are in work/analytics501/.

Not done: no live site or preview request, no browser run, no lead submitted, no GA data read, no deployment, no edit to the mirror. Nothing here proves behavior in a real browser or in the GA property.

Labels: [C] confirmed from source or a local test. [A] assumption or needs owner or runtime verification.

1. Summary

#SeverityFindingStatus
A1HighA declined visitor still gets gtag.js loaded from googletagmanager.com and a config hit queued with no consent default[C] source and harness; real network hit [A]
A2HighDetailed banner button "Accept all" / "Alle akzeptieren" calls the decline handler and stores analytics:false[C]
A3MedWithdrawal only sends consent update denied. _ga* cookies are not deleted and the script stays loaded[C]
A4MedinitGA() is not idempotent. Each consent change appends another gtag.js script and another config[C] harness: 2 script tags
A5MedNo consent default, so Consent Mode is not implemented. ad_user_data and ad_personalization are never set[C]
A6MedNEXT_PUBLIC_GA_ID is build-time only. The repo has no .env*, and the Dockerfile has no ARG or ENV for it, so GA may never load[C] repo; deployed value [A]
A7LowtrackPageView and trackEvent are never called. There are no contact or CTA events, and no SPA page views[C]
A8LowThe banner description is hardcoded English in the provider, so DE and FR visitors see English[C]
A9LowThe npm package gtag@^1.0.1 is in package.json but unused (lib/analytics.ts uses its own code)[C]; recommend removal [A]
P1High/api/contact returns 202 when the CRM call fails. Both forms treat response.ok as success, so the visitor sees "success" while the lead exists only in server logs[C]
P2HighThe route logs full PII (name, email, phone, free text, IP, UA) with console.log, and echoes originalFormData back in the response[C]
P3MedGDPR consent fields (gdprConsentTimestamp, version, basis, retention) are only logged. They are not persisted to the CRM[C]
P4MedThe privacy policy states IP anonymization, "automatic deletion after 26 months" and Facebook plug-ins that the code does not matchSee §4
P5LowThe route has no rate limit, honeypot or captcha, and OPTIONS returns Access-Control-Allow-Origin: *[C]

2. GA initialization and consent flow (source-backed)

Files: lib/analytics.ts, components/cookie-consent-provider.tsx, components/blocks/cookie-consent.tsx, app/[locale]/layout.tsx:49 (the provider wraps all pages). There is no <Script> or GTM tag in the layout. GA is injected only by initGA().

Flow as implemented:

  1. First visit, no cookieConsent cookie. The banner shows and GA is not initialized (provider effect, cookie-consent-provider.tsx lines 239–243). [C] This part is correct.
  2. Return visit with a saved choice. The effect calls initGA() and then enableGA() or disableGA(). initGA() runs even when the saved choice is "decline".
  3. initGA(). It pushes js, appends the gtag.js?id=… script tag and pushes config, with no preceding consent default. Per Google's documented behavior, with no default, storage is treated as granted. So the config/page_view command is processed as granted before the later consent update denied. [A: this is documented Google behavior and was not measured on the network.]
  4. Button handlers. Accept, Decline and Save each write the cookie, then call the provider's setConsent, which calls initGA() again.

Local harness (harness.ts, output in harness-output.txt): fake window/document, fake ID G-TEST000000, no network.

ScenarioOriginalPatched
decline1 script tag, config queued, _ga* cookies remain0 script tags, no commands, _ga* removed
acceptno consent default before configconsent default denied → config → update granted
accept twice2 script tags, 2 × js/config1 script tag
accept → withdraw2 script tags, _ga* remain_ga* removed, ga-disable-<ID> set

Notes:

3. Contact-form paths (source-backed)

4. Privacy behavior vs policy

Policy page: app/[locale]/privacy-policy/page.tsx (German text in the file). Stated in §14.3 and nearby:

Policy statementImplementationVerdict
"Data transfer only with your explicit consent"Declined visitors still load gtag.js (A1)Contradicted [C]
"You can withdraw consent at any time" via the footer linkWithdrawal does not clear _ga* cookies (A3)Partly true
"IP anonymization enabled"anonymize_ip is a no-op in GA4 and IPs are not stored by GA4Wording outdated [A]
"Data deleted automatically after 26 months"GA4 retention is configured in the property (the options are 2 or 14 months for standard properties)Needs check in the GA admin [A]
Facebook plug-ins (lines ~426, 479)No Facebook script or pixel in the sourceBoilerplate, no matching code [C]; owner to confirm
Cookie banner "Accept all"Declines (A2)Contradicted [C]

Also: the policy does not name the CRM (Twenty) as a processor or the log retention for form data. Whether it should is a legal decision for the owner or DPO. [A]

5. Fixes prepared (not applied, not deployed)

work/analytics501/analytics.patch (3 files; git apply --check OK on the mirror; tsc --noEmit and eslint clean on a throwaway copy with the patch applied; layout classes and visible copy unchanged):

work/analytics501/crm202.patch (2 files, 1 line each): treat HTTP 202 as an error in both forms so the visitor sees the error message instead of "success". Owner decision: this changes lead-path behavior, so approve it separately from the analytics patch. The existing submitError text is reused and no new copy is added.

Not patched (need owner or legal input): P2 log minimization, P3 persisting consent, P4 policy wording, A6 build env, A8 banner copy (changing it alters visible text), A9 package removal, P5 abuse protection.

6. Test plan (needs authorization where marked)

Static and local (done): see harness-output.txt; tsc and eslint pass on the patched copy.

On the CLA private preview over the SSH tunnel, with a fake GA ID or the real one only if the owner approves a test property or a filtered internal stream:

  1. Fresh profile, load /de. Expected: banner visible, zero requests to googletagmanager.com/google-analytics.com, no _ga* cookies. Run on the original and the patched build.
  2. Decline → reload. Expected (patched): still zero GA requests. Original: gtag/js is expected. This confirms A1.
  3. Accept in the default banner, then in the detailed banner via the footer link. Check the "Accept all" button stores analytics:true (A2). Check dataLayer order consent default → js → config → consent update.
  4. Accept, then withdraw via the footer. Expected: _ga* gone, no further hits, one gtag.js script tag in the DOM.
  5. Contact form: use the failure path only and no real lead. Point GRAPHQL_ENDPOINT at a closed local port in a local next start, submit with an obviously fake address on a non-production instance, and expect an error message (with crm202.patch) or "success" (without it). Do not submit to the production or CRM-connected preview.
  6. Check the build env: confirm whether NEXT_PUBLIC_GA_ID is set in the deploy pipeline (A6) and whether the GA property exists. Needs owner.
  7. In GA admin (owner): check the data-retention setting against the policy's "26 months", the Google Signals setting and the EU data region.

7. Open owner questions

  1. Is a GA4 property in use, and which ID? Is it injected at build time?
  2. Is the 202-as-error change acceptable, and who monitors CRM failures?
  3. Should consent evidence be stored in the CRM (needs a Twenty custom field)?
  4. Should form data stay in container logs? Decide the retention or a minimized log format.
  5. Policy corrections (26 months, IP anonymization, Facebook, CRM processor): owner or DPO.

8. Files

work/analytics501/: analytics.patch, crm202.patch, harness.ts, harness-output.txt, orig/ and new/ (the three analytics files before and after).

Материалы