diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..38bcb77 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + name: Test & Build (Bun) + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - name: Install dependencies + run: bun install + + - name: Biome Linter & Formatter Check + run: bun run check + + - name: TypeScript Typecheck + run: bun run typecheck + + - name: Run Tests + run: bun test + + - name: Build Package + run: bun run build diff --git a/.gitignore b/.gitignore index 04c01ba..da3f531 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ -dist/ \ No newline at end of file +dist/ +TODO.md \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b4df074 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,30 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.4.0] - 2026-11-15 + +### Added +- **Google Consent Mode v2 Default Signals**: `ConsentProvider` and `AdSenseScript` now automatically initialize `gtag('consent', 'default', ...)` on mount. +- **IAB TCF & GPP Compliance**: Added `gdprApplies` handling to avoid blocking non-EEA traffic, updated purpose checking, and added GPP section query support for CCPA/CPRA opt-out signals. +- **Active GAM & Ezoic Adapters**: Implemented actual `googletag` command queue dispatching for Google Ad Manager and `ezstandalone` queue lifecycle for Ezoic. +- **Unfill Detection**: Added `MutationObserver` on `data-ad-status` attributes to immediately trigger fallbacks when AdSense unfill occurs. +- **Dev Sanity Warnings**: Emits helpful development warnings when ad units or clients are missing or defaulting to dummy placeholders. +- **Deterministic Keys**: `injectPortableTextAds` and `injectPortableTextAffiliate` now use deterministic paragraph-based keys, eliminating React hydration mismatches. +- **CI Workflow**: Restored automated GitHub Actions continuous integration workflow. +- **Package Metadata**: Added `sideEffects: false`, `engines`, and `./package.json` to exports. + +### Fixed +- **Quickstart Ad Delivery**: Fixed issue where `ConsentProvider` defaulted to unknown status and blocked ad tags from rendering in quickstart examples. +- **RSC Module Boundaries**: Fixed `"use client"` directive being stamped across root exports, allowing Server Components to cleanly import transformers and config client. +- **Dead CLS Guard & Unfill Effects**: Fixed effect dependency bugs in `AdSenseSlot` that prevented unfill detection and CLS warnings from executing. +- **Paragraph Spacing**: Fixed `startOffset` placement calculation and implemented missing `minParagraphsTotal` checks in in-article inserters. +- **Feed Cache Safety**: Replaced unbounded map in `feed-inserter` with a bounded LRU cache that correctly invalidates on items changes or rule toggles. +- **Timer Leaks**: Fixed un-cleared intervals in `useAdMetrics` when crossing viewability thresholds. +- **Tailwind Coupling**: Replaced Tailwind v4-exclusive utilities with standard fallbacks and added solid inline styles for unstyled environments. + +## [1.3.2] - Previous Release +- Enhanced PortableTextBlock types and Sanity integration. diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..fe2907f --- /dev/null +++ b/biome.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.6.6/schema.json", + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true + }, + "files": { + "ignoreUnknown": true + }, + "formatter": { + "enabled": true, + "indentStyle": "tab", + "lineWidth": 80 + }, + "linter": { + "enabled": true, + "rules": { + "preset": "recommended", + "performance": { + "noImgElement": "off" + } + } + } +} diff --git a/package.json b/package.json index 26b5918..d11226f 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,12 @@ "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", + "sideEffects": false, + "engines": { + "node": ">=18.0.0" + }, "exports": { + "./package.json": "./package.json", ".": { "types": "./dist/index.d.ts", "import": "./dist/index.mjs", @@ -65,7 +70,7 @@ "url": "https://github.com/LinuxCTRL/adinject-react/issues" }, "scripts": { - "build": "tsup && node -e 'const fs = require(\"fs\"); [\"dist/index.js\", \"dist/index.mjs\", \"dist/client/index.js\", \"dist/client/index.mjs\"].forEach(f => { if (fs.existsSync(f)) { const c = fs.readFileSync(f, \"utf8\"); if (!c.startsWith(\"\\\"use client\\\"\")) fs.writeFileSync(f, \"\\\"use client\\\";\\n\" + c); } });'", + "build": "tsup && node -e 'const fs = require(\"fs\"); [\"dist/client/index.js\", \"dist/client/index.mjs\"].forEach(f => { if (fs.existsSync(f)) { const c = fs.readFileSync(f, \"utf8\"); if (!c.startsWith(\"\\\"use client\\\"\")) fs.writeFileSync(f, \"\\\"use client\\\";\\n\" + c); } });'", "dev": "tsup --watch", "test": "bun test", "typecheck": "tsc --noEmit", @@ -83,12 +88,16 @@ } }, "devDependencies": { - "@types/node": "^26.3.0", + "@biomejs/biome": "^2.6.6", + "@types/node": "^26.6.6", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", "react": "^19.0.0", "react-dom": "^19.0.0", "tsup": "^8.3.6", "typescript": "^5.7.3" + }, + "allowScripts": { + "esbuild": true } -} \ No newline at end of file +} diff --git a/src/adapters/index.tsx b/src/adapters/index.tsx index a384833..91757e3 100644 --- a/src/adapters/index.tsx +++ b/src/adapters/index.tsx @@ -1,7 +1,32 @@ import type React from "react"; +import { useEffect } from "react"; import { AdSenseSlot } from "../client/AdSenseSlot"; import type { AdDimensions, AdFormat, FallbackBanner } from "../types"; +declare global { + interface Window { + googletag?: { + cmd: Array<() => void>; + defineSlot?: ( + adUnitPath: string, + size: unknown, + divId: string, + ) => { + addService: (service: unknown) => unknown; + }; + pubads?: () => unknown; + enableServices?: () => void; + display?: (divId: string) => void; + }; + ezstandalone?: { + cmd?: Array<() => void>; + define?: (...slots: number[]) => void; + enable?: () => void; + display?: () => void; + }; + } +} + export interface AdAdapterSlotProps { slot: string; client?: string; @@ -97,6 +122,77 @@ export function adsenseAdapter(opts: { }); } +function GamSlotContainer({ + divId, + adUnitPath, + props, +}: { + divId: string; + adUnitPath: string; + props: AdAdapterSlotProps; +}) { + useEffect(() => { + if (typeof window === "undefined") return; + window.googletag = window.googletag || { cmd: [] }; + window.googletag.cmd = window.googletag.cmd || []; + window.googletag.cmd.push(() => { + if (window.googletag?.defineSlot && window.googletag?.pubads) { + window.googletag + .defineSlot(adUnitPath, "fluid", divId) + ?.addService(window.googletag.pubads()); + window.googletag.enableServices?.(); + } + window.googletag?.display?.(divId); + }); + }, [divId, adUnitPath]); + + return ( +