Page 1 of 1

Adsense in PureBasic-Apps

Posted: Tue Jul 17, 2012 12:27 pm
by jamirokwai
Hi there,

lately, I made one of my Apps free (SpeakToMe,http://the-crying-eye.com/SpeakToMe), and added Advertising using AdSense to refinance it :-)
Since Sunday - two days ago - 41 people downloaded it from my site. And some of them seem to click on the advertising inside the Window. At the moment, it shows Advertising about quads, those 4-wheeled-fun-mounts... Don't know, where Google gets the Info about me sticking to quads, but ok. :mrgreen:

So, I'd like to share my findings :-)
You will need an account over at Google Adsense, and about 1k on your own webspace for every ad-campaign you like to set up.
Then - in AdSense - set a campaign for online-content, get the appropriate ID and your publisher-id. You can use these two files:

Part 1: PureBasic-Code, self contained. This works on Mac OS X

Code: Select all

; AdSentified - means AdSense in your Desktop-Apps!
; made by The Crying Eye
; use it, share it, give credit (if you like)
; donate to some international organization planting trees :-)
; comments welcome

EnableExplicit

Global URLgotshot = 0
Global threadid = 0

Procedure  Open_URL(URL$)
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_MacOS   : RunProgram("open", URL$, "")
    CompilerCase #PB_OS_Windows : RunProgram(URL$)
    CompilerCase #PB_OS_Linux   : RunProgram(URL$)
  CompilerEndSelect   
EndProcedure

; I need to fake Callbacks here, because PureBasic does not actively support
; CallBacks from WebGadgets on Mac OS X (or I am too stupid to use it)

Procedure NavigationCallback(*value)
  Define temp$
  Repeat
    temp$ = GetGadgetItemText(0,#PB_Web_PageTitle)
    If temp$ <> "Apps" And temp$ <> ""
      Open_URL(GetGadgetText(0))
      URLgotshot = 1
    EndIf
    Delay(250) ; needs this to stop double or tripleclicks
  ForEver
EndProcedure 

OpenWindow(0,50,50,468,60,"Adsense")
WebGadget(0,0,0,468,60,"http://domain.com/yourhttpfile.html") ; set the URL and Size accordingly.
threadid = CreateThread(@NavigationCallback(),0)

Repeat
  If URLgotshot = 1
    SetGadgetState(0,#PB_Web_Back)
    URLgotshot = 0
  EndIf
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
Part 2: The HTML-file - Do not reformat, remove all comments added using // !!!

Code: Select all

<html><head><title>Apps</title></head><body><div style="position:fixed;top:0;left:0;width:486px;height:60px;padding:0;margin:0;overflow:hidden">
<script type="text/javascript"><!--
google_ad_client = "xxx"; // add your publisher-id here
/* Apps */  // you need to set the same name here like in your campaign
google_ad_slot = ""; // add your ad-slot here - the ID of your campaign
google_ad_width = 468; // the same size as in your PB-Code
google_ad_height = 60;
//-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></body></html>
If statistics are right, I will earn 1 € per day. I don't know the real outcome atm, but that sounds promising. More income than selling the App!
I think, this will decline in the future, when less people download my App, but for now... Nice :-)

If you have more question, don't hesitate to ask.
This is hard to figure out, but easy to setup.

Re: Adsense in PureBasic-Apps

Posted: Tue Jul 17, 2012 12:42 pm
by rsts
Interesting.

Many thanks for the code and idea :)

Re: Adsense in PureBasic-Apps

Posted: Tue Jul 17, 2012 1:56 pm
by wilbert
Nice to hear that this is possible using PureBasic 8)
I considered it for my iOS apps but couldn't put myself to it since I hate ad-based apps myself :shock:

Re: Adsense in PureBasic-Apps

Posted: Tue Jul 17, 2012 2:01 pm
by jamirokwai
wilbert wrote:Nice to hear that this is possible using PureBasic 8)
I considered it for my iOS apps but couldn't put myself to it since I hate ad-based apps myself :shock:
Yes, I also do hate ad-based apps.

But since competition is strong, and has more money ...
Giving away apps for free, and incorporate ads in it sometimes is the only way.

I have to see it this way: Sometimes, it's better earning 10 bucks a week WITH advertising than 3 bucks SELLING the same app ... And this way, people find my other apps, too.

It's a pity, but the world seems to work like this :?

Re: Adsense in PureBasic-Apps

Posted: Tue Jul 17, 2012 2:29 pm
by wilbert
I understand that it can be an attractive method for a developer (just like in app purchases).

As for the navigation callback, this sort of mimics it a bit but I don't know if that would work for you.
http://www.purebasic.fr/english/viewtop ... 19&t=48917

Re: Adsense in PureBasic-Apps

Posted: Tue Jul 17, 2012 3:27 pm
by Num3
Nice!
200 open tabs in 5 seconds!!! Had to hard reset pc...

A few years back there was a javascript virus that did just this...

Re: Adsense in PureBasic-Apps

Posted: Tue Jul 17, 2012 3:44 pm
by jamirokwai
Num3 wrote:Nice!
200 open tabs in 5 seconds!!! Had to hard reset pc...

A few years back there was a javascript virus that did just this...
Oh, that's odd. Which OS do you use?
I am on Mac OS X here.

Probably 250 msec delay isn't enough!?

Re: Adsense in PureBasic-Apps

Posted: Tue Jul 17, 2012 6:21 pm
by c4s
It's not allowed to include Google Adsense in software. This also applies when using a web gadget since its only purpose is to display the advertisment:
AdSense program policies -> Ad placement wrote:Google ads, search boxes or search results may not be:
  • Integrated into a software application of any kind, including toolbars.
  • Placed on any non-content-based page.
[...]
However it seems that this new service called Google AdMob is allowed as it has been created for apps...

Re: Adsense in PureBasic-Apps

Posted: Tue Jul 17, 2012 6:58 pm
by Polo
Only for mobile, however.

Re: Adsense in PureBasic-Apps

Posted: Tue Jul 17, 2012 8:41 pm
by jamirokwai
c4s wrote:It's not allowed to include Google Adsense in software. This also applies when using a web gadget since its only purpose is to display the advertisment:
AdSense program policies -> Ad placement wrote:Google ads, search boxes or search results may not be:
  • Integrated into a software application of any kind, including toolbars.
  • Placed on any non-content-based page.
[...]
However it seems that this new service called Google AdMob is allowed as it has been created for apps...
Damn... Thanks for the info.

I will contact Google to clarify.

Re: Adsense in PureBasic-Apps

Posted: Wed Jul 18, 2012 12:42 am
by IdeasVacuum
I will contact Google to clarify.
Will be interesting to hear what they say - I mean, why limit the service to Mobiles (no screen estate!) and tablets?