@vynix-org/react-native-ads-sdk
v0.2.5
Published
This is ads sdk for vynix
Downloads
415
Readme
react-native-ads-sdk
This is react native ads sdk
Installation
npm install react-native-ads-sdkUsage
import {
useAppOpenAd,
useNativeAd,
useRewardedAd,
useInterstitialAd,
useRewardedInterstitialAd,
BannerAdComponent,
NativeAdComponent,
} from 'react-native-ads-sdk';
// app open
const { showAd } = useAppOpenAd({
adId: 'ad_id',
showOnAppForeground: true,
autoLoad: true,
});
// Banner
<BannerAdComponent
adId={'ad_normal_id'}
adHighpriorityId={'ad_highpriority_id'}
size="BANNER"
/>;
// Native default
const { preloadAd, loadAd, displayAd, refreshAd } = useNativeAd({
adKey: 'native-key',
adId: 'ad_normal_id',
adHighpriorityId: 'ad_highpriority_id',
});
<NativeAdComponent
adKey="native-key"
adId={"ad_normal_id"}
adHighpriorityId={"ad_highpriority_id"}
autoLoad={true}
onLoad={(ad: AdInstance) => console.log('Ad loaded:', ad)}
onClicked={(ad: AdInstance) => console.log('Ad clicked:', ad)}
onError={(error: string, _ad: AdInstance) =>
console.error('Ad error:', error)
}
/>
// Custom native view
import {
TestIds,
NativeAdView,
NativeAsset,
NativeAssetType,
NativeMediaView,
} from 'react-native-google-mobile-ads';
// Sẽ dùng các component view này để hiển thị info của native ads
// Tất cả info ads phải nằm trong NativeAdView, hạn chế sử dụng position absolute
// Xem NativeAdCustom trong example
const { ad, isLoading, error, isLoaded, loadAd, refreshAd } = useNativeAd({
adKey: 'native-key',
adId: 'ad_normal_id',
adHighpriorityId: 'ad_highpriority_id',
});
// ad: là data native ads trả về, dùng để hiển thị info như title, body, image, icon, video
// isLoaded: là các trạng thái load ads
// loadAd: là action load lại ads nếu như error
// refreshAd: refresh lại ads
// Reward
const { preloadAd, displayAd, refreshAd } = useRewardedAd({
adKey: 'rewarded-key',
adId: 'ad_normal_id',
adHighpriorityId: 'ad_highpriority_id',
});
// Interstitial
const { preloadAd, displayAd, refreshAd } = useInterstitialAd({
adKey: 'interstitial-ads',
adId: 'ad_normal_id',
adHighpriorityId: 'ad_highpriority_id',
});
