Skip to content

Instantly share code, notes, and snippets.

@cossssmin
Forked from BeFiveINFO/components-Adsense.vue
Created March 18, 2019 09:52
Show Gist options
  • Save cossssmin/13acc7ee826d3fb0189e8dd277e99620 to your computer and use it in GitHub Desktop.
Save cossssmin/13acc7ee826d3fb0189e8dd277e99620 to your computer and use it in GitHub Desktop.
Adsense for Gridsome
<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>
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
}
)
}
<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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment