Paste Google Adsense code into display Ionic breaks
In this simple Codepen demo , I have a panel and a slider. Works fine, but if I add Google Adsense code then display is broken. How do I insert the Adsense code to display my ad at the top of a web page.
What I mean by "display is broken": the bar overlays the start of the ionic content (hello1 hello2). I've already put class = "has-header" in <ion-content>.
NB I am using the Ionic framework for both a mobile site and (next step) for a hybrid app. I don't expect the ad to work in native code. I just need to display an Adsense ad on a mobile website. Announcement code:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- hybride_320x50 -->
<ins class="adsbygoogle"
style="display:inline-block;width:320px;height:50px"
data-ad-client="ca-pub-4134311660880303"
data-ad-slot="1861097476"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
Ionic page skeleton:
- header / angularjs
- Google ad
- bar
- ionic content
- Content
- slider
- Content
source to share
I would recommend that you use AdMob. I wrote this native plugin that supports ionic: https://github.com/appfeel/admob-google-cordova/wiki/Angular.js,-Ionic-apps . In addition, it will also allow you to serve interstitial ads.
ionic plugin add cordova-admob
<script src="lib/angular-admob/angular-admob.js"></script>
<script>
var app = angular.module('myApp', ['admobModule']);
app.config(['admobSvcProvider', function (admobSvcProvider) {
// Optionally you can configure the options here:
admobSvcProvider.setOptions({
publisherId: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
interstitialAdId: "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII",
autoShowBanner: true,
autoShowInterstitial: true
});
}]);
app.run(['admobSvc', function (admobSvc) {
admobSvc.createBannerView();
admob.requestInterstitialAd();
// Handle events:
$rootScope.$on(admobSvc.events.onAdOpened, function onAdOpened(evt, e) {
console.log('adOpened: type of ad:' + e.adType);
});
}]);
</script>
source to share