nativescript-audience-network
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

nativescript-audience-network

Installation

From the command prompt go to your app's root folder and execute:

tns plugin add nativescript-audience-network

iOS currently not supported

Android

BANNER

Here are the supported functions:

createBanner

TypeScript

import * as AudienceNetwork from 'nativescript-audience-network';
import { isIOS } from "tns-core-modules/platform";

export class HomeComponent implements OnInit {


  ngOnInit(): void {
    
    // Init audienceNetwork SDK here.
    AudienceNetwork.initAds();
  }

  testing = true;
  createBanner() {
    let option: CreateBannerOptions = {
      // global test banner id
      androidBannerId: "<Your audience network banner id>",
      margins: {
        bottom: 10,
        // top:10
      },
      testing: true,
      size: AD_SIZE.STANDARD_BANNER,
    };
    AudienceNetwork.createBanner(option).then(
      () => (this.message = "Banner created"),
      (error) => (this.message = "Error creating banner: " + error)
    );
  }
}

INTERSTITIAL

To show a fullscreen ad, you can use this function. Note that Interstitial banners need to be loaded before they can be shown, and there are two ways to do that:

preloadInterstitial

Use this for instance while loading your view, so it's ready for the moment you want to actually show it (by calling showInterstitial).

preloadInterstitial(){
    let option: CreateInterstitialOptions = {
            "androidInterstitialId": "<Your audience network Interstitial id>",
            "testing": true,
            "onAdClosed": this.onInterstitialClosed.bind(this),
            "onAdClicked": this.onInterstitialClicked.bind(this)
    }
    AudienceNetwork.preloadInterstitial(option).then(
     ()=> {
      console.log(
        "interstitial preloaded - you can now call 'showInterstitial' whenever you're ready to do so"
      );
    }, (error)=> {
      console.log("preloadInterstitial error: " + error);
    }
  );
  }
  onInterstitialClosed() {
      console.log("ad closed");
  };
  onInterstitialClicked() {
      console.log("ad clicked");
  }

showInterstitial

At any moment after preloadInterstitial successfully resolves, you can call showInterstitial.

Note that when you want to use showInterstitial again, you also have to use preloadInterstitial again because those ads can't be reused.

 showInterstitial(){
    AudienceNetwork.showInterstitial()
 }

preloadRewardedVideoAd

Use this for instance while loading your view, so it's ready for the moment you want to actually show it (by calling showRewardedVideoAd).

 preloadRewardedVideoAd(){
    let option = {
      androidAdPlacementId: "<Your audience network RewardedVideo id>"
    }
    AudienceNetwork.preloadRewardedVideoAd(option).then(()=> {
      console.log(
        "RewardedVideoAd preloaded - you can now call 'showRewardedVideoAd' whenever you're ready to do so"
      );
    },(error)=> {
      console.log("preloadRewardedVideoAd error: " + error);
    }
  );
 }

showRewardedVideoAd

At any moment after preloadRewardedVideoAd successfully resolves, you can call showRewardedVideoAd.

Note that when you want to use showRewardedVideoAd again, you also have to use preloadRewardedVideoAd again because those ads can't be reused.

onRewarded is probably the only callback you need to worry about.

 showRewardedVideoAd(){
   let option: ShowRewardedOptions = {
        "onRewardedVideoAdClosed":this.onRewardedVideoAdClosed.bind(this),
        "onRewardedVideoAdOpened":this.onRewardedVideoAdOpened.bind(this),
        "onRewardedVideoCompleted":this.onRewardedVideoCompleted.bind(this),

      }
    AudienceNetwork.showRewardedVideoAd(option)
 }
  onRewardedVideoAdClosed(){
    console.log("onRewardedVideoAdClosed")
  }

  onRewardedVideoAdOpened(){
    console.log("reward clicked")
  }
  onRewardedVideoCompleted(){
    console.log("reward complete")
  }

Package Sidebar

Install

npm i nativescript-audience-network

Weekly Downloads

1

Version

1.0.3

License

Apache-2.0

Unpacked Size

54.8 kB

Total Files

17

Last publish

Collaborators

  • gvkundalwal
  • codegv