Skip to content
Angular Adsense Component
TypeScript HTML CSS JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src fix: allow angular 9 peer dependencies Oct 15, 2019
.codecov.yml chore: fix semantic release May 29, 2018
.editorconfig upgrade cli Nov 24, 2016
.gitignore chore: ignore yarn.lock Jun 2, 2019
LICENSE
README.md Fix package name in readme (#349) Jun 15, 2019
angular.json
browserslist chore: use netlify Jun 2, 2019
build.ts fix: remove angular 7 warning on install, closes #310 Nov 2, 2018
circle.yml fix: update dependencies Oct 15, 2019
karma.conf.js chore: upgrade to angular 8, use circleci May 10, 2019
package-lock.json fix: update dependencies Oct 15, 2019
package.json fix: allow angular 9 peer dependencies Oct 15, 2019
renovate.json fix: update dependencies Oct 15, 2019
tsconfig.app.json chore: upgrade to angular 8, use circleci May 10, 2019
tsconfig.json
tsconfig.spec.json chore: upgrade to angular 8, use circleci May 10, 2019
tslint.json

README.md

ng2-adsense NPM version build status coverage status

Easy AdSense for Angular Applications

Demo: https://ng2-adsense.xmplaylist.com/

Install

npm install ng2-adsense

Dependencies

Latest version available for each version of Angular

ng2-adsense Angular
5.4.3 5.x 6.x 7.x
>6.0.0 8.x

Use

Add adsense code

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>

Import NgModule

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,
    }),
    ...

Show Ad

Uses global defaults which can be overriden via inputs

<ng-adsense></ng-adsense>

Inputs

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
className string add custom class names to the "ins" element
<ng-adsense
  [adClient]="'ca-pub-7640562161899788'"
  [adSlot]="7259870550"
  [display]="'inline-block'"
  [width]="320"
  [height]="108"
></ng-adsense>
You can’t perform that action at this time.