Skip to content

Instantly share code, notes, and snippets.

@BeFiveINFO
Last active June 8, 2021 19:27
Show Gist options
  • Save BeFiveINFO/e0f674479365f226a2816d30eab52b9f to your computer and use it in GitHub Desktop.
Save BeFiveINFO/e0f674479365f226a2816d30eab52b9f 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>
@BeFiveINFO
Copy link
Author

Based on original: https://www.npmjs.com/package/vue-adsense by darrynten

@geographicalanalysis
Copy link

Not work for me

@shumiyao
Copy link

shumiyao commented Feb 8, 2020

Will look into it, as I am moving my site to wlesewhere.

@Lowell130
Copy link

not work and you need fix this in your tutorial(maybe): //pagead2.googlesyndication.com/pagead/js/adsbygoogle.js

@BeFiveINFO
Copy link
Author

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