Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 9 Next »

Prerequisites

Step Summary

  1. Add the Initialization code for the SDK

  2. Register all the app UIViewControllers to the SDK

  3. Add the tagged Wrappers, and tagged Buttons using the accessabilityLabel

  4. Note the transition 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

We require the SDK to be initialized only once and as early as possible It can be done either inside your UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:) method or inside the first UIViewController.viewDidLoad() method.

The first recommended place to initialize the SDK is the UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:) method.

import UIKit
import R89SDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // This is for testing purposes, remove it on prod
        R89SDK.shared.setLogLevel(level: LogLevels.debug)
        // This is for testing purposes, remove it on prod
        R89SDK.shared.setDebug()
  
        addTestingSingleTagData()  /* This is a later step */
        
        R89SDK.shared.initialize(
            publisherId: "TestPublisherID",
            appId: "TestAppId",
            singleLine: true,
            publisherInitializationEvents: nil)
        return true
    }
}

Your publisherId and appId will be provided to you during onboarding process by email, you can also retrieve them from the web interface after login.

This appID is not the same as the Manifest App Id you used in previous steps

Register all UIViewController’s

Use R89SDK.shared.registerUIViewController() method and register each UIViewController instance in your app that represents a screen. This helps the R89SDK to track the user’s navigation and screen transitions in the app.

import UIKit
import R89SDK

class MainViewController: UIViewController {
    ...
    override func viewDidLoad() {
        super.viewDidLoad()
        ...
        R89SDK.shared.registerUIViewController(uiViewController: self)
    }
    ...
}

Tagged Wrappers

 Details for Tagged Wrapper

Tagged Wrappers

What are they?

The tagged wrapper is an iOS UIView with a requirement to have accessibilityLabel specified, either from the XCode UI builder or programmatically. This is used to find the views in the Single tag where you want us to add the monetization inventory. You need to add as many as you can, remember that placing a tagged wrapper does not mean we need to use it.

Example

As mentioned tag values can be specified via UIView’s accessibilityLabel parameter either from the XCode’s UI Builder or programmatically.

Set tag from UI builder (recommended)

Here is what it looks like in the UI Builder. Here we have a blue wrapper on top and a green one on the bottom. Accordingly, the top wrapper has specified to have a tag named top_wrapper_tag and the one in the bottom bottom_wrapper_tag.

Screenshot 2024-06-19 at 06.20.19-20240619-022050.pngScreenshot 2024-06-19 at 06.21.04-20240619-022124.png

In this case, the UIViewController looks like this

import UIKit
import R89SDK
class MainViewController: UIViewController {
    ...
    override func viewDidLoad() {
        super.viewDidLoad()
        ...
        // This line is necessary to inform R89SDK about app navigation.
        R89SDK.shared.registerUIViewController(uiViewController: self)
    }
    ...
}

Set tag programmatically (alternative)

As an alternative approach, we can specify the accessibilityLabel using code, here is the equivalent setup but from the UIViewController.

import UIKit
import R89SDK

class MainViewController: UIViewController {
    
    @IBOutlet var topWrapperUIView:UIView!
    @IBOutlet var bottomWrapperUIView:UIView!
    ...
    override func viewDidLoad() {
        super.viewDidLoad()
        ...
        // Setting tags programmatically 
        topWrapperUIView.accessibilityLabel = "top_wrapper_tag"
        bottomWrapperUIView.accessibilityLabel = "bottom_wrapper_tag"
        // This line is necessary to inform R89SDK about app navigation.
        R89SDK.shared.registerUIViewController(uiViewController: self)
    }
    ...
}

Where to add the wrappers?

Everywhere you have a white space. Tagged wrappers don’t need to contain ads, it's just for flexibility and future-proofing. Indeed, overloading your app with ads is not the best user experience, but the wrappers don’t need to be filled with ads, that’s why we recommend you add the wrappers everywhere where there is a blank space on the screen. Even if you do not want to fill them in.

We can manage which ones are and are not filled from the web interface.

Best practices when adding a wrapper

For Creating the wrappers you need to ensure the wrapper view:

  • Do not overlap other wrappers on the app content, no matter the size it takes. if it is a space that you have a max Size to it, put it in the tag name.

  • Every blank space is a good space for a wrapper (even if you do not plan to use it).

  • Do not use only one tag for all of your wrappers, it will be hard to configure your monetization and change it according to your needs. So use as many different tags as possible (like id’s but you can have some of them repeated when it makes sense).

  • Use a blank (no subviews) UIView as the wrapper view.

Limitations

  • We can fill either all of the wrappers with a tag or just the first one we find with that tag: if you want to differentiate any wrappers you need to assign a different tag to those. E.g.: if you want us to fill a wrapper at the bottom of the screen that has the tag ads_wrapper we can fill that. However, if you have multiple wrappers with the same tag, and you want to fill all of them and exclude some while having the same tag, it’s not possible. We encourage you to ask for advice to our technical support on how to group wrappers.

  • To enable tag lookup in the uiViewController’s view hierarchy and screen navigation tracking you will need to call R89SDK.shared.registerLifecycle(uiViewController: self) in the UIViewController.viewDidLoad() method to explicitly notify the R89SDK about screen load event. Keep in mind to call it AFTER tag configurations.

    import UIKit
    import R89SDK
    
    class MainViewController: UIViewController {
        
        @IBOutlet var topWrapperUIView:UIView!
        @IBOutlet var bottomWrapperUIView:UIView!
        ...
        override func viewDidLoad() {
            super.viewDidLoad()
            ...
            // Setting tags programmatically 
            topWrapperUIView.accessibilityLabel = "top_wrapper_tag"
            bottomWrapperUIView.accessibilityLabel = "bottom_wrapper_tag"
            // This line is necessary to inform R89SDK about app navigation.
            R89SDK.shared.registerUIViewController(uiViewController: self)
        }
        ...
    }

This limitation and R89SDK.shared.registerUIViewController(uiViewController: self) might be removed in forthcoming versions and replaced with an automatic screen-tracking approach.

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:

 

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


Example of button press:

 

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 UIViewController class where we initialized the code, we are going to test all the transitions, 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 → https://refinery89.atlassian.net/wiki/x/EgBWTw

When using the SingleTagConfigBuilder you are not going to be able to select the ad units that are for production, they are by default the testing config id in https://refinery89.atlassian.net/wiki/x/EABGTw.

func addTestingSingleTagData(){

SingleTagConfigBuilder.shared.addAdScreenBuilder(isFragment:false,screenName: "InitialScreenViewController")
    .addBanner(wrapperTag: "banner_tag",
               getAllWithTag: true,
               wrapperRelativePositionInside: true,
               wrapperRelativePositionAfter: false)
    .addInterstitial(eventsToTrackTo: nil, eventsToTrackButton: "button_tag")
    .addInterstitial(eventsToTrackTo: "SecondSCreenViewController", eventsToTrackButton: nil)
}

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 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.shared.setDebug() and addTestingSingleTagData()

  • Change the App id in the info.plist for the production one

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

  • it’s also recommended to remove R89SDK.shared.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.

We have the capability to display Display ads on a tagged wrappers or trigger an Interstitial ads during the transition from one screen to another or in button press. And many other things All of this can be achieved without the need of coding specific triggers or manually adding the ad to the view. It is as simple as initializing the SDK.

  • No labels