Last active
June 8, 2021 19:27
-
-
Save BeFiveINFO/e0f674479365f226a2816d30eab52b9f to your computer and use it in GitHub Desktop.
Adsense for Gridsome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<ins class="adsbygoogle" | |
:data-ad-client="adClient" | |
:data-ad-slot="adSlot" | |
:data-ad-format="adFormat" | |
:style="adStyle"></ins> | |
</template> | |
<script> | |
export default { | |
props: { | |
adClient: { | |
type: String, | |
required: true | |
}, | |
adSlot: { | |
type: String, | |
required: true | |
}, | |
adFormat: { | |
type: String, | |
required: false, | |
default: 'auto' | |
}, | |
adStyle: { | |
type: String, | |
required: false, | |
default: 'display: block' | |
} | |
}, | |
mounted() { | |
(window.adsbygoogle = window.adsbygoogle || []).push({}) | |
} | |
} | |
</script> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue'; | |
// default layout | |
import DefaultLayout from '~/layouts/Default.vue'; | |
export default function (Vue, { head }) { | |
Vue.use(VueDisqus) | |
Vue.component('Layout', DefaultLayout) | |
head.script.push( | |
{ | |
type: 'text/javascript', | |
src: '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js', | |
async: true | |
} | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<Layout> | |
.... insert the following code anywhere in the layout | |
<Adsense | |
class="mb-5" | |
ad-client="ca-pub-XXXXXXXXX" | |
ad-slot="XXXXXXXXXX" | |
ad-style="display:block !important;" | |
ad-format="auto"> | |
</Adsense> | |
.... | |
</Layout> | |
</template> | |
<script> | |
import Adsense from '~/components/Adsense.vue'; | |
export default { | |
components: { | |
Adsense | |
} | |
} | |
</script> |
Not work for me
Will look into it, as I am moving my site to wlesewhere.
not work and you need fix this in your tutorial(maybe): //pagead2.googlesyndication.com/pagead/js/adsbygoogle.js
sorry but I lost my active adsense account (because I let my domain go a while ago),
so I cannot test the script any more.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on original: https://www.npmjs.com/package/vue-adsense by darrynten