0

I am trying to implement ads from google adsense in my angular application. Whenever the component with ads is loaded the ads are not displayed and the error I am getting is:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://tpc.googlesyndication.com') does not match the recipient window's origin ('null').
  1. My first try was with library 'ng2-adsense', https://github.com/scttcper/ng2-adsense. No point to copy paste the code, because usage is really simple as the documentation shows (paste into index.html file the google script in head, in app.module.ts into imports add AdsenseModule with proper id and slot and after just put with optional params). Beside what docs says I tried putting the display html with ad on timeout with like 2 secs delay
  ngAfterViewInit(): void {
    setTimeout(() => {
       this._adTime = true;
    }, 2000);
    
  }

, into index.html I tried 2 scripts the one from docs that has only async src

<script
      async
      src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"
    ></script>

, one what google recommends that has async src, client and cross origin params

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-00000000"
     crossorigin="anonymous"></script>
  1. Instead of using library I tried using code from here Using Google Adsense ads on Angular 2 application.

  2. I have read that this error has something to do with protocols so I tried changing the url in index.html from 'https' into 'http'

<script
      async
      src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"
    ></script>

, also in proxy.config.json changing the api.secure boolean into true

{
  "/api": {
    "target": "https://localhost:4000",
    "secure": true
  }
}

.

  1. Created different ad unit (the first ad unit is already couple days old so it is not a problem with using unit that was just created)

Is this maybe something that will just pulling this error on local machine and I cannot test it without deplying into internet?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Duoxr
  • 1

0 Answers0