अगर आपका ऐप्लिकेशन, वेब कॉन्टेंट दिखाने के लिए
का इस्तेमाल करता है, तो हमारा सुझाव है कि आप इसे इस तरह कॉन्फ़िगर करें कि विज्ञापनों से कॉन्टेंट को ज़्यादा से ज़्यादा कमाई करने के लिए ऑप्टिमाइज़ किया जा सके.WebView
इस गाइड में, WebView
ऑब्जेक्ट को कॉन्फ़िगर करने के तरीके के बारे में जानकारी देने का तरीका बताया गया है.
तीसरे पक्ष की कुकी चालू करना
उपयोगकर्ता को विज्ञापन का बेहतर अनुभव देने और Chrome की कुकी नीति का पालन करने के लिए, अपने WebView
इंस्टेंस पर तीसरे पक्ष की कुकी चालू करें.
Java
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
Kotlin
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true)
वेब की सेटिंग
डिफ़ॉल्ट WebView
सेटिंग, विज्ञापनों के लिए ऑप्टिमाइज़ नहीं की जाती हैं. WebView
को कॉन्फ़िगर करने के लिए, WebSettings
एपीआई का इस्तेमाल करें. इनका इस्तेमाल इन कामों के लिए किया जा सकता है:
- JavaScript
- लोकल स्टोरेज का ऐक्सेस
वीडियो अपने-आप चलने की सुविधा
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
}
}
वेब व्यू का कॉन्टेंट लोड करना
वेब व्यू से कमाई करने के लिए, कुकी और पेज के यूआरएल ज़रूरी होते हैं. ये सिर्फ़ तब ठीक से काम करते हैं, जब loadUrl()
का इस्तेमाल नेटवर्क पर आधारित यूआरएल के साथ किया जाता है. बेहतर 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://google.github.io/webview-ads/test/");
}
}
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://google.github.io/webview-ads/test/")
}
}
वेब व्यू की जांच करना
हमारा सुझाव है कि ऐप्लिकेशन डेवलप करते समय, यह टेस्ट यूआरएल लोड करें:
https://google.github.io/webview-ads/test/
इन सेटिंग का विज्ञापनों पर सही असर पड़ रहा है या नहीं, इसकी पुष्टि करने के लिए. अगर टेस्ट यूआरएल में ये चीज़ें दिखती हैं, तो इसका मतलब है कि इंटिग्रेशन सही तरीके से हुआ है:
वेब व्यू की सेटिंग
- तीसरे पक्ष की कुकी काम करती हैं
- पहले-पक्ष की कुकी काम करती हैं
- JavaScript चालू है
- डीओएम स्टोरेज की सुविधा चालू है
वीडियो विज्ञापन
- वीडियो विज्ञापन, इनलाइन तरीके से चलता है और यह फ़ुल स्क्रीन वाले बिल्ट-इन प्लेयर में नहीं खुलता
- वीडियो विज्ञापन, 'चलाएं' बटन पर क्लिक किए बिना अपने-आप चलता है
- वीडियो विज्ञापन को फिर से चलाया जा सकता है
टेस्टिंग पूरी होने के बाद, टेस्ट यूआरएल को उस यूआरएल से बदलें जिसे वेब व्यू लोड करना चाहता है.