वेबव्यू सेट अप करें

अगर आपके Android ऐप्लिकेशन में वेब कॉन्टेंट दिखाने के लिए WebView का इस्तेमाल किया गया है, तो हमारा सुझाव है कि आप इसे कॉन्फ़िगर करें. इससे, कॉन्टेंट पर विज्ञापनों से बेहतर कमाई की जा सकेगी.

इस गाइड में,WebView ऑब्जेक्ट को कॉन्फ़िगर करने के बारे में जानकारी दी गई है.

तीसरे पक्ष की कुकी चालू करें

उपयोगकर्ता को विज्ञापन देखने का बेहतर अनुभव देने और Chrome की कुकी नीति का पालन करने के लिए, अपने WebView इंस्टेंस पर तीसरे पक्ष की कुकी चालू करें.

Java

CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);

Kotlin

CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true)

वेब की सेटिंग

Default WebView settings are not optimized for ads. Use the WebSettings APIs to configure your WebView for:

  • JavaScript
  • Access to local storage
  • Automatic video play

Java

import android.webkit.CookieManager;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {
  private WebView webView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    webView = findViewById(R.id.webview);

    // Let the web view accept third-party cookies.
    CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
    // Let the web view use JavaScript.
    webView.getSettings().setJavaScriptEnabled(true);
    // Let the web view access local storage.
    webView.getSettings().setDomStorageEnabled(true);
    // Let HTML videos play automatically.
    webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
  }
}

Kotlin

import android.webkit.CookieManager
import android.webkit.WebView

class MainActivity : AppCompatActivity() {
  lateinit var webView: WebView

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    webView = findViewById(R.id.webview)

    // Let the web view accept third-party cookies.
    CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true)
    // Let the web view use JavaScript.
    webView.settings.javaScriptEnabled = true
    // Let the web view access local storage.
    webView.settings.domStorageEnabled = true
    // Let HTML videos play automatically.
    webView.settings.mediaPlaybackRequiresUserGesture = false
  }
}

वेब व्यू कॉन्टेंट लोड करें

कुकी और पेज यूआरएल, वेब व्यू की परफ़ॉर्मेंस के लिए ज़रूरी होते हैं. ये उम्मीद के मुताबिक तब ही काम करते हैं, जब को नेटवर्क पर आधारित यूआरएल के साथ इस्तेमाल किया जाता है. ऑप्टिमाइज़ की गई WebView परफ़ॉर्मेंस के लिए, वेब कॉन्टेंट को सीधे नेटवर्क पर आधारित यूआरएल से लोड करें. WebViewAssetLoader का इस्तेमाल करने, डिवाइस से ऐसेट लोड करने या डाइनैमिक तरीके से वेब कॉन्टेंट जनरेट करने से बचें.

Java

import android.webkit.CookieManager;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {
  private WebView webView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    webView = findViewById(R.id.webview);

    // Let the web view accept third-party cookies.
    CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
    // Let the web view use JavaScript.
    webView.getSettings().setJavaScriptEnabled(true);
    // Let the web view access local storage.
    webView.getSettings().setDomStorageEnabled(true);
    // Let HTML videos play automatically.
    webView.getSettings().setMediaPlaybackRequiresUserGesture(false);

    // Load the URL for optimized web view performance.
    webView.loadUrl("https://webview-api-for-ads-test.glitch.me");
  }
}

Kotlin

import android.webkit.CookieManager
import android.webkit.WebView

class MainActivity : AppCompatActivity() {
  lateinit var webView: WebView

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    webView = findViewById(R.id.webview)

    // Let the web view accept third-party cookies.
    CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true)
    // Let the web view use JavaScript.
    webView.settings.javaScriptEnabled = true
    // Let the web view access local storage.
    webView.settings.domStorageEnabled = true
    // Let HTML videos play automatically.
    webView.settings.mediaPlaybackRequiresUserGesture = false

    // Load the URL for optimized web view performance.
    webView.loadUrl("https://webview-api-for-ads-test.glitch.me")
  }
}

वेब व्यू की जांच करना

हमारा सुझाव है कि ऐप्लिकेशन डेवलप करने के दौरान, आप इस टेस्ट यूआरएल को लोड करें:

https://webview-api-for-ads-test.glitch.me#webview-settings-tests

ताकि यह पुष्टि की जा सके कि इन सेटिंग का विज्ञापनों पर सही असर पड़ता है. इन बातों का पता चलने पर, टेस्ट यूआरएल में पूरे इंटिग्रेशन के लिए सफलता के मानदंड तय होते हैं:

वेब व्यू सेटिंग

  • तीसरे पक्ष की कुकी काम करती हैं
  • पहले-पक्ष की कुकी काम करती हैं
  • JavaScript सक्षम
  • DOM स्टोरेज चालू किया गया

वीडियो विज्ञापन

  • वीडियो विज्ञापन इनलाइन चलता है और फ़ुल स्क्रीन बिल्ट-इन प्लेयर में नहीं खुलता है
  • चलाएं बटन पर क्लिक किए बिना वीडियो विज्ञापन अपने-आप चलता है
  • वीडियो विज्ञापन फिर से चलाया जा सकता है

जांच पूरी होने के बाद, टेस्ट यूआरएल को उस यूआरएल से बदल दें जिससे वेब व्यू लोड होता है.