# ATT Consent - Developer Context ## What This Is A WordPress plugin implementing Google Consent Mode v2 with session attribution preservation. It replaces paid CMv2 plugins (e.g., CookieYes) with a self-contained, distributable alternative. ## Architecture ### Core Flow 1. **Inline `` script (priority 1)** - Sets consent defaults and captures attribution to sessionStorage. Must run before any Google tags. 2. **Tracking script (priority 2)** - Loads gtag.js or GTM. In Advanced mode, loads immediately. In Basic mode, deferred until consent. 3. **Footer** - Banner HTML + enqueued `banner.js` and `banner.css`. ### Key Files - `includes/class-frontend.php` - Orchestrates the output order. The `output_consent_defaults()` method generates the critical inline script. - `public/js/consent-manager.js` - Core logic: `AttConsent.update()` replays attribution, sends consent signals, injects scripts, sets cookie. This is the public API. - `public/js/banner.js` - UI only. Calls `AttConsent.update()` on button clicks. - `includes/class-admin.php` - Admin settings with 5 tabs. Handles save via `admin_post`, scripts CRUD via AJAX. - `includes/class-scripts-manager.php` - CRUD for custom JS snippets stored in `{prefix}att_cc_scripts` table. ### Settings Single serialized option: `att_consent_settings`. Access via `ATT_Consent::get_settings()` which merges with defaults. ### Custom Scripts Table ```sql {prefix}att_cc_scripts (id, name, snippet, category, placement, status, priority, created_at, updated_at) ``` Scripts are rendered in PHP as inert `