4.0.4 • Published 5 years ago

cordova-plugin-hms-ads v4.0.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 years ago

cordova-plugin-hms-ads

Contents

  1. Introduction
  2. Installation Guide
  3. Cordova Example API Method Definition
  4. Configure Description
  5. Licensing and Terms

1. Introduction

This Cordova SDK code encapsulates the Huawei Ads Kit interface. It provides many APIs for your reference or use.

The package is described as follows:

  • src/main/com/huawei/hms/cordova/ads: core layer that exposes AdsKit SDK functionality to JS side.
  • www/: Public interfaces for interacting AdsKit SDK through Cordova.

2. Installation Guide

  1. Create an application on AppGallery Connect.

  2. Go to Develop > Overview > App information then download agconnect-services.json and add it to root directory.

  3. Copy package_name value from agconnect-services.json file and put it in id field of config.xml file.

  4. Download the Cordova Ads SDK Plugin.

  5. Add platform to project.

cordova platform add android
  1. Run the following command in the root directory of the Cordova project:
cordova plugin add PATH_TO_CORDOVA_ADS_SDK
  1. Check whether the Cordova ADS SDK is successfully added to plugins folder in the root directory of the Cordova project.

  2. Add jks(keystore) file to root directory. Refer to creating jks file.

  3. Add build.json file to your project's root.

{
    "android": {
        "release": {
          "keystore": "./YOUR-JKS-FILE-NAME",
          "storePassword": "STORE-PASSWORD",
          "alias": "ALIAS",
          "password" : "PASSWORD"
        },
        "debug": {
          "keystore": "./YOUR-JKS-FILE-NAME",
          "storePassword": "STORE-PASSWORD",
          "alias": "ALIAS",
          "password" : "PASSWORD"
        }
    }
  }
  1. Develop your app.

3. Cordova SDK API method definitions

Data Types

AdParam

Defines an ad request.

Field nameTypeDescription
genderintThe gender.
adContentClassificationStringAd content rating.
tagForUnderAgeOfPromiseintSpecifies whether to process ad requests as directed to users under the age of consent.
tagForChildProtectionintSpecifies whether to process ad requests according to the COPPA.
nonPersonalizedAdintSpecifies whether to request personalized ads.
appCountryStringThe country code corresponding to the language in which an ad needs to be returned for an app.
appLangStringThe language in which an ad needs to be returned for an app.
countryCodeStringThe home country code.

BannerAdOptions

Defines required information for a banner ad.

Field nameTypeDescription
adIdStringAn ad slot ID.
bannerAdSizeStringSpecifies size for banner.
bgColorStringBackground color.
anchorStringBanner position, bottom or top gravity.
bannerRefreshlongRotation interval.

SplashAdOptions

Defines required information for a splash ad.

Field nameTypeDescription
preloadbooleanWhether to preload the ad or not.
orientationintOrientation of splash screen. (Required if preload is true.)
adIdStringAn ad slot id. (Required if preload is true.)
adAdParamAdParam object. (Required if preload is true.)
sloganResIdStringDefault app launch image in portrait mode, which is displayed before a splash ad is displayed. (Android resource id)
wideSloganResIdStringDefault app launch image in landscape mode, which is displayed before a splash ad is displayed. (Android resource id)
audioFocusTypeintThe audio focus preemption policy for a video splash ad.
logoSplashAdLogoOptionsLogo options.

SplashAdLogoOptions

Defines how splash ad's logo section looks like.

Field nameTypeDescription
hiddenbooleanVisibility state of the logo portion.
anchorStringLogo placement, either "top" or "bottom"
ownerStringOwner text.
copyrightStringCopyright text.
bgintBackground color of logo portion.

SplashAdLoadOptions

Defines required information to load splash ad.

Field nameTypeDescription
orientationintOrientation of splash screen.
adIdStringAn ad slot id.
adAdParamAdParam object.

RewardAdOptions

Defines required information for a reward ad.

Field nameTypeDescription
userIdStringA user ID.
dataStringCustom data.
immersivebooleanImmersive or not.
rewardVerifyConfigRewardVerifyConfigServer-side verification parameters.

RewardVerifyConfig

Defines verify related configuration for reward ad.

Field nameTypeDescription
dataStringCustom data.
userIdStringUser ID.

InterstitialAdOptions

Defines required information for a interstitial ad.

Field nameTypeDescription
adIdStringAd slot ID.

NativeAdOptions

Defines required information for a native ad.

Field nameTypeDescription
divStringCompanion HTML div id.
templateStringNative ad view template. Options are: "small", "full", "banner", "video"

NativeAdLoadOptions

Defines required information to load native ad.

Field nameTypeDescription
adIdStringAd slot ID.
adAdParamAdParam object.
nativeAdOptionsNativeAdConfigurationNative ad configuration.

NativeAdConfiguration

Defines extra information for a native ad.

Field nameTypeDescription
adSizeAdSizeRequested ad size.
choicesPositionintPosition of an ad choice icon.
mediaAspectintAspect ratio of an ad image..
mediaDirectionintDirection of an ad image..
returnUrlsForImagesbooleanWhether the SDK is allowed to download native ad images or not.
requestCustomDislikeThisAdbooleanWhether native ad will have custom dislike this button or not.
requestMultiImagesbooleanWhether multiple ad images are requested.
videoConfigurationVideoConfigurationVideo configuration used to control video playback.

AdSize

Defines an ad size.

Field nameTypeDescription
widthintThe width in dp.
heightintThe height in dp.

VideoConfiguration

Video configuration used to control video playback.

Field nameTypeDescription
audioFocusTypeintThe video playback scenario where the audio focus needs to be obtained.
clickToFullScreenRequestbooleanWhether click to full screen request exists.
startMutedbooleanWhether a video is initially muted.

InitOptions

Initial configuration options for Ads Kit.

Field nameTypeDescription
appCodeStringApp code.
bannerFloatbooleanWhether banner ads will float on Cordova webview or not.

IsLoadingResult

Returned when .isLoading() function called on an ad.

Field nameTypeDescription
isLoadingbooleanWhether the ad is loading.

IsLoadedResult

Returned when .isLoaded() function called on an ad.

Field nameTypeDescription
isLoadedbooleanWhether the ad is loading.

OaidResult

The OAID and setting of Disable personalized ads.

Field nameTypeDescription
idstringThe current OAID.
isLimitAdTracingEnabledbooleanObtains the current setting of Disable personalized ads.

ReferrerDetails

Describes the install referrer information.

Field nameTypeDescription
responseCodeintegerConnection status. The options are as follows: -1: Failed to connect. 0: Connected successfully. 1: The service does not exist. 2: The service is not supported. 3: An error.
installReferrerstringObtains install referrer information.
referrerClickTimestamplongObtains the ad click timestamp, in milliseconds.
installBeginTimestamplongObtains the app installation timestamp, in milliseconds.

Constants

Constant NameDescription
BANNER_SIZE_360_57Banner ad size: 360 x 57 dp
BANNER_SIZE_360_144Banner ad size: 360 x 144 dp
BANNER_SIZE_160_600Banner ad size: 160 x 600 dp
BANNER_SIZE_300_250Banner ad size: 300 x 250 dp
BANNER_SIZE_320_100Banner ad size: 320 x 100 dp
BANNER_SIZE_320_50Banner ad size: 320 x 50 dp
BANNER_SIZE_468_60Banner ad size: 468 x 60 dp
BANNER_SIZE_728_90Banner ad size: 728 x 90 dp
BANNER_SIZE_DYNAMICDynamic banner ad size. The width of the parent layout and the height of the ad content are used.
BANNER_SIZE_INVALIDInvalid size. No ad can be requested using this size.
BANNER_SIZE_SMARTDynamic banner ad size. The screen width and an adaptive height are used

BannerAd

Public Method Summary

Method nameReturn TypeDescription
create(params: BannerAdOptions)Promise<BannerAd>Creates the Banner Ad.
on(eventName: String, cb: Function)undefinedSubscribe to given event.
loadAd(adParam: AdParam)Promise<>Load ad with given adParam.
pause()Promise<>Pauses any additional processing related to an ad view.
resume()Promise<>Resumes an ad view after the pause() method is called last time.
destroy()Promise<>Destroys an ad view.

Event names

You can subscribe to these events using .on function, with event name as described below.

Event NameDescription
loadedCalled when an ad is loaded successfully.
failedCalled when an ad request fails.
openedCalled when an ad is opened.
clickedCalled when an ad is tapped.
leaveCalled when an ad leaves an app.
closedCalled when an ad is closed.

SplashAd

Public Method Summary

Method nameReturn TypeDescription
create(params: SplashAdOptions)Promise<SplashAd>Creates the Splash Ad.
on(eventName: String, cb: Function)undefinedSubscribe to given event.
load(options: SplashAdLoadOptions)Promise<>Loads the splash ad.
show()Promise<>Show the splash ad.
cancel()Promise<>Close the splash ad.
pause()Promise<>Pauses any additional processing related to an ad view.
resume()Promise<>Resumes an ad view after the pause() method is called last time.
destroy()Promise<>Destroys the ad view.
isLoaded()Promise<IsLoadedResult>Checks whether the ad has been loaded or not.
isLoading()Promise<IsLoadingResult>Checks whether the ad is being loaded or not.

Event Names

You can subscribe to these events using .on function, with event name as described below.

Event NameDescription
loadedCalled when a splash ad is loaded successfully.
loadFailedCalled when a splash ad fails to be loaded.
dismissedCalled after a splash ad disappears.
showedCalled when a splash ad is displayed.
clickCalled when a splash ad is clicked.

RewardAd

Public Method Summary

Method nameReturn TypeDescription
create(params: RewardAdOptions)Promise<RewardAd>Creates the Reward Ad.
on(eventName: String, cb: Function)undefinedSubscribe to given event.
loadAd(adParam: AdParam)Promise<>Load the ad with given adParam.
show()Promise<>Show the splash ad.
pause()Promise<>Pauses any additional processing related to an ad view.
resume()Promise<>Resumes an ad view after the pause() method is called last time.
destroy()Promise<>Destroys the ad view.
isLoaded()Promise<IsLoadedResult>Checks whether the ad has been loaded or not.

Event Names

You can subscribe to these events using .on function, with event name as described below.

Event NameDescription
loadedCalled when a rewarded ad is successfully loaded.
loadFailedCalled when a rewarded ad fails to be loaded.
openedCalled when a rewarded ad is opened.
showFailedCalled when a rewarded ad fails to be displayed.
closedCalled when a rewarded ad is closed.
rewardedCalled when a rewarded ad is provided based on a rewarded ad.

InterstitialAd

Public Method Summary

Method nameReturn TypeDescription
create(params: InterstitialAdOptions)Promise<InterstitialAd>Creates the Interstitial Ad.
on(eventName: String, cb: Function)undefinedSubscribe to given event.
loadAd(adParam: AdParam)Promise<>Load the ad with given adParam.
show()Promise<>Show the ad.
destroy()Promise<>Destroys the ad view.
isLoaded()Promise<IsLoadedResult>Checks whether the ad has been loaded or not.
isLoading()Promise<IsLoadingResult>Checks whether the ad is being loaded or not.

Event Names

You can subscribe to these events using .on function, with event name as described below.

Event NameDescription
loadedCalled when a splash ad is loaded successfully.
loadFailedCalled when a splash ad fails to be loaded.
dismissedCalled after a splash ad disappears.
showedCalled when a splash ad is displayed.
clickCalled when a splash ad is clicked.
metadataChangedCalled when metadata is changed.

NativeAd

Public Method Summary

Method nameReturn TypeDescription
create(params: NativeAdOptions)Promise<InterstitialAd>Creates the Native Ad.
on(eventName: String, cb: Function)undefinedSubscribe to given event.
loadAd(params: NativeAdLoadOptions)Promise<>Load the ad with given parameters.
destroy()Promise<>Destroys the ad view.

Event Names

You can subscribe to these events using .on function, with event name as described below.

Event NameDescription
nativeAdLoadedCalled when native ad is loaded.
dislikedCalled when ad is disliked.
videoStartCalled when video started playing.
videoPlayCalled when video is playing.
videoPauseCalled when video is paused.
videoEndCalled when video is ended.
videoMuteCalled when video is muted.
loadedCalled when an ad is loaded successfully.
failedCalled when an ad request fails.
openedCalled when an ad is opened.
clickedCalled when an ad is tapped.
leaveCalled when an ad leaves an app.
closedCalled when an ad is closed.

Other Public Methods

NameReturn TypeFunction Description
HMSAds.init(opts: InitOptions)Promise<>Initialize some necessary values. You need to resolve the returning promise to be able to use Ads kit functionality.
HMSAds.getOaidResult()Promise<OaidResult>Obtains the current OAID.
HMSAds.getReferrerDetails(isTest: boolean)Promise<ReferrerDetails>Starts to connect to the install referrer service and obtains the Install Referrer information
HMSAds.disconnectFromReferrerClient()Promise<>Ends the service connection and releases all occupied resources.
HMSAds.verifyAdId(adId: String, isLimitAdTracking: boolean)Promise<VerifyResult>Verifies the OAID and setting of Disable personalized ads.

4. Configure Description

No.

5. Licensing and Terms

Apache 2.0 license.

4.0.4

5 years ago