Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Step

...

summary

  1. Add The initialization code.

  2. Create the Channel between web and native with R89SDK.shared.configureWebView() method.

  3. Use R89SDK.shared.loadUrlWithConsentDataOrWait() to load your urls URLs into the webviewweb view.

  4. Test everything is working.

  5. Change everything to production codcode.

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

...

Note

If you are placing all or some ads natively, meaning that the actions on the web view trigger native code through some kind of javascript interface, then we recommend using Manual Implementation or if you are displaying some ads inside the webview and others in the native app you can use this implementation and the manual together to make this happen.

Initialize the SDK

Note

We require the SDK to be initialized only once 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 Activitythe UIApplicationDelegate’s didFinishLaunchingWithOptions method or the first UIViewController’s viewDidLoad method is recomended.

Override the UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:) method.

Code Block
languageswift
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() // This is for testing purposes, remove it on prod
        // publisherId and appId are for testing purposes, remove it on prod
        R89SDK.shared.initialize(
          publisherId: "TestRefinery89ID", /* This is for testing purposes, change it on prod */
          appId: "TestDemoApp", /* This is for testing purposes, change it on prod */
          singleLine: false,
          publisherInitializationEvents: nil
        )
        return true
    }
}
Info

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.

Note

This appID is not the same GADApplicationIdentifier provided in the Info.plist in previous steps.

Until here is the same as the Manual implementation, this is why this implementation is compatible with the manual, but now instead of focusing on wrappers, events, and formats we will see how to create the channel and how to load URLs to have consent in them.

Info

If you want to have native ads to be triggered from the webview we recommend using the manual configuration alongside some kind of javascript interface implemented in the web side to trigger native code, although first finish this whole guide and then go to the manual

Create the channel

Right after Initialization, you should use the following methods

Code Block
languageswift
import UIKit
import R89SDK
import WebKit

class ViewController: UIViewController, WKNavigationDelegate {
    
    @IBOutlet var wkWebView: WKWebView!
    ...

    override func viewDidLoad() {
        super.viewDidLoad()
        ...
        let url = <YOUR-URL>
      
        wkWebView.navigationDelegate = self
        
        // This helps the channel to identify this as an app
        let userAgent = R89SDK.shared.getUserAgent(
                          webView: wkWebView, 
                          siteName: <YOUR-SITE-NAME>)
                          
        R89SDK.shared.configureWebView(webView: wkWebView, userAgent: userAgent)
        ...        
    }
}

Load URLs with consent

Use the following method to replace any webview.load() method usages you might have

Code Block
languageswift
R89SDK.shared.loadUrlWithConsentDataOrWait(webView: wkWebView, url: url)
Note

This url must only be the urls related to you content, or own. Other urls can be loaded normally. with webview.loadUrl()

Go into production

  • Remove the methods R89SDK.shared.setDebug().

  • Change the GADApplicationIdentifier in the info.plist for the production one.

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

  • Change the r89ConfigId in the formats for the production ones.

  • it’s also recommended to remove R89SDK.shared.setLogLevel(level: LogLevels.debug) but not needed.

How does it work?

Works by creating a channel linking our SDK to your current in-web monetization solutions. This channel just makes sure that the ad units on the web know that the current environment is app and also sends the consent data so you get the same consent on both sides complying with privacy policies.