4.0.4-300 • Published 4 years ago

react-native-hms-ads v4.0.4-300

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

react-native-hms-ads

Contents

  1. Introduction
  2. Installation Guide
  3. Function Definitions
  4. Configuration & Description
  5. Licencing & Terms

1. Intruduction

This module enables communication between Huawei Ads SDK and React Native platform. It exposes all functionality provided by Huawei Ads SDK.

2. Installation Guide

  • Download the module and copy it into 'node_modules' folder. The folder structure can be seen below;
project-name
    |_ node_modules
        |_ ...
        |_ react-native-hms-ads
        |_ ...
  • Add following lines into 'android/settings.gradle' file
include ':react-native-hms-ads'
project(':react-native-hms-ads').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-hms-ads/android')
  • Add maven repository address and AppGallery Connect service dependencies into 'android/build.gradle' file.
maven {url 'https://developer.huawei.com/repo/'}
classpath 'com.huawei.agconnect:agcp:1.2.1.301'
  • Add AppGallery Connect plugin and 'react-native-hms-ads' dependency into 'android/app/build.gradle' file.
apply plugin: 'com.huawei.agconnect'
implementation project(":react-native-hms-ads")
  • Download 'agconnect-services.json' file and put it under 'android/app' folder.

  • Put keystore file under 'android/app' folder. Add signing configuration into 'android/app/build.gradle' file.

signingConfigs {
        release {
            storeFile file('<keystore>')
            storePassword '<storePassword>'
            keyAlias '<keyAlias>'
            keyPassword '<keyPassword>'
        }

        debug {
            storeFile file('<keystore>')
            storePassword '<storePassword>'
            keyAlias '<keyAlias>'
            keyPassword '<keyPassword>'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
  • Add 'RNHMSAdsPackage' to your application.
import com.huawei.hms.rn.ads.RNHMSAdsPackage;
...
...

@Override
protected List<ReactPackage> getPackages() {
  @SuppressWarnings("UnnecessaryLocalVariable")
  List<ReactPackage> packages = new PackageList(this).getPackages();
  packages.add(new RNHMSAdsPackage());
  return packages;
}
  • Run the app by executing following command.
react-native run-android

3. Function Definitions

Components

HMSBanner

Banner ad component

import {
  HMSBanner,
  BannerAdSizes,
} from 'react-native-hms-ads';

// Simple example
<HMSBanner
  style={{height: 100}}
  bannerAdSize={{
    bannerAdSize:BannerAdSizes.B_320_100,
  }}
  adId="testw6vs28auh3"
/>

Properties

PropTypeDefinition
bannerAdSizeBannerAdSizePropThe object parameter that has banner size information. It can have width information if needed.
adIdstringAd slot id.
adParamAdParamAd request parameter.
onAdLoadedfunctionThe function to handle the event when ad loads. It gets event information object as argument which has nativeEvent as key and BannerResult object as value.
onAdFailedfunctionThe function to handle the event when ad fails to load. It gets event information object as argument which has nativeEvent as key and Error object as value.
onAdOpenedfunctionThe function to handle the event when ad is opened.
onAdClickedfunctionThe function to handle the event when ad is clicked.
onAdClosedfunctionThe function to handle the event when ad is closed.
onAdImpressionfunctionThe function to handle the event when ad impression is detected.
onAdLeavefunctionThe function to handle the event when user leaves the app.

BannerAdSizeProp

ParameterTypeDefinition
bannerAdSizestringBanner ad sizes. Check BannerAdSizes for possible values.
widthintegerIf banner ad size is 'portrait', or 'landscape', or 'currentDirection', this will be needed to set the width of the banner .

Commands

Commands can be used with component references which are created with ref prop of React component.

import {
  HMSBanner,
  BannerAdSizes,
} from 'react-native-hms-ads';

// Example for commands
let adBannerElement;
// ...
<HMSBanner
  style={{height: 100}}
  bannerAdSize={{
    bannerAdSize:BannerAdSizes.B_320_100,
  }}
  adId="testw6vs28auh3"
  ref={(el) => (adBannerElement = el)}
/>

a) loadAd()

Loads banner.

adBannerElement.loadAd()

b) setRefresh(number)

Sets a rotation interval for banner ads. Input is rotation interval, in seconds. It should range from 30 to 120.

adBannerElement.setRefresh(60)

c) pause()

Pauses any additional processing related to ad.

adBannerElement.pause()

f) resume()

Resumes ad after the pause() method is called last time.

adBannerElement.resume()

e) destroy()

Destroys ad.

adBannerElement.destroy()

Complex example

import {
  HMSBanner,
  BannerAdSizes,
  ContentClassification,
  Gender,
  NonPersonalizedAd,
  TagForChild,
  UnderAge,
} from 'react-native-hms-ads';

<HMSBanner
  style={{height: 100}}
  bannerAdSize={{
    bannerAdSize:BannerAdSizes.B_PORTRAIT,
    width: 300,
  }}
  adId="testw6vs28auh3"
  adParam={{
    adContentClassification:
      ContentClassification.AD_CONTENT_CLASSIFICATION_UNKOWN,
    gender: Gender.UNKNOWN,
    nonPersonalizedAd: NonPersonalizedAd.ALLOW_ALL,
    tagForChildProtection:
      TagForChild.TAG_FOR_CHILD_PROTECTION_UNSPECIFIED,
    tagForUnderAgeOfPromise: UnderAge.PROMISE_UNSPECIFIED,
  }}
  onAdLoaded={(e) => {
    console.log('HMSBanner onAdLoaded', e.nativeEvent);
  }}
  onAdFailed={(e) => {
    console.warn('HMSBanner onAdFailed', e.nativeEvent);
  }}
  onAdOpened={(e) => console.log('HMSBanner onAdOpened')}
  onAdClicked={(e) => console.log('HMSBanner onAdClicked')}
  onAdClosed={(e) => console.log('HMSBanner onAdClosed')}
  onAdImpression={(e) => console.log('HMSBanner onAdImpression')}
  onAdLeave={(e) => console.log('HMSBanner onAdLeave')}
/>

HMSNative

Native ad component

import {
  HMSNative,
  NativeMediaTypes,
} from 'react-native-hms-ads';

// Simple example
<HMSNative
  style={{ height: 322 }}
  displayForm={{
    mediaType: NativeMediaTypes.VIDEO,
    adId: 'testy63txaom86'
  }}
/>

Properties

ParameterTypeDefinition
displayFormDisplayFormPropThe object parameter that has ad slot id and media type information.
adParamAdParamAd request parameter.
nativeConfigNativeAdConfigurationNative ad configuration parameter.
viewOptionsViewOptionsPropView options parameter.
onNativeAdLoadedfunctionThe function to handle the event when ad loads. It gets event information object as argument which has nativeEvent as key and NativeResult object as value.
onAdDislikedfunctionThe function to handle the event when ad is disliked.
onAdFailedfunctionThe function to handle the event when ad fails to load. It gets event information object as argument which has nativeEvent as key and Error object as value.
onAdClickedfunctionThe function to handle the event when ad is clicked.
onAdImpressionfunctionThe function to handle the event when ad impression is detected.
onVideoStartfunctionThe function to handle the event when ad video starts playing.
onVideoPlayfunctionThe function to handle the event when ad video plays.
onVideoEndfunctionThe function to handle the event when ad video ends.

DisplayFormProp

ParameterTypeDefinition
mediaTypestringMedia type of the native ad. Check NativeMediaTypes for possible values.
adIdstringAd slot id.

ViewOptionsProp

ParameterTypeDefinition
showMediaContentbooleanThe option for showing media content.
mediaImageScaleTypeintegerThe image scale type. Check ScaleType for possible values
adSourceTextStyleAdTextStyleThe style of ad source.
adFlagTextStyleAdTextStyleThe style of ad flag.
titleTextStyleAdTextStyleThe style of ad title.
descriptionTextStyleAdTextStyleThe style of ad description.
callToActionStyleAdTextStyleThe style of ad call-to-action button.

Commands

Commands can be used with component references which are created with ref prop of React component.

import {
  HMSNative,
  NativeMediaTypes,
} from 'react-native-hms-ads';

// Example for commands
let adNativeElement;
// ...
<HMSNative
  style={{height: 100}}
  displayForm={{
    mediaType:NativeMediaTypes.VIDEO,
    adId:'testy63txaom86',
  }}
  ref={(el) => (adNativeElement = el)}
/>

a) loadAd()

Loads native ad.

adNativeElement.loadAd()

b) dislikeAd(string)

Dislikes ad with description.

adNativeElement.dislikeAd('Just dont like it')

c) destroy()

Destroys ad.

adNativeElement.destroy()

d) gotoWhyThisAdPage()

Goes to the page explaining why an ad is displayed.

adNativeElement.gotoWhyThisAdPage()

e) setAllowCustomClick()

Enables custom tap gestures.

adNativeElement.setAllowCustomClick()

f) recordClickEvent()

Reports a custom tap gesture.

adNativeElement.recordClickEvent()

g) recordImpressionEvent(object)

Reports an ad impression.

adNativeElement.recordImpressionEvent({myKey: 'myValue', yourKey:{ cool: true}})

Complex example

import {
  HMSNative,
  NativeMediaTypes,
  ContentClassification,
  Gender,
  NonPersonalizedAd,
  TagForChild,
  UnderAge,
  ChoicesPosition,
  Direction,
  AudioFocusType,
  ScaleType
} from 'react-native-hms-ads';

<HMSNative
  style={{height: 322}}
  displayForm={{
    mediaType:NativeMediaTypes.VIDEO,
    adId:'testy63txaom86',
  }}
  adParam={{
    adContentClassification:
      ContentClassification.AD_CONTENT_CLASSIFICATION_UNKOWN,
    gender: Gender.UNKNOWN,
    nonPersonalizedAd: NonPersonalizedAd.ALLOW_ALL,
    tagForChildProtection:
      TagForChild.TAG_FOR_CHILD_PROTECTION_UNSPECIFIED,
    tagForUnderAgeOfPromise: UnderAge.PROMISE_UNSPECIFIED,
  }}
  nativeConfig={{
    choicesPosition: ChoicesPosition.BOTTOM_RIGHT,
    mediaDirection: Direction.ANY,
    videoConfiguration: {
      audioFocusType: AudioFocusType.NOT_GAIN_AUDIO_FOCUS_ALL,
      startMuted: true,
    },
  }}
  viewOptions={{
    showMediaContent: false,
    mediaImageScaleType: ScaleType.FIT_CENTER,
    adSourceTextStyle: {color: 'red'},
    adFlagTextStyle: {backgroundColor: 'red', fontSize: 10},
    titleTextStyle: {color: 'red'},
    descriptionTextStyle: {visibility: false},
    callToActionStyle: {color: 'black', fontSize: 12},
  }}
  onNativeAdLoaded={(e) => {
    console.log('HMSNative onNativeAdLoaded', e.nativeEvent);
  }}
  onAdDisliked={(e) => console.log('HMSNative onAdDisliked')}
  onAdFailed={(e) => {
    console.warn('HMSNative onAdFailed', e.nativeEvent);
  }}
  onAdClicked={(e) => console.log('HMSNative onAdClicked')}
  onAdImpression={(e) => console.log('HMSNative onAdImpression')}
  onVideoStart={(e) => console.log('HMSNative onVideoStart')}
  onVideoPlay={(e) => console.log('HMSNative onVideoPlay')}
  onVideoEnd={(e) => console.log('HMSNative onVideoEnd')}
  ref={(el) => {
    adNativeElement = el;
  }}
/>

Modules

Methods

HMSAds.init()

Initializes the HUAWEI Ads SDK. The function returns a promise that resolves a string 'Hw Ads Initialized'.

import HMSAds from 'react-native-hms-ads';

HMSAds.init()
  .then((result) => console.log('HMSAds init, result:', result))

HMSAds.getSDKVersion()

Obtains the version number of the HUAWEI Ads SDK. The function returns a promise that resolves a string of the version number.

import HMSAds from 'react-native-hms-ads';

HMSAds.getSDKVersion()
  .then((result) => console.log('HMS getSDKVersion, result:', result));

HMSAds.setVideoMuted(boolean)

Un/mute videos.

import HMSAds from 'react-native-hms-ads';

HMSAds.setVideoMuted(true);

HMSAds.setVideoVolume(number)

Sets video volume.

import HMSAds from 'react-native-hms-ads';

HMSAds.setVideoVolume(100);

HMSAds.setRequestOptions(RequestOptions)

Provides the global ad request configuration. The function returns a promise that resolves a RequestOptions object.

import HMSAds, {
  ContentClassification,
  NonPersonalizedAd,
  TagForChild,
  UnderAge,
} from 'react-native-hms-ads';

HMSAds.setRequestOptions({
  tagForUnderAgeOfPromise: UnderAge.PROMISE_UNSPECIFIED,
  nonPersonalizedAd: NonPersonalizedAd.ALLOW_ALL,
  adContentClassification:
    ContentClassification.AD_CONTENT_CLASSIFICATION_A,
  tagForChildProtection:
    TagForChild.TAG_FOR_CHILD_PROTECTION_UNSPECIFIED,
  appCountry: "TR",
  appLang: "tr",
})
  .then((result) => console.log('HMS setRequestOptions, result:', result))

HMSAds.getRequestOptions()

Obtains the global request configuration. The function returns a promise that resolves a RequestOptions object.

import HMSAds from 'react-native-hms-ads';

HMSAds.getRequestOptions()
  .then((result) => console.log('HMS getRequestOptions, result:', result))

HMSAds.setConsent(Consent)

Provides ad consent configuration. The function returns a promise that resolves a ConsentResult object.

import HMSAds, {
  ConsentStatus,
  DebugNeedConsent,
  UnderAge,
} from 'react-native-hms-ads';

HMSAds.setConsent({
  consentStatus: ConsentStatus.NON_PERSONALIZED,
  debugNeedConsent: DebugNeedConsent.DEBUG_NEED_CONSENT,
  underAgeOfPromise: UnderAge.PROMISE_UNSPECIFIED,
  // testDeviceId: '********',
})
  .then((result) => console.log('HMS setConsent, result:', result))
  .catch((e) => console.warn('HMS setConsent, error:', e))

HMSAds.checkConsent()

Obtains ad consent configuration. The function returns a promise that resolves a ConsentResult object.

import HMSAds from 'react-native-hms-ads';

HMSAds.checkConsent()
  .then((result) => console.log('HMS checkConsent, result:', result))
  .catch((e) => console.log('HMS checkConsent, error:', e))

HMSOaid.getAdvertisingIdInfo(string)

Obtains the OAID and 'Limit ad tracking' setting. The string argument should be one of values of CallMode. The function returns a promise that resolves a AdvertisingIdClientInfo object.

import {HMSOaid, CallMode} from 'react-native-hms-ads';

let callMode = CallMode.SDK;
HMSOaid.getAdvertisingIdInfo(callMode)
  .then((result) => console.log('HMSOaid getAdvertisingIdInfo, result:', result))
  .catch((e) => console.log('HMSOaid getAdvertisingIdInfo, error:', e))

HMSOaid.verifyAdvertisingId(AdvertisingIdClientInfo)

Verifies the OAID and 'Limit ad tracking' setting. The function returns a promise that resolves a AdvertisingIdClientInfo object.

import {HMSOaid} from 'react-native-hms-ads';

// should use information obtained from 'getAdvertisingIdInfo()' function
let advertisingInfo = {
  id: "01234567-89abc-defe-dcba-987654321012",
  isLimitAdTrackingEnabled: false
}
HMSOaid.verifyAdvertisingId(advertisingInfo)
  .then((result) => console.log('HMSOaid verifyAdvertisingId, result:', result))
  .catch((e) => console.warn('HMSOaid verifyAdvertisingId, error:', e))

HMSReward.setAdId(string)

Sets ad slot id.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.setAdId("testx9dtjwj8hp"); // video ad

HMSReward.setUserId(string)

Sets user id.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.setUserId("HMS User");

HMSReward.setData(string)

Sets custom data in string.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.setData("HMS Data");

HMSReward.setVerifyConfig(VerifyConfig)

Sets server-side verification parameters.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.setVerifyConfig({userId: 'userxxxxx', data: 'dataxxxx'});

HMSReward.setAdParam(AdParam)

Sets parameters of ad request.

import {HMSReward, ContentClassification, UnderAge} from 'react-native-hms-ads';

HMSReward.setAdParam({
  adContentClassification: ContentClassification.AD_CONTENT_CLASSIFICATION_UNKOWN,
  tagForUnderAgeOfPromise: UnderAge.PROMISE_UNSPECIFIED
});

HMSReward.pause()

Pauses the ad.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.pause();

HMSReward.resume()

Resumes the ad.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.resume();

HMSReward.loadAd()

Requests ad.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.loadAd();

HMSReward.show()

Displays ad.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.show();

HMSReward.isLoaded()

Checks whether ad is successfully loaded. The function returns a promise that resolves a boolean indicating whether the ad is loaded or not.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.isLoaded()
  .then((result) => console.log('HMSReward isLoaded, result:', result))

HMSReward.allListenersRemove()

Remove all listeners for events of HMSReward.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.allListenersRemove();

HMSSplash.setAdId(string)

Sets ad slot id.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.setAdId("testd7c5cewoj6"); // video ad

HMSSplash.setLogoText(string)

Sets logo text.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.setLogoText("HMS Sample");

HMSSplash.setCopyrightText(string)

Sets copyright text.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.setCopyrightText("Copyright HMS");

HMSSplash.setOrientation(integer)

Sets screen orientation.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.setOrientation(1);

HMSSplash.setSloganResource(string)

Sets default app launch image in portrait mode, which is displayed before a splash ad is displayed.

import {HMSSplash} from 'react-native-hms-ads';
// file_name_without_extension.png added to res/drawable or res/mipmap
HMSSplash.setSloganResource("file_name_without_extension");

HMSSplash.setWideSloganResource(string)

Sets default app launch image in landscape mode, which is displayed before a splash ad is displayed.

import {HMSSplash} from 'react-native-hms-ads';
// file_name_without_extension.png added to res/drawable or res/mipmap
HMSSplash.setWideSloganResource("file_name_without_extension");

HMSSplash.setLogoResource(string)

Sets app logo.

import {HMSSplash} from 'react-native-hms-ads';
// file_name_without_extension.png added to res/drawable or res/mipmap
HMSSplash.setLogoResource("file_name_without_extension");

HMSSplash.setMediaNameResource(string)

Sets app text resource.

import {HMSSplash} from 'react-native-hms-ads';
// <string name="media_name">HUAWEI Ads</string> line inserted to strings.xml
HMSSplash.setMediaNameResource("media_name");

HMSSplash.setAudioFocusType(integer)

Sets the audio focus preemption policy for a video splash ad.

import {HMSSplash, AudioFocusType} from 'react-native-hms-ads';

HMSSplash.setAudioFocusType(AudioFocusType.GAIN_AUDIO_FOCUS_ALL);

HMSSplash.setAdParam(AdParam)

Sets parameters of ad request.

import {HMSSplash, ContentClassification, UnderAge} from 'react-native-hms-ads';

HMSSplash.setAdParam({
  adContentClassification: ContentClassification.AD_CONTENT_CLASSIFICATION_UNKOWN,
  tagForUnderAgeOfPromise: UnderAge.PROMISE_UNSPECIFIED
});

HMSSplash.pause()

Pauses ad.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.pause();

HMSSplash.resume()

Resumes ad.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.resume();

HMSSplash.destroy()

Destroys ad.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.destroy();

HMSSplash.show()

Shows ad.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.show();

HMSSplash.isLoaded()

Checks whether a splash ad has been loaded.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.isLoaded()
  .then((result) => console.log('HMSSplash isLoaded, result:', result))

HMSSplash.isLoading()

Checks whether a splash ad is being loaded.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.isLoading()
  .then((result) => console.log('HMSSplash isLoading, result:', result))

HMSSplash.allListenersRemove()

Remove all listeners for events of HMSSplash.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.allListenersRemove();

HMSInterstitial.setAdId(string)

Sets ad slot id.

import {HMSInterstitial} from 'react-native-hms-ads';

HMSInterstitial.setAdId("testb4znbuh3n2"); // video ad

HMSInterstitial.setAdParam(AdParam)

Sets parameters of ad request.

import {HMSInterstitial, ContentClassification, UnderAge} from 'react-native-hms-ads';

HMSInterstitial.setAdParam({
  adContentClassification: ContentClassification.AD_CONTENT_CLASSIFICATION_UNKOWN,
  tagForUnderAgeOfPromise: UnderAge.PROMISE_UNSPECIFIED
});

HMSInterstitial.loadAd()

Initiates a request to load an ad.

import {HMSInterstitial} from 'react-native-hms-ads';

HMSInterstitial.loadAd();

HMSInterstitial.show()

Displays an interstitial ad.

import {HMSInterstitial} from 'react-native-hms-ads';

HMSInterstitial.show();

HMSInterstitial.isLoaded()

Checks whether ad loading is complete.

import {HMSInterstitial} from 'react-native-hms-ads';

HMSInterstitial.isLoaded()
  .then((result) => console.log('HMSInterstitial isLoaded, result:', result))

HMSInterstitial.allListenersRemove()

Remove all listeners for events of HMSInterstitial.

import {HMSInterstitial} from 'react-native-hms-ads';

HMSInterstitial.allListenersRemove();

HMSInstallReferrer.startConnection(string, boolean, string)

Starts to connect to the install referrer service. The first string argument should be one of values of CallMode. And the boolean argument indicates test mode. The last string argument is the name of the package that the service receives information about. The function returns a promise that resolves a boolean indicating whether the service is successfully connected.

import {HMSInstallReferrer, CallMode} from 'react-native-hms-ads';

let callMode = CallMode.SDK;
let isTest = 'true';
let pkgName = 'com.rnhmsadsdemo'; // your app package name
HMSInstallReferrer.startConnection(callMode, isTest, pkgName)
  .then((result) => console.log('HMSInstallReferrer startConnection, result:', result))
  .catch((e) => console.warn('HMSInstallReferrer startConnection, error:', e));

HMSInstallReferrer.endConnection()

Ends the service connection and releases all occupied resources.

import {HMSInstallReferrer} from 'react-native-hms-ads';

HMSInstallReferrer.endConnection()
  .then(() => console.log('HMSInstallReferrer endConnection'))
  .catch((e) => console.warn('HMSInstallReferrer endConnection, error:', e));

HMSInstallReferrer.getReferrerDetails()

Obtains install referrer information.

import {HMSInstallReferrer} from 'react-native-hms-ads';

HMSInstallReferrer.getReferrerDetails()
  .then((result) => console.log('HMSInstallReferrer getReferrerDetails, result:', result))
  .catch((e) => console.warn('HMSInstallReferrer getReferrerDetails, error:', e));

HMSInstallReferrer.isReady()

Indicates whether the service connection is ready.

import {HMSInstallReferrer} from 'react-native-hms-ads';

HMSInstallReferrer.isReady()
  .then((result) => console.log('HMSInstallReferrer isReady, result:', result));

HMSInstallReferrer.allListenersRemove()

Remove all listeners for events of HMSInstallReferrer.

import {HMSInstallReferrer} from 'react-native-hms-ads';

HMSInstallReferrer.allListenersRemove();

Events

Events of HMSInterstitial

a) adFailed

Triggered when ad fails to load.

HMSInterstitial.adFailedListenerAdd(function)

Adds listener for adFailed event. The listener function gets Error as input.

import {HMSInterstitial} from 'react-native-hms-ads';

HMSInterstitial.adFailedListenerAdd((error) => {
  console.warn('HMSInterstitial adFailed, error: ', error);
});

HMSInterstitial.adFailedListenerRemove()

Removes listeners for adFailed event.

HMSInterstitial.adFailedListenerRemove();

b) adClosed

Triggered when ad is closed.

HMSInterstitial.adClosedListenerAdd(function)

Adds listener for adClosed event.

import {HMSInterstitial} from 'react-native-hms-ads';

HMSInterstitial.adClosedListenerAdd(() => {
  console.log('HMSInterstitial adClosed');
});

HMSInterstitial.adClosedListenerRemove()

Removes listeners for adClosed event.

HMSInterstitial.adClosedListenerRemove();

c) adLeave

Triggered when the user leaves the app.

HMSInterstitial.adLeaveListenerAdd(function)

Adds listener for adLeave event.

import {HMSInterstitial} from 'react-native-hms-ads';

HMSInterstitial.adLeaveListenerAdd(() => {
  console.warn('HMSInterstitial adLeave');
});

HMSInterstitial.adLeaveListenerRemove()

Removes listeners for adLeave event.

HMSInterstitial.adLeaveListenerRemove();

d) adOpened

Triggered when ad is displayed.

HMSInterstitial.adOpenedListenerAdd(function)

Adds listener for adOpened event.

import {HMSInterstitial} from 'react-native-hms-ads';

HMSInterstitial.adOpenedListenerAdd(() => {
  console.log('HMSInterstitial adOpened');
});

HMSInterstitial.adOpenedListenerRemove()

Removes listeners for adOpened event.

HMSInterstitial.adOpenedListenerRemove();

e) adLoaded

Triggered when ad loads.

HMSInterstitial.adLoadedListenerAdd(function)

Adds listener for adLoaded event. The listener function gets InterstitialAd as input.

import {HMSInterstitial} from 'react-native-hms-ads';

HMSInterstitial.adLoadedListenerAdd((interstitialAd) => {
  console.log('HMSInterstitial adLoaded, Interstitial Ad: ', interstitialAd);
});

HMSInterstitial.adLoadedListenerRemove()

Removes listeners for adLoaded event.

HMSInterstitial.adLoadedListenerRemove();

f) adClicked

Triggered when ad is clicked.

HMSInterstitial.adClickedListenerAdd(function)

Adds listener for adClicked event.

import {HMSInterstitial} from 'react-native-hms-ads';

HMSInterstitial.adClickedListenerAdd(() => {
  console.log('HMSInterstitial adClicked');
});

HMSInterstitial.adClickedListenerRemove()

Removes listeners for adClicked event.

HMSInterstitial.adClickedListenerRemove();

g) adImpression

Triggered when ad impression is detected.

HMSInterstitial.adImpressionListenerAdd(function)

Adds listener for adImpression event.

import {HMSInterstitial} from 'react-native-hms-ads';

HMSInterstitial.adImpressionListenerAdd(() => {
  console.log('HMSInterstitial adImpression');
});

HMSInterstitial.adImpressionListenerRemove()

Removes listeners for adImpression event.

HMSInterstitial.adImpressionListenerRemove();

Events of HMSSplash

a) adFailedToLoad

Triggered when ad fails to load.

HMSSplash.adFailedToLoadListenerAdd(function)

Adds listener for adFailedToLoad event. The listener function gets Error as input.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.adFailedToLoadListenerAdd((error) => {
  console.warn('HMSSplash adFailedToLoad, error: ', error);
});

HMSSplash.adFailedToLoadListenerRemove()

Removes listeners for adFailedToLoad event.

HMSSplash.adFailedToLoadListenerRemove();

b) adDismissed

Triggered when ad is dismissed.

HMSSplash.adDismissedListenerAdd(function)

Adds listener for adDismissed event.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.adDismissedListenerAdd(() => {
  console.log('HMSSplash adDismissed');
});

HMSSplash.adDismissedListenerRemove()

Removes listeners for adDismissed event.

HMSSplash.adDismissedListenerRemove();

c) adShowed

Triggered when ad is shown.

HMSSplash.adShowedListenerAdd(function)

Adds listener for adShowed event.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.adShowedListenerAdd(() => {
  console.log('HMSSplash adShowed');
});

HMSSplash.adShowedListenerRemove()

Removes listeners for adShowed event.

HMSSplash.adShowedListenerRemove();

d) adLoaded

Triggered when ad loads.

HMSSplash.adLoadedListenerAdd(function)

Adds listener for adLoaded event.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.adLoadedListenerAdd(() => {
  console.log('HMSSplash adLoaded');
});

HMSSplash.adLoadedListenerRemove()

Removes listeners for adLoaded event.

HMSSplash.adLoadedListenerRemove();

e) adClick

Triggered when ad is clicked.

HMSSplash.adClickListenerAdd(function)

Adds listener for adClick event.

import {HMSSplash} from 'react-native-hms-ads';

HMSSplash.adClickListenerAdd(() => {
  console.log('HMSSplash adClick');
});

HMSSplash.adClickListenerRemove()

Removes listeners for adClick event.

HMSSplash.adClickListenerRemove();

Events of HMSReward

a) adFailedToLoad

Triggered when ad fails to load.

HMSReward.adFailedToLoadListenerAdd(function)

Adds listener for adFailedToLoad event. The listener function gets Error as input.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.adFailedToLoadListenerAdd((error) => {
  console.warn('HMSReward adFailedToLoad, error: ', error);
});

HMSReward.adFailedToLoadListenerRemove()

Removes listeners for adFailedToLoad event.

HMSReward.adFailedToLoadListenerRemove();

b) adFailedToShow

Triggered when ad fails to be displayed.

HMSReward.adFailedToShowListenerAdd(function)

Adds listener for adFailedToShow event. The listener function gets Error as input.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.adFailedToShowListenerAdd((error) => {
  console.warn('HMSReward adFailedToShow, error: ', error);
});

HMSReward.adFailedToShowListenerRemove()

Removes listeners for adFailedToShow event.

HMSReward.adFailedToShowListenerRemove();

c) adClosed

Triggered when ad is closed.

HMSReward.adClosedListenerAdd(function)

Adds listener for adClosed event.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.adClosedListenerAdd(() => {
  console.log('HMSReward adClosed');
});

HMSReward.adClosedListenerRemove()

Removes listeners for adClosed event.

HMSReward.adClosedListenerRemove();

d) adOpened

Triggered when ad is opened.

HMSReward.adOpenedListenerAdd(function)

Adds listener for adOpened event.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.adOpenedListenerAdd(() => {
  console.log('HMSReward adOpened');
});

HMSReward.adOpenedListenerRemove()

Removes listeners for adOpened event.

HMSReward.adOpenedListenerRemove();

e) adLoaded

Triggered when ad loads.

HMSReward.adLoadedListenerAdd(function)

Adds listener for adLoaded event. The listener function gets RewardAd as input.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.adLoadedListenerAdd((rewardAd) => {
  console.log('HMSReward adLoaded, Reward ad: ', rewardAd);
});

HMSReward.adLoadedListenerRemove()

Removes listeners for adLoaded event.

HMSReward.adLoadedListenerRemove();

f) adRewarded

Triggered when a reward is provided.

HMSReward.adRewardedListenerAdd(function)

Adds listener for adRewarded event.

import {HMSReward} from 'react-native-hms-ads';

HMSReward.adRewardedListenerAdd((reward) => {
  console.log('HMSReward adRewarded, reward: ', reward);
});

HMSReward.adRewardedListenerRemove()

Removes listeners for adRewarded event.

HMSReward.adRewardedListenerRemove();

Events of HMSInstallReferrer

a) serviceConnected

Triggered when service connection is complete.

HMSInstallReferrer.serviceConnectedListenerAdd(function)

Adds listener for serviceConnected event. The listener function gets InstallReferrerResponse as input.

import {HMSInstallReferrer} from 'react-native-hms-ads';

HMSInstallReferrer.serviceConnectedListenerAdd((response) => {
  console.log('HMSInstallReferrer serviceConnected, response:', response);
});

HMSInstallReferrer.serviceConnectedListenerRemove()

Removes listeners for serviceConnected event.

HMSInstallReferrer.serviceConnectedListenerRemove();

b) serviceDisconnected

Triggered when service is disconnected.

HMSInstallReferrer.serviceDisconnectedListenerAdd(function)

Adds listener for serviceDisconnected event.

import {HMSInstallReferrer} from 'react-native-hms-ads';

HMSInstallReferrer.serviceDisconnectedListenerAdd(() => {
  console.log('HMSInstallReferrer serviceDisconnected');
});

HMSInstallReferrer.serviceDisconnectedListenerRemove()

Removes listeners for serviceDisconnected event.

HMSInstallReferrer.serviceDisconnectedListenerRemove();

Constants

ConsentStatus

KeyValueDefinition
PERSONALIZED0Personalized consent option.
NON_PERSONALIZED1Non-personalized consent option.
UNKNOWN2Unknown consent option.

DebugNeedConsent

KeyValueDefinition
DEBUG_DISABLED0Disabled debug option.
DEBUG_NEED_CONSENT1Consent-needed debug option.
DEBUG_NOT_NEED_CONSENT2Consent-not-needed debug option.

AudioFocusType

Whether to obtain the audio focus during video playback.

KeyValueDefinition
GAIN_AUDIO_FOCUS_ALL0Obtain the audio focus when a video is played, no matter whether the video is muted.
NOT_GAIN_AUDIO_FOCUS_WHEN_MUTE1Obtain the audio focus only when a video is played without being muted.
NOT_GAIN_AUDIO_FOCUS_ALL2Do not obtain the audio focus when a video is played, no matter whether the video is muted.

ContentClassification

Ad content rating.

KeyValueDefinition
AD_CONTENT_CLASSIFICATION_W'W'Content suitable for toddlers and older audiences.
AD_CONTENT_CLASSIFICATION_PI'PI'Content suitable for kids and older audiences.
AD_CONTENT_CLASSIFICATION_J'J'Content suitable for teenagers and older audiences.
AD_CONTENT_CLASSIFICATION_A'A'Content suitable only for adults.
AD_CONTENT_CLASSIFICATION_UNKOWN''Unknown rating.

Gender

Gender.

KeyValueDefinition
UNKNOWN0Unknown gender.
MALE1Male.
FEMALE2Female.

NonPersonalizedAd

Whether to request only non-personalized ads.

KeyValueDefinition
ALLOW_ALL0Request both personalized and non-personalized ads.
ALLOW_NON_PERSONALIZED1Request only non-personalized ads.

TagForChild

Child-directed setting.

KeyValueDefinition
TAG_FOR_CHILD_PROTECTION_FALSE0Do not process ad requests according to the Children’s Online Privacy Protection Act (COPPA).
TAG_FOR_CHILD_PROTECTION_TRUE1Process ad requests according to the COPPA.
TAG_FOR_CHILD_PROTECTION_UNSPECIFIED-1Whether to process ad requests according to the COPPA is not specified.

UnderAge

Setting directed to users under the age of consent.

KeyValueDefinition
PROMISE_FALSE0Do not process ad requests as directed to users under the age of consent.
PROMISE_TRUE1Process ad requests as directed to users under the age of consent.
PROMISE_UNSPECIFIED-1Whether to process ad requests as directed to users under the age of consent is not specified.

NativeAdAssetNames

Constant IDs of all native ad components.

KeyValueDefinition
TITLE1Title material ID.
CALL_TO_ACTION2Material ID of the action text to be displayed on a button.
ICON3Icon material ID.
DESC4Description material ID.
AD_SOURCE5Advertiser material ID.
IMAGE8Image material ID.
MEDIA_VIDEO10Multimedia view material ID.
CHOICES_CONTAINER11Ad choice material ID.

ChoicesPosition

Choice icon position constants.

KeyValueDefinition
TOP_LEFT0Top left.
TOP_RIGHT1Top right.
BOTTOM_RIGHT2Bottom right.
BOTTOM_LEFT3Bottom left.
INVISIBLE4Invisible.

Direction

Orientation constant.

KeyValueDefinition
ANY0Any orientation.
PORTRAIT1Portrait.
LANDSCAPE2Landscape.

ScaleType

Options for scaling the bounds of an image.

KeyValue
MATRIX0
FIT_XY1
FIT_START2
FIT_CENTER3
FIT_END4
CENTER5
CENTER_CROP6
CENTER_INSIDE7

BannerAdSizes

KeyValueDefinition
B_160_600'160_600'160 x 600 dp banner ad size.
B_300_250'300_250'300 x 250 dp banner ad size.
B_320_50'320_50'320 x 50 dp banner ad size.
B_320_100'320_100'320 x 100 dp banner ad size.
B_360_57'360_57'360 x 57 dp banner ad size.
B_360_144'360_144'360 x 144 dp banner ad size.
B_468_60'468_60'468 x 60 dp banner ad size.
B_728_90'728_90'728 x 90 dp banner ad size.
B_CURRENT_DIRECTION'current_direction'Banner ad size based on a based on the current device orientation and a custom width.
B_PORTRAIT'portrait'Banner ad size based on a custom width in portrait orientation.
B_SMART'smart'Dynamic banner ad size. The screen width and an adaptive height are used.
B_DYNAMIC'dynamic'Dynamic banner ad size. The width of the parent layout and the height of the ad content are used.
B_LANDSCAPE'landscape'Banner ad size based on a custom width in landscape orientation.
B_INVALID'invalid'Invalid size. No ad can be requested using this size.

NativeMediaTypes

Native ad media types.

KeyValueDefinition
VIDEO'video'Ad with video.
IMAGE_SMALL'image_small'Ad with small image.
IMAGE_LARGE'image_large'Ad with large image.

BannerMediaTypes

Banner ad media types.

KeyValueDefinition
IMAGE'image'Ad with image.

InterstitialMediaTypes

Interstitial ad media types.

KeyValueDefinition
VIDEO'video'Ad with video.
IMAGE'image'Ad with image.

RewardMediaTypes

Reward ad media types.

KeyValueDefinition
VIDEO'video'Ad with video.

SplashMediaTypes

Splash ad media types.

KeyValueDefinition
VIDEO'video'Ad with video.
IMAGE'image'Ad with image.

CallMode

Option for functions that can use Huawei SDK or Aidl service.

KeyValueDefinition
SDK'sdk'Use Huawei Ads SDK .
AIDL'aidl'(Not properly working, please prefer SDK) Use aidl service.

DataTypes

Reward

Information about the reward item in a rewarded ad.

ParameterTypeDefinition
namestringThe name of a reward item.
amountintegerThe number of reward items.

RewardAd

Rewarded ad.

ParameterTypeDefinition
userIdstringUser id.
datastringCustom data.
rewardRewardReward item.
isLoadedbooleanShows whether a rewarded ad is successfully loaded.

InterstitialAd

Interstitial ad.

ParameterTypeDefinition
adIdstringThe ad slot id.
isLoadedbooleanShows whether ad loading is complete.
isLoadingbooleanShows whether ads are being loaded.

DislikeAdReason

Obtains the reason why a user dislikes an ad.

ParameterTypeDefinition
descriptionstringThe reason why a user dislikes an ad.

VideoOperator

Video controller, which implements video control such as playing, pausing, and muting a video

ParameterTypeDefinition
aspectRationumberThe video aspect ratio.
hasVideobooleanShows whether ad content contains a video.
isCustomizeOperateEnabledbooleanShows whether a custom video control is used for a video ad.
isClickToFullScreenEnabledbooleanShows whether click to full screen option enabled for a video ad.
isMutedbooleanShows whether a video is muted.

NativeAd

Native ad.

ParameterTypeDefinition
adSourcestringAd source.
descriptionstringAd description.
callToActionstringThe text to be displayed on a button, for example, View Details or Install.
dislikeAdReasonsDislikeAdReason[]The choices of not displaying the current ad.
titlestringAd title.
videoOperatorVideoOperatorVideo operator used for the ad.
isCustomClickAllowedbooleanShows whether custom tap gestures are enabled.
isCustomDislikeThisAdEnabledbooleanShows whether custom ad closing is enabled.

AdProvider

Ad provider.

ParameterTypeDefinition
idstringId of ad provider.
namestringName of ad provider.
privacyPolicyUrlstringThe url for privacy policy.
serviceAreastringThe service area for ad (ex: 'Global' or 'Asia').

AdSize

Ad size.

ParameterTypeDefinition
heightintegerAd height, in dp.
widthintegerAd width, in dp.

BannerAdSize

Banner ad size.

ParameterTypeDefinition
heightintegerAd height, in dp.
widthintegerAd width, in dp.
heightPxintegerAd height, in pixels.
widthPxintegerAd width, in pixels.
isAutoHeightSizebooleanShows whether an adaptive height is used.
isDynamicSizebooleanShows whether a dynamic size is used.
isFullWidthSizebooleanShows whether a full-screen width is used.

VideoConfiguration

Video configuration used to control video playback.

ParameterTypeDefinition
audioFocusTypeintegerThe video playback scenario where the audio focus needs to be obtained. Check AudioFocusType for possible values.
isCustomizeOperateRequestedbooleanThe setting for using custom video control.
isStartMutedbooleanThe setting for muting video when it starts.

NativeAdConfiguration

Native Ad configuration.

ParameterTypeDefinition
adSizeAdSizeAd size.
choicesPositionintegerPosition of an ad choice icon. Check ChoicesPosition for possible values.
mediaDirectionintegerDirection of an ad image. Check Direction for possible values.
mediaAspectintegerAspect ratio of an ad image.
videoConfigurationVideoConfigurationVideo Configuration.
isRequestMultiImagesbooleanThe setting for requesting multiple ad images.
isReturnUrlsForImagesbooleanThe setting for enabling the SDK to download native ad images.

NativeAdLoader

Native Ad loader.

ParameterTypeDefinition
isLoadingbooleanShows whether ads are being loaded.

AdvertisingIdClientInfo

Information about advertised clients.

ParameterTypeDefinition
idstringThe OAID.
isLimitAdTrackingEnabledboolean'Limit ad tracking' setting.

ReferrerDetails

Describes the install referrer information.

ParameterTypeDefinition
installReferrerstringInstall referrer information.
installBeginTimestampMillisecondnumberThe app installation timestamp, in milliseconds.
installBeginTimestampSecondsnumberThe app installation timestamp, in seconds.
referrerClickTimestampMillisecondnumberThe ad click timestamp, in milliseconds.
referrerClickTimestampSecondsnumberThe ad click timestamp, in seconds.

RequestOptions

Ad request options.

ParameterTypeDefinition
adContentClassificationstringAd content rating. Check ContentClassification for possible values.
appCountrystringThe country for the app.
appLangstringThe language for the app.
nonPersonalizedAdintegerThe setting for requesting non-personalized ads. Check NonPersonalizedAd for possible values.
tagForChildProtectionintegerThe child-directed setting. Check TagForChild for possible values.
tagForUnderAgeOfPromiseintegerThe setting directed to users under the age of consent. Check UnderAge for possible values.

Consent

Ad consent object to be submitted.

ParameterTypeDefinition
consentStatusintegerConsentStatus option.
debugNeedConsentintegerDebugNeedConsent option.
underAgeOfPromiseintegerUnderAge option.
testDeviceIdstringDevice Id.

ConsentResult

Consent information from api result

ParameterTypeDefinition
consentStatusintegerStatus of consent.
isNeedConsentbooleanShows whether consent is needed.
adProvidersAdProvider[]Ad provider list.

BannerResult

Banner information from banner load event

ParameterTypeDefinition
adIdstringAd slot id.
isLoadingbooleanShows whether banner is loading.
bannerAdSizeBannerAdSizeBannerAdSize information.

NativeResult

Native ad information from native ad load event.

ParameterTypeDefinition
nativeAdNativeAdNative ad information.
nativeAdConfigurationNativeAdConfigurationNative ad configuration information.
nativeAdLoaderNativeAdLoaderNative ad loader information.

Error

Ad error.

ParameterTypeDefinition
errorCodeintegerError code.
errorMessagestringError message.

InstallReferrerResponse

Install referrer connection response.

ParameterTypeDefinition
responseCodeintegerResponse code.
responseMessagestringResponse message.

AdParam

Ad request parameters.

ParameterTypeDefinition
adContentClassificationstringAd content rating. Check ContentClassification for possible values.
appCountrystringCountry code corresponding to the language in which an ad needs to be returned for an app.
appLangstringLanguage in which an ad needs to be returned for an app.
belongCountryCodestringHome country code.
genderintegerGender. Check Gender for possible values.
nonPersonalizedAdintegerThe setting of requesting personalized ads. Check NonPersonalizedAd for possible values.
requestOriginstringOrigin of request.
tagForChildProtectionintegerThe setting of processing ad requests according to the COPPA. Check TagForChild for possible values.
tagForUnderAgeOfPromiseintegerThe setting of processing ad requests as directed to users under the age of consent. Check UnderAge for possible values.
targetingContentUrlstringTargeting content url.

VerifyConfig

Server-side verification parameter.

ParameterTypeDefinition
userIdintegerUser Id.
datastringCustom data.

AdTextStyle

ParameterTypeDefinition
fontSizenumberFont size.
colorintegerColor.
backgroundColorintegerBackground color.
visibilitybooleanVisibility.

4. Confuguration & Description

No.

5. Licencing & Terms

Apache 2.0 license.

4.0.4-1

4 years ago

4.0.4-300

4 years ago

4.0.4

4 years ago