Skip to content
Draft
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
29 changes: 28 additions & 1 deletion crates/js/lib/src/core/config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
// Global configuration storage for the tsjs runtime (mode, logging, etc.).
import { log, LogLevel } from './log';
import type { Config } from './types';
import type { Config, GamConfig } from './types';
import { RequestMode } from './types';

let CONFIG: Config = { mode: RequestMode.FirstParty };

// Lazy import to avoid circular dependencies - GAM integration may not be present
let setGamConfigFn: ((cfg: GamConfig) => void) | null | undefined = undefined;

function getSetGamConfig(): ((cfg: GamConfig) => void) | null {
if (setGamConfigFn === undefined) {
try {
// Dynamic import path - bundler will include if gam integration is present
// eslint-disable-next-line @typescript-eslint/no-require-imports
const gam = require('../integrations/gam/index');
setGamConfigFn = gam.setGamConfig || null;
} catch {
// GAM integration not available
setGamConfigFn = null;
}
}
return setGamConfigFn ?? null;
}

// Merge publisher-provided config and adjust the log level accordingly.
export function setConfig(cfg: Config): void {
CONFIG = { ...CONFIG, ...cfg };
const debugFlag = cfg.debug;
const l = cfg.logLevel as LogLevel | undefined;
if (typeof l === 'string') log.setLevel(l);
else if (debugFlag === true) log.setLevel('debug');

// Forward GAM config to the GAM integration if present
if (cfg.gam) {
const setGam = getSetGamConfig();
if (setGam) {
setGam(cfg.gam);
}
}

log.info('setConfig:', cfg);
}

Expand Down
12 changes: 12 additions & 0 deletions crates/js/lib/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,23 @@ export enum RequestMode {
ThirdParty = 'thirdParty',
}

/** GAM interceptor configuration. */
export interface GamConfig {
/** Enable the GAM interceptor. Defaults to false. */
enabled?: boolean;
/** Only intercept bids from these bidders. Empty array = all bidders. */
bidders?: string[];
/** Force render Prebid creative even if GAM returned a line item. Defaults to false. */
forceRender?: boolean;
}

export interface Config {
debug?: boolean;
logLevel?: 'silent' | 'error' | 'warn' | 'info' | 'debug';
/** Select ad serving mode. Default is RequestMode.FirstParty. */
mode?: RequestMode;
/** GAM interceptor configuration. */
gam?: GamConfig;
// Extendable for future fields
[key: string]: unknown;
}
Expand Down
Loading