Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
dist/
dist/
TODO.md
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
25 changes: 25 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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
}
}
}
118 changes: 98 additions & 20 deletions src/adapters/index.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 (
<aside
id={divId}
aria-label={props.a11yLabel || "Google Ad Manager Advertisement"}
className={`adinject-gam-slot ${props.className || ""}`}
data-adinject-category={props.contentCategory}
style={{
minHeight: props.dimensions?.minHeight || "250px",
width: "100%",
...props.style,
}}
/>
);
}

function EzoicSlotContainer({
slot,
props,
}: {
slot: string;
props: AdAdapterSlotProps;
}) {
useEffect(() => {
if (typeof window === "undefined") return;
const placeholderId = Number.parseInt(slot, 10);
if (Number.isNaN(placeholderId)) return;

window.ezstandalone = window.ezstandalone || {};
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
window.ezstandalone.cmd.push(() => {
window.ezstandalone?.define?.(placeholderId);
window.ezstandalone?.enable?.();
window.ezstandalone?.display?.();
});
}, [slot]);

return (
<aside
id={`ezoic-pub-ad-placeholder-${slot}`}
aria-label={props.a11yLabel || "Ezoic Advertisement"}
className={`adinject-ezoic-slot ${props.className || ""}`}
data-adinject-category={props.contentCategory}
style={{ minHeight: "250px", width: "100%", ...props.style }}
/>
);
}

/**
* Built-in Google Ad Manager (GAM / GPT) Adapter
*/
Expand Down Expand Up @@ -157,17 +253,7 @@ export function gamAdapter(opts: {
}

return (
<aside
id={divId}
aria-label={props.a11yLabel || "Google Ad Manager Advertisement"}
className={`adinject-gam-slot ${props.className || ""}`}
data-adinject-category={props.contentCategory}
style={{
minHeight: props.dimensions?.minHeight || "250px",
width: "100%",
...props.style,
}}
/>
<GamSlotContainer divId={divId} adUnitPath={adUnitPath} props={props} />
);
},
});
Expand Down Expand Up @@ -212,15 +298,7 @@ export function ezoicAdapter(opts: {
);
}

return (
<aside
id={`ezoic-pub-ad-placeholder-${props.slot}`}
aria-label={props.a11yLabel || "Ezoic Advertisement"}
className={`adinject-ezoic-slot ${props.className || ""}`}
data-adinject-category={props.contentCategory}
style={{ minHeight: "250px", width: "100%", ...props.style }}
/>
);
return <EzoicSlotContainer slot={props.slot} props={props} />;
},
});
}
3 changes: 2 additions & 1 deletion src/api/config-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const swrCache = new Map<
*/
export async function fetchAdInjectConfig({
projectId,
baseUrl = typeof process !== "undefined" && process.env?.NEXT_PUBLIC_ADINJECT_API_URL
baseUrl = typeof process !== "undefined" &&
process.env?.NEXT_PUBLIC_ADINJECT_API_URL
? process.env.NEXT_PUBLIC_ADINJECT_API_URL
: "https://adinject.io",
revalidate = 300,
Expand Down
18 changes: 15 additions & 3 deletions src/client/AdFallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,23 @@ export function AdFallback({ fallback, className = "" }: AdFallbackProps) {
? `Advertisement: ${fallback.title}`
: "Sponsored Advertisement"
}
className={`group relative flex flex-col md:flex-row items-center gap-4 rounded-xl border border-primary/20 bg-linear-to-r from-primary/5 via-card to-background p-4 text-card-foreground shadow-xs transition-all hover:border-primary/40 hover:shadow-md ${className}`}
style={{ textDecoration: "none" }}
className={`adinject-fallback-card group relative flex flex-col md:flex-row items-center gap-4 rounded-xl border border-primary/20 bg-gradient-to-r from-primary/5 via-card to-background p-4 text-card-foreground shadow-sm transition-all hover:border-primary/40 hover:shadow-md ${className}`}
style={{
textDecoration: "none",
borderRadius: "12px",
border: "1px solid rgba(var(--primary-rgb, 59, 130, 246), 0.2)",
backgroundColor: "rgba(var(--card-rgb, 255, 255, 255), 0.95)",
color: "inherit",
}}
>
{fallback.imageUrl && (
<div className="relative h-28 w-28 shrink-0 overflow-hidden rounded-lg bg-muted">
<div
className="relative h-28 w-28 shrink-0 overflow-hidden rounded-lg bg-muted"
style={{
backgroundColor: "rgba(0, 0, 0, 0.05)",
borderRadius: "8px",
}}
>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={fallback.imageUrl}
Expand Down
25 changes: 22 additions & 3 deletions src/client/AdInjectFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { AdAdapter } from "../adapters";
import { loadScriptOnce } from "../adapters";
import { injectFeedAds, isAdSlot } from "../transformers/feed-inserter";
import type { AdUnit, PlacementRule } from "../types";
import { useAdInject } from "./AdInjectProvider";
import { InFeedAdCard } from "./InFeedAdCard";

export interface AdInjectFeedProps<T> {
Expand Down Expand Up @@ -56,11 +57,29 @@ export function AdInjectFeed<T>({
startOffset = 1,
maxAds = 4,
gridSpan = "card",
testMode = false,
testMode,
className = "",
renderItem,
renderAd,
}: AdInjectFeedProps<T>) {
const adInjectContext = useAdInject();
const effectiveTestMode =
testMode ?? adUnit?.testMode ?? adInjectContext.testMode ?? false;
const effectiveClient =
adUnit?.client || adInjectContext.client || "ca-pub-XXXXXXXX";
const effectiveFallback = adUnit?.fallback || adInjectContext.defaultFallback;

const resolvedAdUnit: AdUnit = adUnit || {
id: "default-feed-unit",
name: "In-Feed Ad Unit",
client: effectiveClient,
slot: "0000000000",
format: "fluid",
responsive: true,
testMode: effectiveTestMode,
fallback: effectiveFallback,
};

React.useEffect(() => {
if (adapter?.loadScript) {
loadScriptOnce(adapter.name, adapter.loadScript);
Expand All @@ -83,9 +102,9 @@ export function AdInjectFeed<T>({
startOffset: rule?.startOffset ?? startOffset,
maxAdsPerFeed: rule?.maxAdsPerFeed ?? maxAds,
gridSpan: rule?.gridSpan ?? gridSpan,
adUnitId: rule?.adUnitId || adUnit?.id || "default",
adUnitId: rule?.adUnitId || resolvedAdUnit.id,
},
adUnit,
adUnit: resolvedAdUnit,
});

return (
Expand Down
Loading
Loading