I have a with an id of "ad". I am trying to put in an adsense ad in there using JavaScript when a user meets a condition. Basically when a user meets a certain condition, ads will be shown.
This is my code:
if ($resultTot = $db->query($queryTot)) 
    {
        $data = $resultTot->fetch_assoc();
     if($data["total"]>1)
        {
                echo "<script>
                    document.getElementById('ad').innerHTML = 'async src='//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'
<!-- YC2 ads -->
<ins class='adsbygoogle'
     style='display:block'
     data-ad-client='ca-pub-4557496244647182'
     data-ad-slot='4151529047'
     data-ad-format='auto'></ins>
(adsbygoogle = window.adsbygoogle || []).push({});
                </script>";
     }
  }
When I use document.getElementId() to change let's say a p tag, it works. I just can't get the adsense to display. Any ideas on how I can add it in there and why my code isn't working?