Skip to content

Devcui1301/ModuleAds

Repository files navigation

<<<<<<< HEAD

android-ads

Getting started

To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Already a pro? Just edit this README.md and make it your own. Want to make it easy? Use the template at the bottom!

Add your files

cd existing_repo
git remote add origin https://gitlab.rocketstudio.com.vn/skyapps/baseproject/android-ads.git
git branch -M main
git push -uf origin main

Integrate with your tools

Collaborate with your team

Test and Deploy

Use the built-in continuous integration in GitLab.


Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to makeareadme.com for this template.

Suggestions for a good README

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

Name

Choose a self-explaining name for your project.

Description

Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

Badges

On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

Visuals

Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

Installation

Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

Usage

Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

Support

Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

Roadmap

If you have ideas for releases in the future, it is a good idea to list them in the README.

Contributing

State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

Authors and acknowledgment

Show your appreciation to those who have contributed to the project.

License

For open source projects, say how it is licensed.

Project status

If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

RKModuleAds

  • Admob
  • MAX Mediation(Applovin)
  • Google Billing
  • Adjust
  • Appsflyer
  • Firebase auto log tracking event, tROAS

Import Ironsource

    // Init IS trong SplashActivity
    String keyIS = "85460dcd" (Key Test)
    AppIronSource.getInstance().init(TestSplash.this, keyIS , true);
    
    // Load Inter Splash
    AppIronSource.getInstance().loadSplashInterstitial(this, new AdCallback() {
        @Override
        public void onNextAction() {
            super.onNextAction();
            startActivity(new Intent(this, MainActivity.class));
        }
    }, 30000);
    // Load Banner
    AppIronSource.getInstance().loadBanner(this);
    // Load Inter
    if(!AppIronSource.getInstance().isInterstitialReady()){
        AppIronSource.getInstance().loadInterstitial(this, new AdCallback());
    }
    // Show Inter
    if(AppIronSource.getInstance().isInterstitialReady()){
        AppIronSource.getInstance().showInterstitial(this, new AdCallback(){
            @Override
            public void onNextAction() {
                super.onNextAction();
                startActivity(new Intent(this, MainActivity.class));
            }
        });
    }else{
        startActivity(new Intent(this, MainActivity.class));
    }

Import Adjust trong My Application

    AdjustConfig adjustConfig = new AdjustConfig(true, ADJUST_TOKEN);
    RKAdConfig.setAdjustConfig(adjustConfig);

Import Module

    maven { url 'https://jitpack.io' }
    implementation 'com.google.android.play:core:1.10.3'
    implementation 'com.facebook.shimmer:shimmer:0.5.0'
    implementation 'com.google.android.gms:play-services-ads:22.0.0'
    implementation 'androidx.multidex:multidex:2.0.1'

Import Mediation Admob

    maven {url 'https://android-sdk.is.com/'}
    maven {url 'https://artifact.bytedance.com/repository/pangle/'}
    maven {url 'https://dl-maven-android.mintegral.com/repository/mbridge_android_sdk_oversea'}
    
    // Mediation
    implementation 'com.google.ads.mediation:applovin:11.8.2.0'
    implementation 'com.google.ads.mediation:pangle:5.0.1.0.0'
    implementation 'com.google.ads.mediation:facebook:6.13.7.0'
    implementation 'com.google.ads.mediation:ironsource:7.3.0.0'
    implementation 'com.unity3d.ads:unity-ads:4.6.0'
    implementation 'com.google.ads.mediation:unity:4.6.1.0'
    implementation 'com.google.ads.mediation:vungle:6.12.1.0'
    implementation 'com.google.ads.mediation:mintegral:16.4.21.0'
    
    // Setup trong MyApplication
    MBridgeSDK sdk = MBridgeSDKFactory.getMBridgeSDK();
    sdk.setConsentStatus(this, MBridgeConstans.IS_SWITCH_ON);
    
     Admob.getInstance().setAppLovin(true)
     Admob.getInstance().setColony(true)
     Admob.getInstance().setFan(true)
     Admob.getInstance().setVungle(true)

Summary

Setup RKAd

Setup enviroment with id ads for project

We recommend you to setup 2 environments for your project, and only use test id during development, ids from your admob only use when needed and for publishing to Google Store

  • The name must be the same as the name of the marketing request
  • Config variant test and release in gradle
  • appDev: using id admob test while dev
  • appProd: use ids from your admob, build release (build file .aab)
      productFlavors {
      appDev {
                manifestPlaceholders = [ad_app_id: "ca-app-pub-3940256099942544~3347511713"]
                buildConfigField "String", "inter", "\"ca-app-pub-3940256099942544/1033173712\""
                buildConfigField "String", "banner", "\"ca-app-pub-3940256099942544/6300978111\""
                buildConfigField "String", "native", "\"ca-app-pub-3940256099942544/2247696110\""
                buildConfigField "String", "open_resume", "\"ca-app-pub-3940256099942544/3419835294\""
                buildConfigField "String", "RewardedAd", "\"ca-app-pub-3940256099942544/5224354917\""
                buildConfigField "Boolean", "build_debug", "true"
           }
       appProd {
            // ADS CONFIG BEGIN (required)
                manifestPlaceholders = [ad_app_id: "ca-app-pub-3940256099942544~3347511713"]
                buildConfigField "String", "inter", "\"ca-app-pub-3940256099942544/1033173712\""
                buildConfigField "String", "banner", "\"ca-app-pub-3940256099942544/6300978111\""
                buildConfigField "String", "native", "\"ca-app-pub-3940256099942544/2247696110\""
                buildConfigField "String", "open_resume", "\"ca-app-pub-3940256099942544/3419835294\""
                buildConfigField "String", "RewardedAd", "\"ca-app-pub-3940256099942544/5224354917\""
                buildConfigField "Boolean", "build_debug", "false"
            // ADS CONFIG END (required)
           }
      }

AndroidManiafest.xml

        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="${ad_app_id}" />

        // Config SDK Facebook
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />
        <meta-data
            android:name="com.facebook.sdk.ClientToken"
            android:value="@string/facebook_client_token" />

        <meta-data android:name="com.facebook.sdk.AutoInitEnabled"
            android:value="true"/>
        <meta-data android:name="com.facebook.sdk.AutoLogAppEventsEnabled"
            android:value="true"/>

        <meta-data android:name="com.facebook.sdk.AdvertiserIDCollectionEnabled"
            android:value="true"/>

Config ads

Create class Application

Configure your mediation here. using PROVIDER_ADMOB or PROVIDER_MAX

*** Note:Cannot use id ad test for production enviroment

class App extends AdsMultiDexApplication(){
    @Override
    public void onCreate() {
        super.onCreate();
    ...
        String environment = BuildConfig.build_debug ? RKAdConfig.ENVIRONMENT_DEVELOP : RKAdConfig.ENVIRONMENT_PRODUCTION;
        RKAdConfig = new RKAdConfig(this, RKAdConfig.PROVIDER_ADMOB, environment);

        // Optional: setup Adjust event
        AdjustConfig adjustConfig = new AdjustConfig(true,ADJUST_TOKEN);
        // adjustConfig.setEventAdImpression(EVENT_AD_IMPRESSION_ADJUST);
        // adjustConfig.setEventNamePurchase(EVENT_PURCHASE_ADJUST);
        RKAdConfig.setAdjustConfig(adjustConfig);

        // Optional: setup Appsflyer event
        AppsflyerConfig appsflyerConfig = new AppsflyerConfig(true,APPSFLYER_TOKEN);
        RKAdConfig.setAppsflyerConfig(appsflyerConfig);
    
        // Optional: setup client token SDK Facebook
        RKAdConfig.setFacebookClientToken(FACEBOOK_CLIENT_TOKEN)

        // Optional: enable ads resume
        RKAdConfig.setIdAdResume(BuildConfig.ads_open_app);

        // Optional: setup list device test - recommended to use
        listTestDevice.add(DEVICE_ID_TEST);
        RKAdConfig.setListDeviceTest(listTestDevice);

        RKAd.getInstance().init(this, RKAdConfig, false);

        // Auto disable ad resume after user click ads and back to app
        Admob.getInstance().setDisableAdResumeWhenClickAds(true);
        // If true -> onNextAction() is called right after Ad Interstitial showed
        Admob.getInstance().setOpenActivityAfterShowInterAds(true);
    AppOpenManager.getInstance().disableAppResumeWithActivity(SplashActivity.class);
    }
}

AndroidManiafest.xml

<application
android:name=".App"
...
>

Ads formats

SplashActivity

Ad Splash Interstitial

    RKAdCallback adCallback = new RKAdCallback() {
        @Override
        public void onNextAction() {
            super.onNextAction();
            Log.d(TAG, "onNextAction");
            startMain();
        }
    };
        RKAd.getInstance().setInitCallback(new RKInitCallback() {
            @Override
            public void initAdSuccess() {
                RKAd.getInstance().loadSplashInterstitialAds(SplashActivity.this, idAdSplash, TIME_OUT, TIME_DELAY_SHOW_AD, true, adCallback);
            }
        });

SplashActivity

Ad Splash App Open High and Interstitial

    AppOpenManager.getInstance().loadSplashOpenAndInter(SplashActivity.class,SplashActivity.this, BuildConfig.open_lunch_high,BuildConfig.inter_splash,25000, new AdCallback(){
            @Override
            public void onNextAction() {
                super.onNextAction();
                
                // startMain();
            
            }
        });

Interstitial

Load ad interstital before show Check null when Load Inter

  private fun loadInterCreate() {
    ApInterstitialAd mInterstitialAd = RKAd.getInstance().getInterstitialAds(this, idInter);
  }

Show and auto release ad interstitial

         if (mInterstitialAd.isReady()) {
                RKAd.getInstance().forceShowInterstitial(this, mInterstitialAd, new RKAdCallback() {
            @Override
            public void onNextAction() {
                super.onNextAction();
                Log.d(TAG, "onNextAction");
               startActivity(new Intent(MainActivity.this, MaxSimpleListActivity.class));
            }
                
                }, true);
            } else {
                loadAdInterstitial();
            }

Ad Banner

Latest way:

    <com.ads.control.ads.bannerAds.RKBannerAdView
        android:id="@+id/bannerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:layout_constraintBottom_toBottomOf="parent" />

call load ad banner

    bannerAdView.loadBanner(this, idBanner);

The older way:

  <include
  android:id="@+id/include"
  layout="@layout/layout_banner_control"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_alignParentBottom="true"
  app:layout_constraintBottom_toBottomOf="parent" />

call load ad banner

  RKAd.getInstance().loadBanner(this, idBanner);

Ad Native

Load ad native before show

        RKAd.getInstance().loadNativeAdResultCallback(this,ID_NATIVE_AD, com.ads.control.R.layout.custom_native_max_small,new RKAdCallback(){
            @Override
            public void onNativeAdLoaded(@NonNull ApNativeAd nativeAd) {
                super.onNativeAdLoaded(nativeAd);
               //save or show native 
            }
        });

Populate native ad to view

    RKAd.getInstance().populateNativeAdView(MainApplovinActivity.this,nativeAd,flParentNative,shimmerFrameLayout);

auto load and show native contains loading

in layout XML

      <com.ads.control.ads.nativeAds.RKNativeAdView
        android:id="@+id/RKNativeAds"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_150sdp"
        android:background="@drawable/bg_card_ads"
        app:layoutCustomNativeAd="@layout/custom_native_admod_medium_rate"
        app:layoutLoading="@layout/loading_native_medium"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

Call load native ad

 RKNativeAdView.loadNativeAd(this, idNative);

Load Ad native for recyclerView

    // ad native repeating interval
    RKAdAdapter     adAdapter = RKAd.getInstance().getNativeRepeatAdapter(this, idNative, layoutCustomNative, com.ads.control.R.layout.layout_native_medium,
                originalAdapter, listener, 4);
    
    // ad native fixed in position
        RKAdAdapter   adAdapter = RKAd.getInstance().getNativeFixedPositionAdapter(this, idNative, layoutCustomNative, com.ads.control.R.layout.layout_native_medium,
                originalAdapter, listener, 4);
    
        recyclerView.setAdapter(adAdapter.getAdapter());
        adAdapter.loadAds();

Ad Reward

Get and show reward

  ApRewardAd rewardAd = RKAd.getInstance().getRewardAd(this, idAdReward);

   if (rewardAd != null && rewardAd.isReady()) {
                RKAd.getInstance().forceShowRewardAd(this, rewardAd, new RKAdCallback());
            }
});

Ad resume

App

  override fun onCreate() {
    super.onCreate()
    AppOpenManager.getInstance().enableAppResume()
    RKAdConfig.setIdAdResume(AppOpenManager.AD_UNIT_ID_TEST);
    ...
  }
    

Billing app

Init Billing

Application

    @Override
    public void onCreate() {
        super.onCreate();
        AppPurchase.getInstance().initBilling(this,listINAPId,listSubsId);
    }

Check status billing init

 if (AppPurchase.getInstance().getInitBillingFinish()){
            loadAdsPlash();
        }else {
            AppPurchase.getInstance().setBillingListener(new BillingListener() {
                @Override
                public void onInitBillingListener(int code) {
                         loadAdsPlash();
                }
            },7000);
        }

Check purchase status

//check purchase with PRODUCT_ID
 AppPurchase.getInstance().isPurchased(this,PRODUCT_ID);
 //check purchase all
 AppPurchase.getInstance().isPurchased(this);

Purchase

 AppPurchase.getInstance().purchase(this,PRODUCT_ID);
 AppPurchase.getInstance().subscribe(this,SUBS_ID);

Purchase Listener

         AppPurchase.getInstance().setPurchaseListioner(new PurchaseListioner() {
             @Override
             public void onProductPurchased(String productId,String transactionDetails) {

             }

             @Override
             public void displayErrorMessage(String errorMsg) {

             }
         });

Get id purchased

  AppPurchase.getInstance().getIdPurchased();

Consume purchase

  AppPurchase.getInstance().consumePurchase(PRODUCT_ID);

Get price

  AppPurchase.getInstance().getPrice(PRODUCT_ID)
  AppPurchase.getInstance().getPriceSub(SUBS_ID)

Show iap dialog

InAppDialog dialog = new InAppDialog(this);
dialog.setCallback(() -> {
     AppPurchase.getInstance().purchase(this,PRODUCT_ID);
    dialog.dismiss();
});
dialog.show();

Ads rule

Always add device test to idTestList with all of your team's device

To ignore invalid ads traffic https://support.google.com/adsense/answer/16737?hl=en

Before show full-screen ad (interstitial, app open ad), alway show a short loading dialog

To ignore accident click from user. This feature is existed in library

Never reload ad on onAdFailedToLoad

To ignore infinite loop

19b65089f2c600b36537530964652da1e269845b

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages