View
224
Download
0
Category
Tags:
Preview:
Citation preview
1
Mobile ComputingMonetizing An App
Copyright 2014 by Janson Industries
Copyright 2014 by Janson Industries2
Objectives▀ Learn about:
The various ad companies
Ad measurements
AdViews
Define an ad using XML and java
Copyright 2014 by Janson Industries3
Ad Companies▀ AdMob, Inmobi, Mopub,
Jumptap, Tapit, Smaato, Mobfox, AdSense
▀ They provide code that you add to your app
▀ Their code figures out size of ad to display based on the device
Copyright 2014 by Janson Industries4
Measurements▀ CTR – click through rate
% of people who click on an ad► If the ad is displayed 100 times and is
clicked twice, the ctr is 2% or .02
▀ CPC – cost per click
How much advertiser will pay you for each click
►47 cents for each click through
Copyright 2014 by Janson Industries5
Measurements▀ eCPM – effective cost per thousand
ad views (impressions)
How much you should make for a thousand ads being displayed
Need to multiply CPC (.47) by 1000 by CTR (.02)
► .47 * 1000 * .02 = $9.40
▀ Ad companies track all these measurements (and report them to you)
Copyright 2014 by Janson Industries6
Admob provides reports
Copyright 2014 by Janson Industries7
Notice reported stats
Copyright 2014 by Janson Industries8
Detailed stats
Copyright 2014 by Janson Industries9
My sad, unpopular app
Copyright 2014 by Janson Industries10
Measurements▀ Most of the ad companies won’t let
you post these numbers
▀ Also, if they see unusual numbers:
A CTR of 57%
Clicks are done by a small % of users or locations
►They may shut down your app
• People have their friends, relatives, and neighbors download app and click ads
Copyright 2014 by Janson Industries11
Going to use AdMob (owned by Google) http://www.google.com/ads/admob/
Copyright 2014 by Janson Industries12
Sign up using your google account
Copyright 2014 by Janson Industries13
If you are at the same computer that you created the account on they will know who you are!
If so, fill in the password
Copyright 2014 by Janson Industries14
Copyright 2014 by Janson Industries15
Specify info for an Admob account then click Continue
Copyright 2014 by Janson Industries16
Scroll down, accept Terms, click Submit
Copyright 2014 by Janson Industries17
Click Add Your First App
Copyright 2014 by Janson Industries18
Specify tax and payment info, the click Submit
Copyright 2014 by Janson Industries19
Click Sites and Apps then Android App
Copyright 2014 by Janson Industries20
Fill in app info and click Continue
Copyright 2014 by Janson Industries21
Go to https://apps.admob.com/#home click Monetize new app
Copyright 2014 by Janson Industries22
Specify Project name and Android
Copyright 2014 by Janson Industries23
Specify Ad type and give it a name
Copyright 2014 by Janson Industries24
You can change some ad formatting
Copyright 2014 by Janson Industries25
You need the add unit ID and you can have them info email to you
Copyright 2014 by Janson Industries26
Specify email address to send to
Copyright 2014 by Janson Industries27
The Ad unit ID that you will need to get ads
Copyright 2014 by Janson Industries28
Go back to Home, scroll down, and the project(s) should be displayed
Copyright 2014 by Janson Industries29
Creating From Scratch▀ Must create a new project
(AdProj) with a min target of 3.2, package (my.ad.com), activity (AdProjActivity), and layout (main) Example will be 4.X
▀ Need to: Add a reference to the Google play
services library
Modify the Manifest
Copyright 2014 by Janson Industries30
Copyright 2014 by Janson Industries31
Must import google-play-services_lib into the workspace (Should already be there from MapProj but if not…)
File, Import, expand the Android folder and select Existing Android Code Into WorkSpace, then click Next
Copyright 2014 by Janson Industries32
Click the Browse button then navigate to the sdk/extras/google/google_play_services/libproject/google-
play-services_lib, click OK then Finish
Copyright 2014 by Janson Industries33
Click Android
Right click AdProj and select Properties
Copyright 2014 by Janson Industries34
Scroll down, click Add, then select the library and click OK
•c
Copyright 2014 by Janson Industries35
Setup▀ Manifest have:
The following meta tag in the application element
The following activity defined
<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"/>
Copyright 2014 by Janson Industries36
Copyright 2014 by Janson Industries37
Setup The following permissions
outside the application tags
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Copyright 2014 by Janson Industries38
Copyright 2014 by Janson Industries39
Defining an Ad▀ Use an AdView component
▀ Two ways to define an AdView
With xml in the layout
With java in the activity
▀ Will define an AdView component in xml
Copyright 2014 by Janson Industries
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" ads:adUnitId="ca-app-pub-6333216089167186/1679833953" ads:adSize="BANNER"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /></LinearLayout>
40
Don’t forget to substitute your Ad Unit ID in the adUnitId parameter
main.xml
Copyright 2014 by Janson Industries41
AdProjActivity.java▀ Need to import
▀ Need an AdView variable and object in onCreate then After setContentView, create an
AdRequest and add a test device
Load ad into adView
import com.google.android.gms.ads.*;
// Look up the AdView as a resource and load a request. AdView adView = (AdView)this.findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice("abc") .build(); adView.loadAd(adRequest);
Copyright 2014 by Janson Industries42
AdProjActivity.java▀ You will get a test ad
Google doesn't want you to download real ads while testing
▀ To get a real add
// Look up the AdView as a resource and load a request. AdView adView = (AdView)this.findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder() //.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) //.addTestDevice("abc") .build(); adView.loadAd(adRequest);
Copyright 2014 by Janson Industries43
AdProjActivity.java
▀ Have to run to get a real TestDevice number
▀ Find in logcat
Copyright 2014 by Janson Industries44
AdProjActivity.java
▀ Substitute for abc
// Look up the AdView as a resource and load a request. AdView adView = (AdView)this.findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder(). .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice("B3EEABB8EE11C2BE770B684D95219ECB") .build(); adView.loadAd(adRequest);
Copyright 2014 by Janson Industries45
Copyright 2014 by Janson Industries46
ads:adSize="SMART_BANNER"
Copyright 2014 by Janson Industries47
ads:adSize="MEDIUM_RECTANGLE"
Copyright 2014 by Janson Industries48
Other Types of Ad
Interstitial Ads
Full screen ads with a close button
More expensive, therefore there are often display limits
Copyright 2014 by Janson Industries49
Go back to AdMob and add an Interstatial add to the app
Copyright 2014 by Janson Industries50
Specify timeout and ad name
Copyright 2014 by Janson Industries51
Copyright 2014 by Janson Industries52
Copyright 2014 by Janson Industries53
Copyright 2014 by Janson Industries54
Interstitial Need class level variables
In onCreate, create an InterstitialAd object, set the Ad Unit ID, create the AdRequest and load the ad
private InterstitialAd interstitial;private static final String AD_UNIT_ID = "ca-app-pub-6333216089167186/1679833953";
interstitial = new InterstitialAd(this);interstitial.setAdUnitId(AD_UNIT_ID);
// Create ad request.AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading the interstitialinterstitial.loadAd(adRequest);
Copyright 2014 by Janson Industries55
Interstitial Ads Can take a while to load
If you try to display before loaded will get an error
So we will put a button on the screen and show the ad after the button is touched
Copyright 2014 by Janson Industries
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"><TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginLeft="100px"> <Button android:id="@+id/Btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="doClick"
android:text="Show Ad" /> </LinearLayout></LinearLayout>
56
main.xml
Copyright 2014 by Janson Industries57
doClick in AdProjActivity
Time to test
import android.view.View; : : :public void doClick(View arg0) {
interstitial.show();}
Copyright 2014 by Janson Industries58
Check in logcat that ad has loaded
Copyright 2014 by Janson Industries59
Click Show Ad
Copyright 2014 by Janson Industries60
AdListeners In java, Activity can implement
the AdListener interface
Then tie the ad listener to the adView
adView.setAdListener(this);
Copyright 2014 by Janson Industries61
AdListeners Activity can implement onAdxxx
methods that are called when ad is: Successfully and unsuccessfully
received onAdLoaded, onAdFailedToLoad
When ad is overlaid on the screen onAdOpened
Ad dismissed and returning to app onAdClosed
When ad clicked onAdLeftApplication
Copyright 2014 by Janson Industries62
AdListeners So instead of having a button to
display the ad
Create onAdLoaded method and have it display the ad
And if ad doesn't load
Create onFailedToLoad method to retry to load the ad
Recommended