@bhooai/nexus-ads
v3.0.2
Published
Google AdSense module: Management API v2 client, reporting builder, display snippets.
Readme
@bhooai/nexus-ads
Google AdSense module (publisher-side): AdSense Management API v2 client, reporting builder, and frontend display-snippet helpers.
Exports
createAdSense(config, opts)→AdSenseClient.AdSenseClient—listAccounts(),listAdClients(),listSites(),listAdUnits(),generateReport(),earningsReport().- ReportBuilder — fluent reporting params +
earningsReportOptions(),topPagesReportOptions(). adsenseScript(),autoAdsScript(),adUnit(),normalizeAdClient()— framework-agnostic HTML strings (work withnexus-futurehtml/raw).fetchTransport— the default transport helper.- Types for config, accounts, ad clients, sites, ad units, reports.
OAuth2 credentials (adsense.readonly scope) are configured via
NEXUS_ADS_* / nexus.config.ts (ads: { enabled, publisherId, clientId,
clientSecret, refreshToken, accountId? }). Tests mock the HTTP transport
(no live AdSense calls).
OAuth consent flow (obtain a refresh token)
buildAuthorizeUrl({ clientId, redirectUri, state? })— consent URL withaccess_type=offline+prompt=consentso a refresh token is issued.redirectUrimust be registered on the Google Cloud OAuth web client.exchangeCode({ clientId, clientSecret, code, redirectUri })— exchange the returned?code=...for tokens; persistrefreshTokenasNEXUS_ADS_REFRESH_TOKEN(gitignored.env, never in git).
Display snippet CSP
Allow script-src https://pagead2.googlesyndication.com and
frame-src https://googleads.g.doubleclick.net. For GDPR, gate the loader
behind consent and consider data-npa-on-unknown-consent.
