Posts under category Google

I have a singleton class for loading and displaying ads

object AdmobProvider {     var countLoadAds = 0     lateinit var mInterstitialAd: InterstitialAd     private val adRequest = AdRequest.Builder().build()     fun init(activity: Activity) {         MobileAds.initialize(activity)         initInterstitial(activity)     }     private fun initInterstitial(context: Activity) {         mInterstitialAd = InterstitialAd(context)         if (!SubscriptionProvider.hasSubscription()) {             mInterstitialAd.adUnitId = context.getString(R.string.interstitial_video)             mInterstitialAd.loadAd(adRequest)             mInterstitialAd.adListener = object : AdListener() {                 override fun onAdClosed() {                     super.onAdClosed()                     Log.i("AdmobProvider", "onAdClosed: ")                 }                 override fun onAdFailedToLoad(p0: Int) {                     super.onAdFailedToLoad(p0)                     countLoadAds++                     Log.i("AdmobProvider", "onAdFailedToLoad: $countLoadAds")                     if (countLoadAds <= 3) {                         initInterstitial(context)                     } else {                         callback?.Failed(true)                     }                 }                 override fun onAdOpened() {                     super.onAdOpened()                     Log.i("AdmobProvider", "onAdOpened: ")                 }                 override fun onAdLoaded() {                     super.onAdLoaded()                     Log.i("AdmobProvider", "onAdLoaded: ")                     if (mInterstitialAd.isLoaded) {                         callback?.Success(true)                     }                 }             }         }     }     fun showInterstitial() {         if (mInterstitialAd.isLoaded) {             mInterstitialAd.show()         }     } } 

I load ads via

ActivityA in onCreate()

AdmobProvider.init(this) override fun Success(state: Boolean) {         Handler().postDelayed({             val intent = Intent(this@ActivityA, ActivityB::class.java)             intent.putExtra("ActivityB", 1)             startActivity(intent)             finish()         }, 200)     } 

and show in ActivityB in onCreate()

if (intent.getIntExtra("ActivityB", 0) == 1) {     AdmobProvider.showInterstitial() } 

While I tested it on the phone and emulators everything was fine, but from users, a crash began to arrive in the ActivityB, mainly on Android 8+

java.lang.RuntimeException: Unable to start activity ComponentInfo{MainActivity}: d.m: lateinit property mInterstitialAd has not been initialized     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3455)     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3598)     at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2164)     at android.os.Handler.dispatchMessage(Handler.java:107)     at android.os.Looper.loop(Looper.java:241)     at android.app.ActivityThread.main(ActivityThread.java:7582)     at java.lang.reflect.Method.invoke(Native Method)     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941) Caused by: d.m: lateinit property mInterstitialAd has not been initialized     at .b.i(Unknown Source)     at .MainActivity.onCreate(Unknown Source)     at android.app.Activity.performCreate(Activity.java:7822)     at android.app.Activity.performCreate(Activity.java:7811)     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1328)     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3430) 

I understand what the error is, but I can't figure out how to fix it correctly, because if I initialize an advertisement in the second activity, I will need to load it there, but it doesn't suit me. According to statistics, 88% of cases crash in background. Please tell me how to fix it correctly?

i need display multiple ads on one page with this code:

<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script> <div id="gpt-passback650x250"> <script> window.googletag = window.googletag || {cmd: []}; googletag.cmd.push(function() { googletag.defineSlot('/162717810/xxxxx/650x250', [650, 250], 'gpt-  passback650x250').addService(googletag.pubads()); googletag.enableServices(); googletag.display('gpt-passback650x250'); }); </script> </div> 

If i use this code twice or more on page, i get error: Exception in queued GPT command TypeError: Cannot read property 'addService' of null

Code must be same, customer want paste it to page via shortcode in cms. How to solve this? Thanks

I have catalog page with all brads included. I want users after clicking on my add to open filtered catalog page with specific brand by adding GET-parameters into url. For example: site.com/catalog?good=notebooks&brand=acer

And I want to add UTM-parameters. Is it possible to make final url like: site.com/catalog?good=notebooks&brand=acer?utm_source=google&utm_medium=cpc&utm_campaign=acer_notebook&utm_content=ad1&utm_term=acer

Sorry for my bad english.

I've been tasked to extract the period comparison data from Google Ads. At the moment a user can select a comparison date period in the ads.google.com UI, to see percentage growth of their ads, from one period to another.

I'd like to extract these comparison percentages from their API.

Does anyone know if this is even possible, or do I have to calculate them myself?

I've read through the API docs, but I'm afraid I missed something.

image of google ads ui