Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
stylenone

Prerequisites

Step Summary

  1. Add the Initialization code.

  2. Add the Application class to the Manifest (in case you are using it)

  3. Add the Tagged Wrappers, Tagged Buttons and

  4. Note the Transitions Events

  5. Add the testing Single Data

  6. Test everything is working

  7. Change everything to production code

  8. Your app is now prepared for monetization with us.

Initialize the SDK

Note

We require the SDK to be initialized only once and as early as possible so for this purpose using Android’s application class is recommended but if your app only has one activity, if using the activity make sure it is never destroyed unless killing the app or placing it in the background, matching then the lifecycle of Application, you can initialize it in onCreate method of that Activity.

...

Then add this application class to the manifest you already had from the Android Get Started.

The code for adding the application is the following

...

We will come back to this Application class to add our testing single tag data, but let's first add the tagged wrappers and events

Tagged wrappers

Tagged Wrappers are the container inside which the ads will show, they are normal wrappers with the android:tag attribute set. You need to add as many as you can, remember that placing a tagged wrapper does not mean we need to use it.

Check both https://refinery89.atlassian.net/wiki/x/A4DcSQ and Tagged Wrappers for more information

We recommend you add the wrappers using XML Views, since it’s easier than creating them using code, so something like this:

...

Info

With this added to your views we can detect that tag and place an ad inside of it if the single tag data says so.

Events

Events can trigger other formats, right now the single tag supports:

  • Transitions events are detected by the single tag automatically after initialization. They happen when an activity or fragment is started from other activity or fragment.

  • Button Presses when a button is pressed, this works They are detected by adding the android:tag attribute to the button.

...

Example of transition:

Code Block
class MainActivity : AppCompatActivity()
{
	override fun onCreate(savedInstanceState: Bundle?)
	{
		super.onCreate(savedInstanceState)
		setContentView(R.layout.activity_main_auto)
		
		findViewById<Button>(R.id.goToNewsPost).setOnClickListener {
			val intent = Intent(this, NewsPostDetailActivity::class.java).apply {
				putExtra("newsPostData", newPostData)
			}
			startActivity(intent)
		}
	}
}
Info

In this example an interstitial would be triggered when we see the NewsPostDetailActivity comes to live after loading.

...

Example of button press:

with this button code

Code Block
# activity_main.xml
...
<Button
    android:id="@+id/play_video_trailer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:tag="play_video_trailer_tag" />
...

...

Info

In this example an interstitial would be triggered when the button is pressed and when the interstitial is closed the playVideoTrailer() method will be executed.

...

Adding testing single tag data

Go back to the application class that was created at the start of the guide, we are going to test all the transitiontransitions, tagged wrappers and tagged buttons you have placed in the app.

...

Before initialization method we called addTestingSingleTagData() that uses the SingleTagConfigBuilder to create the testing data needed for debugging the sdk.

More info in → How to test Single Tag Implementation

Note

When using the SingleTagConfigBuilder you are not going to be able to select the ad units that are displayed for production, they are by default the testing config id in Android - Ad Formats.

Code Block
breakoutModefull-widthwide
languagekotlin
fun addTestingSingleTagData()
{
    //Add a Screen that is an Activity, the screenName you can get it by logging this in you code -> 
    // MainActivity::class.simpleName -> MainActivity
    // NewsPostDetailActivity::class.simpleName -> NewsPostDetailActivity
    
    val screenBuilder = SingleTagConfigBuilder.addAdScreenBuilder(
        isFragment = false, 
        screenName = "MainActivity"
    )
    
    // Add a banner format to the wrapper with the tag main_activity_bottom_ad_container
    screenBuilder.addBanner(
      wrapperTag = "main_activity_bottom_ad_container", 
      getAllWithTag = false, /* Only the first tagged wrapper in "MainActivity" with this tag will be used for this banner*/
      wrapperRelativePositionInside = true /* the ad will be placed inside of the wrapper */
    )
    
    /* trigger interstitial when we transition from "MainActivity" (ScreenBuilder.screenName) TO NewsPostDetailActivity */
    screenBuilder.addInterstitial(
        eventsToTrackTo = "NewsPostDetailActivity", 
        eventsToTrackButton = null
    )
    
    /* trigger an interstitial when a button with this tag is pressed in "MainActivity" (ScreenBuilder.screenName) */
    screenBuilder.addInterstitial(
        eventsToTrackTo = null
        eventsToTrackButton = "play_video_trailer_tag" 
    )
}

Note

This step is for testing purposes and you are only going to see test ads when using this approach, but this is very helpful to us if you provide this peace of code to tell us where you want to place the ads.

Later when in production, this code have been will be removed and you have hopefully added flexible tagged wrappers and tagged all the button as possible so we can change your ad slots from the server without the need of updating the app.

Go into production

For going into production you will need to use you ids:

  • Remove the methods R89SDK.setDebug() and addTestingSingleTagData()

  • Change the Google app App id in the manifest for the production one

  • Change the appId and publisherId in the initialization method for the production ones

  • it’s also recommended to remove R89SDK.setLogLevel(LogLevels.DEBUG) but not needed

...

How does it works?

We monitor your app to determine the active screen at any given moment. For each screen, we maintain a record of events and tags that you have supplied, enabling us to place ads in those tagged views or during specific transitions and events from the record.

...