Easy AdSense for Angular Applications
Demo: https://scttcper.github.io/ng2-adsense/
npm install ng2-adsense
Use the standard AdSense code somewhere in your <head></head>
as you normally would
<script async src=//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js></script>
Add AdsenseModule to the imports of your NgModule
import { AdsenseModule } from 'ng2-adsense';
@NgModule({
imports: [
// shown passing global defaults (optional)
AdsenseModule.forRoot({
adClient: 'ca-pub-7640562161899788',
adSlot: 7259870550,
}),
...
Uses global defaults which can be overriden via inputs
<ng-adsense></ng-adsense>
input | type | description |
---|---|---|
adClient | string | account ca-pub-XXXXXXXXXXXXXXXX |
adSlot | string/number | ad slot/number |
adFormat | string | adsense ad format |
adRegion | string | older adsense code to make all ads on page the same |
display | string | element display style |
height | number | element height in px |
width | number | element width in px |
layout | string | used for in-feed ads |
layoutKey | string | used for in-feed ads |
pageLevelAds | boolean | enable page-level ads |
timeOutRetry | boolean | on first load sometimes adsense is not ready. retry's push after x ms |
adtest | string | sets up some sort of google test ad |
<ng-adsense
[adClient]="'ca-pub-7640562161899788'"
[adSlot]="7259870550"
[display]="'inline-block'"
[width]="320"
[height]="108">
</ng-adsense>