Skip to content

Instantly share code, notes, and snippets.

@arohim
Last active July 4, 2019 08:05
Show Gist options
  • Save arohim/404ef7e739436eb02e04123e0e238631 to your computer and use it in GitHub Desktop.
Save arohim/404ef7e739436eb02e04123e0e238631 to your computer and use it in GitHub Desktop.
Ad Publisher maker with Adomik
private fun makePublisherAdView(context: Context, adUnitId: String, adomik: String): PublisherAdView {
val publisherAdView = PublisherAdView(context)
publisherAdView.adUnitId = adUnitId
publisherAdView.setAdSizes(AdSize.MEDIUM_RECTANGLE)
val adRequest = PublisherAdRequest.Builder().addCustomTargeting("ad_group", adomik)
publisherAdView.loadAd(adRequest.build())
return publisherAdView
}
/**
* Adomik
*
*/
fun adomikSplitAdGroup(): String {
val randomNum = Random().nextInt(98).toDouble() / 100
return when {
randomNum < 0.09 -> "ad_ex" + floor(100 * randomNum).toInt().toString()
randomNum < 0.10 -> "ad_bc"
else -> "ad_opt"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment