Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ads personalization settings pauseOnLoad #127

Merged
merged 1 commit into from
Aug 2, 2021
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ added to the `<head>` section of your pages.
| `analyticsDomainName` | String | Google Analytics Account Domain (if linking analytics with AdSense, i.e. `example.com`).
| `overlayBottom` | Boolean | Enable Adsense Anchor Ads to show at bottom. Default is `false`. Refer to the AdSense docs for details.
| `onPageLoad` | Boolean | Loads Adsense script after page loade. Default is `false`.
| `pauseOnLoad` | Boolean | Pauses ad requests to obtain user consent to use cookies or other local storage in accordance with the GDPR. Refer to the AdSense docs for details. `false`.
| `test` | Boolean | Force AdSense into _test_ mode (see below).

### Test mode
Expand Down
8 changes: 6 additions & 2 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const Defaults = {
analyticsDomainName: '',
overlayBottom: false,
test: false,
onPageLoad: false
onPageLoad: false,
pauseOnLoad: false
}

// Default client ID for testing
Expand All @@ -30,6 +31,7 @@ module.exports = function nuxtAdSense (moduleOptions = {}) {
options.analyticsDomainName = options.analyticsDomainName || ''
options.overlayBottom = Boolean(options.overlayBottom)
options.onPageLoad = Boolean(options.onPageLoad)
options.pauseOnLoad = Boolean(options.pauseOnLoad)

if (this.options.dev && process.env.NODE_ENV !== 'production') {
// If in DEV mode, place ads in 'test' state automatically
Expand Down Expand Up @@ -79,14 +81,16 @@ module.exports = function nuxtAdSense (moduleOptions = {}) {
this.options.head.script.push({
hid: 'adsbygoogle',
innerHTML: ensureScriptExecuteOnce(
`(window.adsbygoogle = window.adsbygoogle || []).push(${adsenseScript});`
`(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=${options.pauseOnLoad ? '1' : '0'};
(window.adsbygoogle = window.adsbygoogle || []).push(${adsenseScript});`
)
})
} else {
this.options.head.script.push({
hid: 'adsbygoogle',
innerHTML: ensureScriptExecuteOnce(
`(window.adsbygoogle = window.adsbygoogle || []).onload = function () {
(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=${options.pauseOnLoad ? '1' : '0'};
[].forEach.call(document.getElementsByClassName('adsbygoogle'), function () { adsbygoogle.push(${adsenseScript}); })
};`
)
Expand Down