revUp - Updates and news for the LiveCode community
Issue 136 | July 13th 2012 Contact the Editor | How to Contribute

Embedding Ads in LiveCode
Enhance your Apps and improve your revenue stream by taking advantage of the new in-app advertising features of LiveCode 5.5.1

by Hanson Schmidt-Cornelius

This lesson describes how to set up in-app advertising in LiveCode applications. The advertising content is provided by Inneractive. Screen captures and sample code are provided.

Introduction

Many applications use advertising as a means to increase the revenue stream. LiveCode provides the functionality for easy integration of advertising content in a LiveCode application. The following steps outline the process of adding advertising content to a LiveCode application.

Registering with the Advertising Content Provider (LiveCode Login)

The advertising content provided to the application is supplied by our ad partner Inneractive. In order to receive the advertising content, you have to first register with Inneractive. The following link: http://runrev.com/store/account/inneractive/ takes you to LiveCode login page where you log in with your LiveCode login information.

Registering with the Advertising Content Provider (Inneractive Login)

Once you have logged into the LiveCode account you are taken to the login screen for Inneractive. If you already have an account with Inneractive, use your login information here to proceed. If you do not have login information, then register with Inneractive by selecting the "Join Us" link at the top right hand corner of the login dialog. This opens a new dialog window in which you provide your "Name" and "e-mail address". This sets up the account with Inneractive for you. You are then sent a confirmation e-mail and a subsequent e-mail with the relevant registration information, including a password.

Generating an Advertising Key

Once you have an account with Inneractive, you need to create a key for the application that is to display advertising content.
Log into your Inneractive account using the login information you were sent in the registration e-mail. Then select the "Add App" tab on the Inneractive dashboard and follow the key generation instructions that are provided.
The key allows Inneractive to identify the application that is to display the content and record how much advertising content was routed through your application.

Writing the LiveCode Application

The next sections of this lesson describe how to set up the application for advertising content.

Registering the LiveCode Application

The LiveCode application has to be registered with Inneractive, using the advertising key that Inneractive provided you with. This key is registered with your LiveCode application using the following syntax:

mobileAdRegister "YOUR-AD-KEY"

Creating an Advert

Once your ad key has been registered, it is possible to create a region in your application that can be used to display adverts. The command mobileAdCreate allows you to specify the name of the advert that is retained throughout the lifetime of the advert, the size of the advert to display, the placement of the advert on your application screen and metadata that is used to control how often the add is to appear and what kind of ad is to be displayed:

local tDetails
// See the dictionary for more metadata entries
put "30" into tDetails["refresh"] // The advert refresh interval in seconds
put 25 into tDetails["age"] // The age of the target audience
put "male" into tDetails["gender"] // The expected gender of the target audience  
mobileAdCreate "myAd1", "banner", (0,0), tDetails

Deleting an Advert

Ads can be deleted at any time using to command mobileAdDelete. This command takes the name of the advert as a parameter.

mobileAdDelete "myAd1"

Ad Visibility

The visibility of ads can be controlled by setting a boolean switch:

mobileAdGetTopVisible ("myAd1") // Returns a boolean, indicating if the ad is visible or not
mobileAdSetTopVisible ("myAd1", true) //  Sets the visible of the ad "myAd1" to true

Returning a list of Active Ads

A list of all the currently active ads can be acquired by using the function:

mobileAds()

This returns a return-delimited list of the ad names.

Building a Test Application

It is easy to build a test application with advertising content. You can build a stack that displays adverts by copying and pasting code from this lesson:

  1. Create a new stack.
  2. Drag and drop three buttons onto the stack.
  3. Rename the buttons to Register, Create and Delete.
  4. Copy the code from section Registering the LiveCode Application and paste it into the on mouseUp handler of button Register. Remember to insert your own ad-key.
  5. Copy the code from section Creating an Advert and paste it into the on mouseUp handler of button Create.
  6. Copy the code from section Deleting an Advert and paste it into the on mouseUp handler of button Delete.

You are done. We cannot guarantee that you will get cool adverts like the one displayed in the image of this section, but you should now be able to display advert content on your device.

Further Reading

To understand the complete feature set and functionality that is available, refer to the LiveCode dictionary. This covers ad specific messages and further ad placement information that is not discussed in this lesson.

Hanson Schmidt-Cornelius

About the Author

Hanson Schmidt-Cornelius is an experienced software developer with an interest in artificial intelligence.

 

Main Menu

What's New

Summer Sale