UNPKG

next-google-adsense

Version:
19 lines (18 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GoogleAdSense = void 0; const tslib_1 = require("tslib"); const script_1 = tslib_1.__importDefault(require("next/script")); const react_1 = tslib_1.__importDefault(require("react")); const utils_1 = require("./utils"); const GoogleAdSense = (_a) => { var _b; var { publisherId, isAutoAd = false, debug = false } = _a, props = tslib_1.__rest(_a, ["publisherId", "isAutoAd", "debug"]); const _publisherId = (_b = process.env.NEXT_PUBLIC_ADSENSE_PUBLISHER_ID) !== null && _b !== void 0 ? _b : publisherId; if (!(0, utils_1.isPublisherId)(_publisherId)) { console.error("❌ [next-google-adsense] Invalid publisherId. It should be like this: pub-xxxxxxxxxxxxxxxx, there is a total of 16 digits behind pub-"); return null; } return (react_1.default.createElement(script_1.default, Object.assign({ async: true, src: `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-${_publisherId}${debug ? "google_console=1" : ""}`, strategy: isAutoAd ? "lazyOnload" : "afterInteractive", crossOrigin: "anonymous" }, props))); }; exports.GoogleAdSense = GoogleAdSense;