🚨 Latest Research:Tanstack npm Packages Compromised in Ongoing Mini Shai-Hulud Supply-Chain Attack.Learn More
Socket
Book a DemoSign in
Socket

@nuxtjs/google-adsense

Package Overview
Dependencies
Maintainers
8
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuxtjs/google-adsense - npm Package Compare versions

Comparing version
2.0.0
to
2.1.0
+127
dist/module.cjs
'use strict';
const kit = require('@nuxt/kit');
const defu = require('defu');
const url = require('url');
const pathe = require('pathe');
const DEFAULTS = {
tag: "adsbygoogle",
pageLevelAds: false,
includeQuery: false,
analyticsUacct: "",
analyticsDomainName: "",
overlayBottom: false,
test: false,
onPageLoad: false,
pauseOnLoad: false
};
const CONFIG_KEY = "google-adsense";
const TEST_ID = "ca-google";
const ADSENSE_URL = "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
const distDir = pathe.resolve(typeof __dirname === "undefined" ? pathe.dirname(url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('module.cjs', document.baseURI).href)))) : __dirname);
const _makeResolve = (base) => {
return (...p) => pathe.resolve(base, ...p);
};
const runtimeDir = pathe.resolve(distDir, "runtime");
const resolveRuntimeDir = _makeResolve(runtimeDir);
const templateDir = pathe.resolve(distDir, "templates");
const resolveTemplateDir = _makeResolve(templateDir);
const module$1 = kit.defineNuxtModule({
meta: {
name: "@nuxtjs/google-adsense",
configKey: CONFIG_KEY,
compatibility: {
nuxt: "^2.15.0 || ^3.0.0-rc.11"
}
},
defaults: (nuxt) => ({
...DEFAULTS,
test: nuxt.options.dev && process.env.NODE_ENV !== "production"
}),
setup(options, nuxt) {
if (options.test) {
kit.logger.info("Test mode enabled - Using Test AdSense ID");
options.id = TEST_ID;
}
if (!options.id || typeof options.id !== "string") {
kit.logger.warn("Invalid AdSense client ID specified");
return;
}
const isNuxt2 = kit.isNuxt2(nuxt);
const useNuxtMeta = (fn) => fn(isNuxt2 ? nuxt.options.head : nuxt.options.app.head);
useNuxtMeta((head) => {
head.script = head.script ?? [];
head.script.push({
hid: "adsbygoogle-script",
defer: true,
crossorigin: "anonymous",
src: `${ADSENSE_URL}?client=${options.id}`
});
const adsenseScript = `{
google_ad_client: "${options.id}",
overlays: {bottom: ${options.overlayBottom}},
${options.pageLevelAds ? "enable_page_level_ads: true" : ""}
}`;
if (!options.onPageLoad) {
head.script.push(
createScriptMeta(
`adsbygoogle.pauseAdRequests=${options.pauseOnLoad ? "1" : "0"};
adsbygoogle.push(${adsenseScript});`)
);
} else {
head.script.push(
createScriptMeta(
`adsbygoogle.onload = function () {
adsbygoogle.pauseAdRequests=${options.pauseOnLoad ? "1" : "0"};
[].forEach.call(document.getElementsByClassName('adsbygoogle'), function () { adsbygoogle.push(${adsenseScript}); })
};`)
);
}
if (options.test) {
head.meta = head.meta ?? [];
head.meta.unshift({
name: "robots",
content: "noindex,noarchive,nofollow"
});
}
});
if (isNuxt2) {
kit.addPluginTemplate({
src: resolveTemplateDir("./plugin.mjs"),
filename: "adsbygoogle.js",
options: {
component: resolveRuntimeDir("./components/Adsbygoogle.vue"),
alias: options.tag
}
});
} else {
kit.addComponentsDir({
path: resolveRuntimeDir("components-v3")
});
}
if (isNuxt2) {
nuxt.options.publicRuntimeConfig[CONFIG_KEY] = defu(
nuxt.options.publicRuntimeConfig[CONFIG_KEY],
options
);
} else {
nuxt.options.runtimeConfig.public[CONFIG_KEY] = defu(
nuxt.options.runtimeConfig.public[CONFIG_KEY],
options
);
}
}
});
function createScriptMeta(script, isNuxt2) {
script = `(window.adsbygoogle = window.adsbygoogle || []); ${script}`;
script = `if (!window.__abg_called){ ${script} window.__abg_called = true;}`;
return {
hid: "adsbygoogle",
innerHTML: script
};
}
module.exports = module$1;
import * as _nuxt_schema from '@nuxt/schema';
interface ModuleOptions {
tag?: string;
id?: string;
analyticsUacct?: string;
analyticsDomainName?: string;
pageLevelAds?: boolean;
includeQuery?: boolean;
overlayBottom?: boolean;
onPageLoad?: boolean;
pauseOnLoad?: boolean;
test?: boolean;
}
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
export { ModuleOptions, _default as default };
{
"name": "@nuxtjs/google-adsense",
"configKey": "google-adsense",
"compatibility": {
"nuxt": "^2.15.0 || ^3.0.0-rc.11"
},
"version": "2.1.0"
}
import { defineNuxtModule, logger, isNuxt2, addPluginTemplate, addComponentsDir } from '@nuxt/kit';
import defu from 'defu';
import { fileURLToPath } from 'url';
import { resolve, dirname } from 'pathe';
// -- Unbuild CommonJS Shims --
import __cjs_url__ from 'url';
import __cjs_path__ from 'path';
import __cjs_mod__ from 'module';
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
const __dirname = __cjs_path__.dirname(__filename);
const require = __cjs_mod__.createRequire(import.meta.url);
const DEFAULTS = {
tag: "adsbygoogle",
pageLevelAds: false,
includeQuery: false,
analyticsUacct: "",
analyticsDomainName: "",
overlayBottom: false,
test: false,
onPageLoad: false,
pauseOnLoad: false
};
const CONFIG_KEY = "google-adsense";
const TEST_ID = "ca-google";
const ADSENSE_URL = "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
const distDir = resolve(typeof __dirname === "undefined" ? dirname(fileURLToPath(import.meta.url)) : __dirname);
const _makeResolve = (base) => {
return (...p) => resolve(base, ...p);
};
const runtimeDir = resolve(distDir, "runtime");
const resolveRuntimeDir = _makeResolve(runtimeDir);
const templateDir = resolve(distDir, "templates");
const resolveTemplateDir = _makeResolve(templateDir);
const module = defineNuxtModule({
meta: {
name: "@nuxtjs/google-adsense",
configKey: CONFIG_KEY,
compatibility: {
nuxt: "^2.15.0 || ^3.0.0-rc.11"
}
},
defaults: (nuxt) => ({
...DEFAULTS,
test: nuxt.options.dev && process.env.NODE_ENV !== "production"
}),
setup(options, nuxt) {
if (options.test) {
logger.info("Test mode enabled - Using Test AdSense ID");
options.id = TEST_ID;
}
if (!options.id || typeof options.id !== "string") {
logger.warn("Invalid AdSense client ID specified");
return;
}
const isNuxt2$1 = isNuxt2(nuxt);
const useNuxtMeta = (fn) => fn(isNuxt2$1 ? nuxt.options.head : nuxt.options.app.head);
useNuxtMeta((head) => {
head.script = head.script ?? [];
head.script.push({
hid: "adsbygoogle-script",
defer: true,
crossorigin: "anonymous",
src: `${ADSENSE_URL}?client=${options.id}`
});
const adsenseScript = `{
google_ad_client: "${options.id}",
overlays: {bottom: ${options.overlayBottom}},
${options.pageLevelAds ? "enable_page_level_ads: true" : ""}
}`;
if (!options.onPageLoad) {
head.script.push(
createScriptMeta(
`adsbygoogle.pauseAdRequests=${options.pauseOnLoad ? "1" : "0"};
adsbygoogle.push(${adsenseScript});`)
);
} else {
head.script.push(
createScriptMeta(
`adsbygoogle.onload = function () {
adsbygoogle.pauseAdRequests=${options.pauseOnLoad ? "1" : "0"};
[].forEach.call(document.getElementsByClassName('adsbygoogle'), function () { adsbygoogle.push(${adsenseScript}); })
};`)
);
}
if (options.test) {
head.meta = head.meta ?? [];
head.meta.unshift({
name: "robots",
content: "noindex,noarchive,nofollow"
});
}
});
if (isNuxt2$1) {
addPluginTemplate({
src: resolveTemplateDir("./plugin.mjs"),
filename: "adsbygoogle.js",
options: {
component: resolveRuntimeDir("./components/Adsbygoogle.vue"),
alias: options.tag
}
});
} else {
addComponentsDir({
path: resolveRuntimeDir("components-v3")
});
}
if (isNuxt2$1) {
nuxt.options.publicRuntimeConfig[CONFIG_KEY] = defu(
nuxt.options.publicRuntimeConfig[CONFIG_KEY],
options
);
} else {
nuxt.options.runtimeConfig.public[CONFIG_KEY] = defu(
nuxt.options.runtimeConfig.public[CONFIG_KEY],
options
);
}
}
});
function createScriptMeta(script, isNuxt2) {
script = `(window.adsbygoogle = window.adsbygoogle || []); ${script}`;
script = `if (!window.__abg_called){ ${script} window.__abg_called = true;}`;
return {
hid: "adsbygoogle",
innerHTML: script
};
}
export { module as default };
import { ModuleOptions } from './module'
declare module '@nuxt/schema' {
interface NuxtConfig { ['google-adsense']?: Partial<ModuleOptions> }
interface NuxtOptions { ['google-adsense']?: ModuleOptions }
}
export { ModuleOptions, default } from './module'
+2
-0
<script>
// eslint-disable-next-line import/named
import { h } from 'vue'
import { useRuntimeConfig } from '#imports'

@@ -5,0 +7,0 @@ export default {

+6
-2

@@ -104,5 +104,9 @@ declare namespace _default {

}
function render(): any;
function render(): any;
function render(): import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}>;
function render(): import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}>;
}
export default _default;
<script>
export default {

@@ -3,0 +4,0 @@ props: {

{
"name": "@nuxtjs/google-adsense",
"version": "2.0.0",
"description": "Google Adsense Module for Nuxt.js",
"version": "2.1.0",
"description": "Google AdSense Module for Nuxt.js",
"license": "MIT",
"repository": "https://github.com/nuxt-community/adsense-module",
"type": "module",
"exports": {
".": "./dist/index.mjs"
".": {
"import": "./dist/module.mjs",
"require": "./dist/module.cjs"
}
},
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"scripts": {
"build": "unbuild",
"lint": "eslint --ext .vue,.ts,.js .",
"test": "yarn lint",
"release": "standard-version && git push --follow-tags && npm publish"
},
"main": "./dist/module.cjs",
"types": "./dist/types.d.ts",
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"prepack": "nuxt-module-build",
"dev": "nuxt dev playground",
"dev:nuxt2": "cd nuxt2-playground && yarn dev",
"dev:build": "nuxt build playground",
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
"test": "yarn vitest run",
"release": "standard-version"
},
"dependencies": {
"pathe": "^0.2.0"
"@nuxt/kit": "^3.0.0-rc.12"
},
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "^8.0.0",
"codecov": "^3.8.3",
"eslint": "^8.5.0",
"eslint-plugin-vue": "^8.2.0",
"jest": "^27.4.5",
"jsdom": "^19.0.0",
"nuxt": "^2.15.8",
"standard-version": "^9.3.2",
"unbuild": "^0.6.7"
"@nuxt/module-builder": "^0.2.0",
"@nuxt/schema": "^3.0.0-rc.12",
"@nuxt/test-utils": "^3.0.0-rc.12",
"@nuxtjs/eslint-config-typescript": "^11.0.0",
"eslint": "^8.26.0",
"nuxt": "^3.0.0-rc.12",
"standard-version": "^9.5.0",
"vitest": "^0.24.3"
},
"keywords": [
"AdSense",
"Google",
"Nuxt",
"NuxtJS",
"Nuxt.js",
"PWA",
"SSR",
"Vue",
"VueJS",
"Vue2",
"VueRouter",
"vue-router",
"Web"
]
"resolutions": {
"@nuxtjs/google-adsense": "link:./"
}
}
+10
-10

@@ -63,4 +63,4 @@ # Google AdSense

| -------- | ---- | -----------
| `id` | String | Your Google Adsense Publisher client ID (i.e. `ca-pub-#########`). **Required** when not in test mode.
| `pageLevelAds` | Boolean | Enable Adsense Page Level Ads. Default is `false`. Refer to the AdSense docs for details.
| `id` | String | Your Google AdSense Publisher client ID (i.e. `ca-pub-#########`). **Required** when not in test mode.
| `pageLevelAds` | Boolean | Enable AdSense Page Level Ads. Default is `false`. Refer to the AdSense docs for details.
| `tag` | String | AdSense component tag name. Defaults to `adsbygoogle`.

@@ -96,3 +96,3 @@ | `includeQuery` | Boolean | When `false`, only `$route.path` is checked for changes. If set to `true` `$route.query` will also be taken into account. The default is `false`.

Use the `ad-slot` property to specify your google adsense ad slot value (specified as a string)
Use the `ad-slot` property to specify your Google AdSense ad slot value (specified as a string)

@@ -104,7 +104,7 @@ **Component props:**

| `ad-slot` | String | Google Adsense adslot. **This prop is required when not in test mode**. Refer to your AdSense account for ad-slot values.
| `ad-format` | String | Defaults to `'auto'`. Refer to the adsense docs for other options
| `ad-format` | String | Defaults to `'auto'`. Refer to the AdSense docs for other options
| `ad-style` | Object | Styles to apply to the rendered `<ins>` element. Default: `{ display: 'block' }`. Refer to VueJS [style binding docs](https://vuejs.org/v2/guide/class-and-style.html#Object-Syntax-1) for the Object format.
| `ad-layout` | String | Optional. Refer to the adsense docs
| `ad-layout-key` | String | Optional. Refer to the adsense docs
| `page-url` | String | Optional. Set a reference page URL (of similar content) if the ad is on a page that requires authentication. When set, this prop must be a fully qualified URL (inclcuding protocol and hostname).
| `ad-layout` | String | Optional. Refer to the AdSense docs
| `ad-layout-key` | String | Optional. Refer to the AdSense docs
| `page-url` | String | Optional. Set a reference page URL (of similar content) if the ad is on a page that requires authentication. When set, this prop must be a fully qualified URL (including protocol and hostname).
| `include-query` | Boolean | Override global option `includeQuery` on a per ad basis. Ensure all ads on a page have the same setting.

@@ -116,3 +116,3 @@ | `analytics-uacct` | String | Google Analytics Account ID (if linking analytics with AdSense, i.e. `UA-#######-#`). Defaults to the value specified in the plugin option `analyticsUacct`.

## Automatic updating of Ads
Whenever your route changes, any disaplayed ads will update, just as they would on normal
Whenever your route changes, any displayed ads will update, just as they would on normal
page loads.

@@ -131,3 +131,3 @@

## Background
This module uses a technique developed by the Angular team (with help from Google Adsense)
This module uses a technique developed by the Angular team (with help from Google AdSense)
to handle updating ads on progressive web applications:

@@ -137,3 +137,3 @@ - https://github.com/leonardteo/google-ads-test-angularjs

Each time a new advertisement is requested, the adsense parameter `data-ad-region` is
Each time a new advertisement is requested, the AdSense parameter `data-ad-region` is
updated to a random value. For this reason, you cannot set the `data-ad-region` attribute

@@ -140,0 +140,0 @@ on the `<adsbygoogle />` component.

# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [2.0.0](https://github.com/nuxt-community/adsense-module/compare/v1.4.0...v2.0.0) (2021-12-19)
### Features
* support Nuxt bridge & Nuxt 3 ([#150](https://github.com/nuxt-community/adsense-module/issues/150)) ([155a7bd](https://github.com/nuxt-community/adsense-module/commit/155a7bdf53de4ac3cdc5882842aa7e27dda4862d))
### Bug Fixes
* lint ([47996b5](https://github.com/nuxt-community/adsense-module/commit/47996b5ab5ee22a3796308270b6a48602e5c83e3))
* module exports ([66090b7](https://github.com/nuxt-community/adsense-module/commit/66090b7d01e82ae45ddfed20d827c0b34d9ea3a6))
* page level ads error ([#135](https://github.com/nuxt-community/adsense-module/issues/135)) ([e789f62](https://github.com/nuxt-community/adsense-module/commit/e789f62a090fcef2b7ae142ec80e01eab8978da1))
* **module:** add window as property owner ([#138](https://github.com/nuxt-community/adsense-module/issues/138)) ([cd86b0c](https://github.com/nuxt-community/adsense-module/commit/cd86b0c61b05e9d5374485c7b40d916b8eda4a79))
## [1.4.0](https://github.com/nuxt-community/adsense-module/compare/v1.3.0...v1.4.0) (2021-08-02)
### Features
* ads personalization settings `pauseOnLoad` ([#127](https://github.com/nuxt-community/adsense-module/issues/127)) ([ad93745](https://github.com/nuxt-community/adsense-module/commit/ad93745701dd81cdc869ed0371976ecc3fd8043b))
* Allow config options via `publicRuntimeConfig` ([#120](https://github.com/nuxt-community/adsense-module/issues/120)) ([752b176](https://github.com/nuxt-community/adsense-module/commit/752b176bb2fed4c66961866c5e2903bd600496db))
* Improving ad performance with the new AdSense code ([#128](https://github.com/nuxt-community/adsense-module/issues/128)) ([fa8e5c5](https://github.com/nuxt-community/adsense-module/commit/fa8e5c504bf2857680a1f34d6555f55ce250c423))
### Bug Fixes
* add data-ad-client attribute ([#116](https://github.com/nuxt-community/adsense-module/issues/116)) ([4d83100](https://github.com/nuxt-community/adsense-module/commit/4d831003697fc52f5719cec6b24c7a3ec571572d))
* do not update unconnected components ([#107](https://github.com/nuxt-community/adsense-module/issues/107)) ([345703b](https://github.com/nuxt-community/adsense-module/commit/345703bfa11f96ec3eb9aaec842753a068001b02))
* use defer in script load ([#122](https://github.com/nuxt-community/adsense-module/issues/122)) ([5e6ff50](https://github.com/nuxt-community/adsense-module/commit/5e6ff507ad2f3fabd746bbe7e7e9dcb2cab6af94))
## [1.3.0](https://github.com/nuxt-community/adsense-module/compare/v1.3.0-rc.1...v1.3.0) (2020-12-23)
## [1.3.0-rc.1](https://github.com/nuxt-community/adsense-module/compare/v1.2.1...v1.3.0-rc.1) (2020-12-17)
### Bug Fixes
* ensure script calls once ([#98](https://github.com/nuxt-community/adsense-module/issues/98)) ([aa811ed](https://github.com/nuxt-community/adsense-module/commit/aa811ed7800bddad120c0917b298e0a06411f835))
### [1.2.1](https://github.com/nuxt-community/adsense-module/compare/v1.2.0...v1.2.1) (2020-12-16)
### Bug Fixes
* prevent duplicate script injection ([#95](https://github.com/nuxt-community/adsense-module/issues/95)) ([4b25dfa](https://github.com/nuxt-community/adsense-module/commit/4b25dfa4d99b250e25f02e638f57e64ca0edf971))
## [1.2.0](https://github.com/nuxt-community/adsense-module/compare/v1.1.3...v1.2.0) (2020-10-26)
### Features
* Add support for full width responsive prop ([#38](https://github.com/nuxt-community/adsense-module/issues/38)) ([de1a059](https://github.com/nuxt-community/adsense-module/commit/de1a059c72f02814a50e00dbc353bc19a5b0a37c))
* support anchor ads config ([#27](https://github.com/nuxt-community/adsense-module/issues/27)) ([008adba](https://github.com/nuxt-community/adsense-module/commit/008adba057804024ffddbb124aa8d05a68226ef0))
### Bug Fixes
* prevent `adsbygoogle` is not defined error ([#68](https://github.com/nuxt-community/adsense-module/issues/68)) ([d853d9a](https://github.com/nuxt-community/adsense-module/commit/d853d9a36a02447199ad1d27c79f5d1d2a026562))
<a name="1.1.3"></a>
## [1.1.3](https://github.com/nuxt-community/adsense-module/compare/v1.1.2...v1.1.3) (2018-01-16)
### Bug Fixes
* unhandle error ([9556861](https://github.com/nuxt-community/adsense-module/commit/9556861))
<a name="1.1.2"></a>
## [1.1.2](https://github.com/nuxt-community/adsense-module/compare/v1.1.1...v1.1.2) (2017-11-05)
### Features
* **options:** New config option for page level ads
* New initialization script added in `<head>`
<a name="1.1.0"></a>
## [1.1.1](https://github.com/nuxt-community/adsense-module/compare/v1.1.0...v1.1.1) (2017-11-02)
<a name="1.1.0"></a>
## [1.1.0](https://github.com/nuxt-community/adsense-module/compare/v1.0.1...v1.1.0) (2017-11-02)
### Features
* **options:** New configurtion options ([#6](https://github.com/nuxt-community/adsense-module/issues/6)) ([a9f7a29](https://github.com/nuxt-community/adsense-module/commit/a9f7a29))
<a name="1.0.1"></a>
## [1.0.1](https://github.com/nuxt-community/adsense-module/compare/v1.0.0...v1.0.1) (2017-10-27)
### Bug Fixes
* **package.json:** add missing lib ([727ff15](https://github.com/nuxt-community/adsense-module/commit/727ff15))
declare function nuxtAdSense(moduleOptions?: {}): void;
export { nuxtAdSense as default };
import { fileURLToPath } from 'url';
import { resolve, dirname } from 'pathe';
const distDir = resolve(typeof __dirname === "undefined" ? dirname(fileURLToPath(import.meta.url)) : __dirname);
const _makeResolve = (base) => {
return (...p) => resolve(base, ...p);
};
const runtimeDir = resolve(distDir, "runtime");
const resolveRuntimeDir = _makeResolve(runtimeDir);
const templateDir = resolve(distDir, "templates");
const resolveTemplateDir = _makeResolve(templateDir);
const Defaults = {
tag: "adsbygoogle",
id: null,
pageLevelAds: false,
includeQuery: false,
analyticsUacct: "",
analyticsDomainName: "",
overlayBottom: false,
test: false,
onPageLoad: false,
pauseOnLoad: false
};
const TestID = "ca-google";
const AdSenseURL = "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
function nuxtAdSense(moduleOptions = {}) {
const nuxt = this.nuxt;
const isNuxt2 = (nuxt?._version || nuxt?.version || nuxt?.constructor?.version || "").replace(/^v/g, "").startsWith("2.");
const useNuxtMeta = (fn) => fn(isNuxt2 ? nuxt.options.head : nuxt.options.meta);
const options = Object.assign({}, Defaults, nuxt.options["google-adsense"] || moduleOptions);
options.test = Boolean(options.test);
options.pageLevelAds = Boolean(options.pageLevelAds);
options.includeQuery = Boolean(options.includeQuery);
options.analyticsUacct = options.analyticsUacct || "";
options.analyticsDomainName = options.analyticsDomainName || "";
options.overlayBottom = Boolean(options.overlayBottom);
options.onPageLoad = Boolean(options.onPageLoad);
options.pauseOnLoad = Boolean(options.pauseOnLoad);
if (nuxt.options.dev && process.env.NODE_ENV !== "production") {
options.test = true;
}
if (options.test) {
options.id = TestID;
}
if (!options.id || typeof options.id !== "string") {
return;
}
options.tag = options.tag || Defaults.tag;
useNuxtMeta((head) => {
head.script.push({
hid: "adsbygoogle-script",
defer: true,
crossorigin: "anonymous",
src: `${AdSenseURL}?client=${options.id}`
});
head.__dangerouslyDisableSanitizersByTagID = head.__dangerouslyDisableSanitizersByTagID || {};
head.__dangerouslyDisableSanitizersByTagID.adsbygoogle = ["innerHTML"];
const adsenseScript = `{
google_ad_client: "${options.id}",
overlays: {bottom: ${options.overlayBottom}},
${options.pageLevelAds ? "enable_page_level_ads: true" : ""}
}`;
if (!options.onPageLoad) {
head.script.push(createScriptMeta(`adsbygoogle.pauseAdRequests=${options.pauseOnLoad ? "1" : "0"};
adsbygoogle.push(${adsenseScript});`));
} else {
head.script.push(createScriptMeta(`adsbygoogle.onload = function () {
adsbygoogle.pauseAdRequests=${options.pauseOnLoad ? "1" : "0"};
[].forEach.call(document.getElementsByClassName('adsbygoogle'), function () { adsbygoogle.push(${adsenseScript}); })
};`));
}
if (options.test) {
head.meta.unshift({
name: "robots",
content: "noindex,noarchive,nofollow"
});
}
});
if (isNuxt2) {
this.addPlugin({
src: resolveTemplateDir("./plugin.mjs"),
fileName: "adsbygoogle.js",
options: {
component: resolveRuntimeDir("./components/Adsbygoogle.vue"),
alias: options.tag
}
});
} else {
nuxt.hook("components:dirs", (dirs) => {
dirs.push({
path: resolveRuntimeDir("components-v3"),
isAsync: false,
prefix: "",
level: 999
});
});
}
nuxt.options.publicRuntimeConfig["google-adsense"] = {
...options,
...nuxt.options.publicRuntimeConfig["google-adsense"] || {}
};
function createScriptMeta(script) {
script = `(window.adsbygoogle = window.adsbygoogle || []); ${script}`;
script = `if (!window.__abg_called){ ${script} window.__abg_called = true;}`;
return isNuxt2 ? {
hid: "adsbygoogle",
innerHTML: script
} : {
hid: "adsbygoogle",
children: script
};
}
}
export { nuxtAdSense as default };
import Vue from 'vue'
import Adsbygoogle from '<%= relativeToBuild(options.component) %>'
Vue.component('<%= options.alias %>', Adsbygoogle)