next-google-ads
Version:
Google AdSense component for Next.js with optimized script loading
437 lines (436 loc) • 12.9 kB
JavaScript
import re from "react";
import O from "next/script";
var E = { exports: {} }, g = {};
var D;
function ae() {
if (D) return g;
D = 1;
var a = Symbol.for("react.transitional.element"), o = Symbol.for("react.fragment");
function s(l, n, u) {
var f = null;
if (u !== void 0 && (f = "" + u), n.key !== void 0 && (f = "" + n.key), "key" in n) {
u = {};
for (var m in n)
m !== "key" && (u[m] = n[m]);
} else u = n;
return n = u.ref, {
$$typeof: a,
type: l,
key: f,
ref: n !== void 0 ? n : null,
props: u
};
}
return g.Fragment = o, g.jsx = s, g.jsxs = s, g;
}
var b = {};
var M;
function te() {
return M || (M = 1, process.env.NODE_ENV !== "production" && (function() {
function a(e) {
if (e == null) return null;
if (typeof e == "function")
return e.$$typeof === Q ? null : e.displayName || e.name || null;
if (typeof e == "string") return e;
switch (e) {
case A:
return "Fragment";
case J:
return "Profiler";
case G:
return "StrictMode";
case X:
return "Suspense";
case H:
return "SuspenseList";
case Z:
return "Activity";
}
if (typeof e == "object")
switch (typeof e.tag == "number" && console.error(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
), e.$$typeof) {
case U:
return "Portal";
case V:
return e.displayName || "Context";
case q:
return (e._context.displayName || "Context") + ".Consumer";
case z:
var r = e.render;
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case B:
return r = e.displayName || null, r !== null ? r : a(e.type) || "Memo";
case k:
r = e._payload, e = e._init;
try {
return a(e(r));
} catch {
}
}
return null;
}
function o(e) {
return "" + e;
}
function s(e) {
try {
o(e);
var r = !1;
} catch {
r = !0;
}
if (r) {
r = console;
var t = r.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t.call(
r,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
i
), o(e);
}
}
function l(e) {
if (e === A) return "<>";
if (typeof e == "object" && e !== null && e.$$typeof === k)
return "<...>";
try {
var r = a(e);
return r ? "<" + r + ">" : "<...>";
} catch {
return "<...>";
}
}
function n() {
var e = x.A;
return e === null ? null : e.getOwner();
}
function u() {
return Error("react-stack-top-frame");
}
function f(e) {
if (C.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning) return !1;
}
return e.key !== void 0;
}
function m(e, r) {
function t() {
I || (I = !0, console.error(
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
r
));
}
t.isReactWarning = !0, Object.defineProperty(e, "key", {
get: t,
configurable: !0
});
}
function R() {
var e = a(this.type);
return $[e] || ($[e] = !0, console.error(
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
)), e = this.props.ref, e !== void 0 ? e : null;
}
function T(e, r, t, i, y, j) {
var d = t.ref;
return e = {
$$typeof: N,
type: e,
key: r,
props: t,
_owner: i
}, (d !== void 0 ? d : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: R
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: 0
}), Object.defineProperty(e, "_debugInfo", {
configurable: !1,
enumerable: !1,
writable: !0,
value: null
}), Object.defineProperty(e, "_debugStack", {
configurable: !1,
enumerable: !1,
writable: !0,
value: y
}), Object.defineProperty(e, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: j
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
}
function _(e, r, t, i, y, j) {
var d = r.children;
if (d !== void 0)
if (i)
if (K(d)) {
for (i = 0; i < d.length; i++)
S(d[i]);
Object.freeze && Object.freeze(d);
} else
console.error(
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
);
else S(d);
if (C.call(r, "key")) {
d = a(e);
var p = Object.keys(r).filter(function(ee) {
return ee !== "key";
});
i = 0 < p.length ? "{key: someKey, " + p.join(": ..., ") + ": ...}" : "{key: someKey}", L[d + i] || (p = 0 < p.length ? "{" + p.join(": ..., ") + ": ...}" : "{}", console.error(
`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,
i,
d,
p,
d
), L[d + i] = !0);
}
if (d = null, t !== void 0 && (s(t), d = "" + t), f(r) && (s(r.key), d = "" + r.key), "key" in r) {
t = {};
for (var h in r)
h !== "key" && (t[h] = r[h]);
} else t = r;
return d && m(
t,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), T(
e,
d,
t,
n(),
y,
j
);
}
function S(e) {
P(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === k && (e._payload.status === "fulfilled" ? P(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
}
function P(e) {
return typeof e == "object" && e !== null && e.$$typeof === N;
}
var v = re, N = Symbol.for("react.transitional.element"), U = Symbol.for("react.portal"), A = Symbol.for("react.fragment"), G = Symbol.for("react.strict_mode"), J = Symbol.for("react.profiler"), q = Symbol.for("react.consumer"), V = Symbol.for("react.context"), z = Symbol.for("react.forward_ref"), X = Symbol.for("react.suspense"), H = Symbol.for("react.suspense_list"), B = Symbol.for("react.memo"), k = Symbol.for("react.lazy"), Z = Symbol.for("react.activity"), Q = Symbol.for("react.client.reference"), x = v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, C = Object.prototype.hasOwnProperty, K = Array.isArray, w = console.createTask ? console.createTask : function() {
return null;
};
v = {
react_stack_bottom_frame: function(e) {
return e();
}
};
var I, $ = {}, Y = v.react_stack_bottom_frame.bind(
v,
u
)(), F = w(l(u)), L = {};
b.Fragment = A, b.jsx = function(e, r, t) {
var i = 1e4 > x.recentlyCreatedOwnerStacks++;
return _(
e,
r,
t,
!1,
i ? Error("react-stack-top-frame") : Y,
i ? w(l(e)) : F
);
}, b.jsxs = function(e, r, t) {
var i = 1e4 > x.recentlyCreatedOwnerStacks++;
return _(
e,
r,
t,
!0,
i ? Error("react-stack-top-frame") : Y,
i ? w(l(e)) : F
);
};
})()), b;
}
var W;
function oe() {
return W || (W = 1, process.env.NODE_ENV === "production" ? E.exports = ae() : E.exports = te()), E.exports;
}
var c = oe();
const ne = ({
className: a = "",
style: o = {
display: "block",
width: "728px",
height: "90px"
},
format: s = "auto",
layout: l = "",
layoutKey: n = "",
responsive: u = "false",
client: f,
slot: m,
npaMode: R = !1,
adTest: T,
adChannel: _
}) => /* @__PURE__ */ c.jsx(
"ins",
{
className: `${a} adsbygoogle`,
style: o,
"data-ad-client": f,
"data-ad-slot": m,
"data-ad-layout": l,
"data-ad-layout-key": n,
"data-ad-format": s,
"data-full-width-responsive": u,
"data-npa-mode": R ? "1" : void 0,
"data-adtest": T,
"data-ad-channel": _
}
), de = ({
className: a = "",
style: o = { display: "block", textAlign: "center" },
client: s,
slot: l,
npaMode: n = !1
}) => /* @__PURE__ */ c.jsx(
"ins",
{
className: `${a} adsbygoogle`,
style: o,
"data-ad-client": s,
"data-ad-slot": l,
"data-ad-format": "fluid",
"data-ad-layout": "in-article",
"data-npa-mode": n ? "1" : void 0
}
), ue = ({
className: a = "",
style: o = { display: "block" },
client: s,
slot: l,
layoutKey: n,
npaMode: u = !1
}) => /* @__PURE__ */ c.jsx(
"ins",
{
className: `${a} adsbygoogle`,
style: o,
"data-ad-client": s,
"data-ad-slot": l,
"data-ad-format": "fluid",
"data-ad-layout": "in-feed",
"data-ad-layout-key": n,
"data-npa-mode": u ? "1" : void 0
}
), ce = ({
className: a = "",
style: o = { display: "block" },
client: s,
slot: l,
format: n = "autorelaxed",
npaMode: u = !1
}) => /* @__PURE__ */ c.jsx(
"ins",
{
className: `${a} adsbygoogle`,
style: o,
"data-ad-client": s,
"data-ad-slot": l,
"data-ad-format": n,
"data-npa-mode": u ? "1" : void 0
}
), fe = ({
client: a,
slot: o,
position: s = "bottom",
collapsible: l = !0,
npaMode: n = !1
}) => /* @__PURE__ */ c.jsx(
"ins",
{
className: "adsbygoogle",
style: { display: "block" },
"data-ad-client": a,
"data-ad-slot": o,
"data-ad-format": "anchor",
"data-anchor-position": s,
"data-collapsible": l ? "true" : "false",
"data-npa-mode": n ? "1" : void 0
}
), me = ({
client: a,
config: o,
consentMode: s,
npaMode: l = !1
}) => a ? /* @__PURE__ */ c.jsxs(c.Fragment, { children: [
s && /* @__PURE__ */ c.jsx(
O,
{
id: "google-consent-mode-v2",
strategy: "beforeInteractive",
dangerouslySetInnerHTML: {
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', ${JSON.stringify(s)});
`
}
}
),
/* @__PURE__ */ c.jsx(
O,
{
id: "google-adsense-auto",
src: "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js",
"data-ad-client": a,
crossOrigin: "anonymous",
strategy: "afterInteractive",
"data-npa-mode": l ? "1" : void 0,
onLoad: () => {
typeof window < "u" && o?.enableAutoAds && (window.adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: a,
enable_page_level_ads: !0,
...o.adDensity && { ad_density: o.adDensity },
...o.enableAdIntents && { ad_intents: !0 }
});
}
}
)
] }) : null, se = ({ client: a, npaMode: o = !1, crossOrigin: s = !0 }) => a ? /* @__PURE__ */ c.jsx(
O,
{
id: "google-adsense",
src: "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js",
"data-ad-client": a,
strategy: "afterInteractive",
crossOrigin: s ? "anonymous" : void 0,
"data-npa-mode": o ? "1" : void 0,
onLoad: () => {
try {
(window.adsbygoogle = window.adsbygoogle || []).push({});
} catch (l) {
console.error("AdSense error:", l);
}
}
}
) : null, pe = (a) => /* @__PURE__ */ c.jsxs(c.Fragment, { children: [
/* @__PURE__ */ c.jsx(se, { client: a.client, npaMode: a.npaMode }),
/* @__PURE__ */ c.jsx(ne, { ...a })
] });
export {
fe as AnchorAd,
me as AutoAdsScript,
pe as GoogleAdsense,
ne as GoogleAdsenseWidget,
de as InArticleAd,
ue as InFeedAd,
ce as MultiplexAd,
se as NextGoogleAdsenseScript,
pe as default
};
//# sourceMappingURL=index.mjs.map