원본

https://www.xamarinexpert.it/admob-made-easy/

 

 

In this tutorial I’ll show you how to monetize your Xamarin apps with AdMob using my MTAdmob plugin.

Important: If you receive errors compiling the code for iOS, install the package Xamarin.Google.iOS.MobileAds in your iOS project.

UPDATE 1/May/2019: I’ve released the new version 1.3 thas sovles some issues with iOS and improves performances.

UPDATE: From version 1.2, MTAdmob supports also Google ads rewarded videos for Android and iOS

UPDATE: I’ve added on github the source code of a project to test this Admob plugin. You can find it here: https://github.com/marcojak/TestMTAdmob

To help you to speed up your Xamarin development, I’ve created a set of plugins, one of them is MTAdmob. Thanks to this plugin you can add Admob banners and Insterstitials in just few lines of code. It couldn’t be easier than that and I’ll show you.

Install the plugin

First of all, right click on your Xamarin solution and select “Manage Nuget packages for Solution”

Visual Studio will open a new screen where you can search and install one or more nuget packages. In this case we can search for the MTAdmob plugin. Searching for MarcTron will show you all my packages (I’m sure you can find other useful plugins that I’ve written), and we can select the MTAdmob plugin as showed in the next image.

It’s very important that you install the plugin in your PCL/.Net standard project and in your platform projects (Android, iOS, UWP).

After the Admob plugin is installed we can add banners and insterstitials to our projects.

Add Ads to our project

With version 1.0 the MTAdmob plugin supports banner and interstitials for Android and iOS. If you would like to see the plugin supporting also the UWP platform, let me now and I’ll add the support in a new version.

As I’ve said we can add Banners and Interstitials Admob ads to our project. Let’s start with the Banners

How to add an Admob Banner

An Admob banner is just a view inside our page. It means that we can add it using XAML or C#. First of all let’s see how to add an Admob banner using XAML.

Add an Admob Banner with XAML

In MTAdmob to use an Admob banner I’ve created a custom control called AdView, so to use it we can use this code:

<?xml version="1.0" encoding="utf-8" ?>

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"

             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

             xmlns:controls="clr-namespace:MarcTron.Plugin.Controls;assembly=Plugin.MtAdmob"

             x:Class="Test.MTAdmob.MainPage">

 

<StackLayout>

    <Label Text="Let's test an Admob Banner!"

           HorizontalOptions="Center"

           VerticalOptions="CenterAndExpand" />

    <!-- Place the Admob controls here -->

    <controls:MTAdView></controls:MTAdView>

</StackLayout>

In this example we have created a StackLayout with 2 controls: a label and an AdView (our Admob banner). Easy! Isn’t it???

The AdView control is basically a View so you can use all the properties you can think of like: HorizontalOptions, VerticalOptions, IsVisible…

In addition to these properties, I’ve added in AdView two other properties: AdsId and PersonalizedAds.

AdsId: Allows you to add the Banner Id (you can find it in your Admob account)

PersonalizedAds: This allow you to use non personalized ads. For example in case of GPDR. Of course it’s better to use personalized Ads.

To use these properties you can update the previous code to:

<controls:AdView PersonalizedAds="true" AdsId="xxxxxxxxxxxxxxxxxx"></controls:AdView>

Add an Admob Banner with C#

In case you don’t write your pages with XAML or you write your UI in C# or you want to add your view only in some cases, you can add your Admob Banner using this code:

using MarcTron.Plugin;

...

MTAdView ads = new MTAdView();

Of course you need to attach this View to your layout, but you know how to do it (If not, feel free to ask).

To use the custom properties you can change the previous code to:

...

MTAdView ads = new MTAdView();

ads.AdsId = "xxx";

ads.PersonalizedAds = true;

Also in this case, to add an Admob banner is INCREDIBILY EASY!!!

Global Custom Properties

As you have seen, the properties AdsId and PersonalizedAds belong to a single AdView. It means that you have to set them for every Admob Banner.

To make things even easier I’ve added the option to set these properties only once. To do so, you can use this C# code:

CrossMTAdmob.Current.UserPersonalizedAds = true;

CrossMTAdmob.Current.AdsId = "xxxxxxxxxxxxxxxx";

In this case all your Admob banner will show personalized ads and will have the same Id.

If you set local and global properties, the local ones will have higher priority.

Use of Banner Events

I’ve added 4 events to the Admob banner that you could find nice to have. These events are:

  • AdsClicked When a user clicks on the ads
  • AdsClosed When the user closes the ads
  • AdsImpression Called when an impression is recorded for an ad.
  • AdsOpened When the ads is opened

To use these events you can write this code:

AdView myAds = new AdView();

myAds.AdsClicked += MyAdsAdsClicked;

myAds.AdsClosed += MyAds_AdVClosed;

myAds.AdsImpression += MyAds_AdVImpression;

myAds.AdsOpened += MyAds_AdVOpened;

Of course you can use these events also if you have declared your AdView in your XAML code.

Admob Interstitials

Now that we know how to add Admob banners using my plugin MTAdmob, let’s see how we can add Admob Interstitials. If possible, to add an Admob interstitial is even easier. You just need a single line of code. Don’t you believe me? Look here how to show an Admob interstitial:

CrossMTAdmob.Current.ShowInterstitial("ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx");

I told you!!! That’s it!!! With that line of code you have just showed an Interstitial in you app. Of course you need to replace that string with the Insterstitial ID you can find in your Admob account.

Events for Interstitials

There 3 events that you can use with Interstitials:

OnInterstitialLoaded        When it's loaded

OnInterstitialOpened        When it's opened      

OnInterstitialClosed        When it's closed

Rewarded Video

From version 1.1 the plugin supports the amazing Rewarded Video too.

To show a rewarded video you just need a single line of code:

CrossMTAdmob.Current.ShowRewardedVideo("xx-xxx-xxx-xxxxxxxxxxxxxxxxx/xxxxxxxxxx");

Events for Rewarded videos

There are 7 events that you can use with the Rewarded video Ads:

OnRewarded                          When the user gets a reward

OnRewardedVideoAdClosed             When the ads is closed

OnRewardedVideoAdFailedToLoad       When the ads fails to load

OnRewardedVideoAdLeftApplication    When the users leaves the application

OnRewardedVideoAdLoaded             When the ads is loaded

OnRewardedVideoAdOpened             When the ads is opened

OnRewardedVideoStarted              When the ads starts

Initialization

Before you can use the Admob banners and Interstitials, you need to initialize it. You need to do it only once so it makes sense to initialize it onside the OnCreate method in Android and FinishedLaunching in iOS.

In your Android project add this line in your OnCreate method:

MobileAds.Initialize(ApplicationContext, "ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx");

In your iOS project add this line in your FinishedLaunching method:

MobileAds.Configure("ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx");

If you receive errors compiling the code for iOS, install the package Xamarin.Google.iOS.MobileAds in your iOS project.

ANDROID PROJECT (IMPORTANT)

In your AndroidManifest you should add these lines:

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

 

<application android:label="Test.MTAdmob.Android">

    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>

    <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" />

</application>

Some useful links

Conclusion

This Admob MTAdmob plugin is incredibly easy to use but in case you need help, or you want to suggest a new feature or for any other reason, write me.

 

 

AdMob 에서 정책을 위반 했다면서 광고 게재가 중단되었다.

아래와 같은 메일이 오게된다.

 

 

정책 센터에서 보기 를 클릭하면

아래처럼 정책 센터에 왜 중단이 되었는지 사유가 나온다.

 

참고로 사이트 행동 : 탐색 은 아래와 같은 사유다

 

 

검토 요청을 하기 전에 문제가 있는 부분을 수정한 앱을 다시 올리고 검토 요청을 클릭한다.

(만약 앱에 문제가 없다면 검토 요청을 바로 하면 되나 변경할게 없더라도 되도록 다시 앱을 버전업 하는게 좋다.

 이렇게 하는게 확실히 한번에 패스 되는 것 같다.)

 

아래와 같은 화면이 나오는데 여기서 사유를 적고 검토 요청 글자를 클릭하면 된다.

 

내가 경험한바로는 앱을 변경없이 다시 올리면 왠만한건 바로 패스가 된다.

(전면 광고인 경우 가끔 한번식 저러는데 왜그런지 모르겠다.;;)

 

하지만 그렇지 않는 경우엔 광고를 과감히 포기해야한다.^^

 

 

 

 


수익이 꾸준하게 증가하고있다
지난달이 큰 상승 곡선을 그렸는데
이번달도 지난달을 넘도록하는게
목표다.

'Life' 카테고리의 다른 글

[Life] 연말정산-원천징수영수증  (0) 2019.05.12
실패  (0) 2019.04.18
구글 광고 수익 증가중..  (0) 2019.04.10
민방위 교육  (0) 2019.04.03
수원제천 시외버스 시간표  (0) 2019.03.13
하담이 작품^^  (0) 2019.02.16


광고야 고맙다^^

'Life' 카테고리의 다른 글

수원제천 시외버스 시간표  (0) 2019.03.13
하담이 작품^^  (0) 2019.02.16
드디어 애드센스 1000달러 돌파  (1) 2019.01.23
하담이가 만든 서있는 악어  (0) 2019.01.08
강제 환기 (제로홈) 설치 후기  (0) 2019.01.06
실력이점점 늘어가는 하담이  (0) 2019.01.01
  1. Favicon of https://iotvrar.tistory.com PolarisEcho 2019.01.28 02:30 신고

    술사줘

이번달은 20일만에 100달러를
돌파했다
역시 전면광고가 답이다

'Life' 카테고리의 다른 글

아들작품  (0) 2018.11.27
Small Six Robot  (0) 2018.11.27
구글광고수익  (0) 2018.09.20
하담이 개그  (0) 2018.09.12
태풍아 오긴오니?  (0) 2018.08.23
iptime ddns 먹통  (0) 2018.08.17

Xamarin.Android 에 광고 넣는 방법을 소개합니다.

이번 시간에는 AdMob 에서 광고 ID 를 얻는 방법입니다.

우선 AdMob 에 가입을 합니다.

https://www.google.com/admob/

구글 로그인 해서 가입을 진행해야합니다.

가입 완료 후 수익창출 을 선택합니다.

여기서 좌측 상단의 빨간색 버튼 '새로운 앱에서 수익 창출' 을 클릭합니다.

아직 구글 플레이에 배포된 앱이 없다면 앱 직접 추가를 선택하고 이름을 넣습니다.

ANDROID 플랫폼을 선택합니다.

이름을 넣으면 아래처럼 앱추가 버튼이 활성화 됩니다.

앱추가를 클릭합니다.

광고 형식을 선택합니다. 배너를 선택합니다.

당연히 광고 크기가 크면 클수록 수익성이 좋을테지만 광고가 크면 클수록 사용자가 줄어들수도 있습니다.

 

광고 단위 이름을 넣고 저장 버튼을 클릭합니다.

애널리틱스는 건너뛰기 합니다. (필요하신 분을 사용하셔도 됩니다 _ 사용방법은 알아서^^)

아래 광고 단위 ID 가 생성되었습니다. 요놈을 잘 복사해 둡니다.

아래 목록에 광고 단위가 추가 된걸 확인 할수 있습니다.

 

다음 포스팅때 광고 ID를 가지고 XAMARIN.ANDROID 에 적용해보겠습니다.

+ Recent posts