目录

Interstitial Ad

has.createInterstitialAd

has.createInterstitialAd(Object object): InterstitialAd

Creates an interstitial ad instance. Each time this method is called, a new instance is returned. An interstitial ad instance cannot be used across pages.

Since: 2.0.2

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
adUnitId string Yes

Ad unit ID.

For ad debugging purposes, you can use the test ad unit ID testb4znbuh3n2.

For official ad delivery, you need to apply for a formal ad unit ID. Before app release, go to Petal Ads Publisher Service, click Start now, and sign in to Petal Publisher Center to apply for a formal ad unit. For details, please refer to Adding/Enabling an Ad Unit.

Returns:

InterstitialAd instance.

Error codes

Error Code Error Message
17000901 adId already exists.

Example:

const interstitialAd = has.createInterstitialAd({
  adUnitId: 'testb4znbuh3n2' // The ad unit ID here is for testing only. Replace it with a formal ad unit ID.
});

InterstitialAd

Interstitial ad instance. The ad is displayed above your content and is hidden by default. You need to call InterstitialAd.show to display it.

[h2]InterstitialAd.load

InterstitialAd.load(): Promise<void>

Loads an interstitial ad.

Since: 2.0.2

Error codes

Error Code Error Message
17000201

1. Interstitial load params invalid.

2. Interstitial ad load failed.

17000601

1. can't invoke load() while is showed.

2. loadAd error.

Example:

const interstitialAd = has.createInterstitialAd({
  adUnitId: 'testb4znbuh3n2' // The ad unit ID here is for testing only. Replace it with a formal ad unit ID.
});
interstitialAd.load().then(() => {
  console.info('InterstitialAd load success');
}).catch((err) => {
  console.error('InterstitialAd load fail', err);
});

[h2]InterstitialAd.show

InterstitialAd.show(): Promise<void>

Shows an interstitial ad. You need to call InterstitialAd.load to load an interstitial ad first.

Since: 2.0.2

Error codes

Error Code Error Message
17000501

1. Interstitial show params invalid.

2. Interstitial ad show failed.

17000701

1. A rewarded video ad or interstitial ad is being played and cannot be displayed again.

2. The interval since the last ad playback is insufficient and the ad cannot be displayed.

3. showAd error.

Example:

const interstitialAd = has.createInterstitialAd({
  adUnitId: 'testb4znbuh3n2' // The ad unit ID here is for testing only. Replace it with a formal ad unit ID.
});
interstitialAd.onLoad(() => {
  console.info('InterstitialAd onLoad callback triggered');
  interstitialAd.show().then(() => {
    console.info('InterstitialAd show success');
  }).catch((err) => {
    console.error('InterstitialAd show fail', err);
  });
  interstitialAd.offLoad();
});
interstitialAd.load();

[h2]InterstitialAd.destroy

InterstitialAd.destroy()

Destroys an interstitial ad instance.

Since: 2.0.2

Error codes

Error Code Error Message
102 destroy -> Interstitial destroy params invalid.

Example:

const interstitialAd = has.createInterstitialAd({
  adUnitId: 'testb4znbuh3n2' // The ad unit ID here is for testing only. Replace it with a formal ad unit ID.
});
interstitialAd.destroy();

[h2]InterstitialAd.onLoad

InterstitialAd.onLoad(function callback)

Listens for interstitial ad loading events.

Since: 2.0.2

Parameters

Parameter Type Mandatory Description
callback function Yes Listener function for interstitial ad loading events.

Example:

const interstitialAdOnLoadFn = function() {
  console.info('InterstitialAd onLoad callback triggered');
};
const interstitialAd = has.createInterstitialAd({
  adUnitId: 'testb4znbuh3n2' // The ad unit ID here is for testing only. Replace it with a formal ad unit ID.
});
interstitialAd.onLoad(interstitialAdOnLoadFn);

[h2]InterstitialAd.offLoad

InterstitialAd.offLoad(function callback)

Removes the listener function for interstitial ad loading events.

Since: 2.0.2

Parameters

Parameter Type Mandatory Description
callback function No Listener function passed by InterstitialAd.onLoad. If this parameter is not passed, all listener functions are removed.

Example:

const interstitialAdOnLoadFn = function() {
  console.info('InterstitialAd onLoad callback triggered');
};
const interstitialAd = has.createInterstitialAd({
  adUnitId: 'testb4znbuh3n2' // The ad unit ID here is for testing only. Replace it with a formal ad unit ID.
});
interstitialAd.onLoad(interstitialAdOnLoadFn);
interstitialAd.offLoad(interstitialAdOnLoadFn);
interstitialAd.offLoad();

[h2]InterstitialAd.onError

InterstitialAd.onError(function callback)

Listens for interstitial ad error events.

Since: 2.0.2

Parameters

Parameter Type Mandatory Description
callback function Yes Listener function for interstitial ad error events.

Example:

const interstitialAdOnErrorFn = function() {
  console.error('InterstitialAd onError callback triggered');
};
const interstitialAd = has.createInterstitialAd({
  adUnitId: 'testb4znbuh3n2' // The ad unit ID here is for testing only. Replace it with a formal ad unit ID.
});
interstitialAd.onError(interstitialAdOnErrorFn);

[h2]InterstitialAd.offError

InterstitialAd.offError(function callback)

Removes the listener function for interstitial ad error events.

Since: 2.0.2

Parameters

Parameter Type Mandatory Description
callback function No Listener function passed by InterstitialAd.onError. If this parameter is not passed, all listener functions are removed.

Example:

const interstitialAdOnErrorFn = function() {
  console.error('InterstitialAd onError callback triggered');
};
const interstitialAd = has.createInterstitialAd({
  adUnitId: 'testb4znbuh3n2' // The ad unit ID here is for testing only. Replace it with a formal ad unit ID.
});
interstitialAd.onError(interstitialAdOnErrorFn);
interstitialAd.offError(interstitialAdOnErrorFn);
interstitialAd.offError();

[h2]InterstitialAd.onClose

InterstitialAd.onClose(function callback)

Listens for interstitial ad closing events.

Since: 2.0.2

Parameters

Parameter Type Mandatory Description
callback function Yes Listener function for interstitial ad closing events.

Example:

const interstitialAdOnCloseFn = function() {
  console.info('InterstitialAd onClose callback triggered');
};
const interstitialAd = has.createInterstitialAd({
  adUnitId: 'testb4znbuh3n2' // The ad unit ID here is for testing only. Replace it with a formal ad unit ID.
});
interstitialAd.onClose(interstitialAdOnCloseFn);

[h2]InterstitialAd.offClose

InterstitialAd.offClose(function callback)

Removes the listener function for interstitial ad closing events.

Since: 2.0.2

Parameters

Parameter Type Mandatory Description
callback function No Listener function passed by InterstitialAd.onClose. If this parameter is not passed, all listener functions are removed.

Example:

const interstitialAdOnCloseFn = function() {
  console.info('InterstitialAd onClose callback triggered');
};
const interstitialAd = has.createInterstitialAd({
  adUnitId: 'testb4znbuh3n2' // The ad unit ID here is for testing only. Replace it with a formal ad unit ID.
});
interstitialAd.onClose(interstitialAdOnCloseFn);
interstitialAd.offClose(interstitialAdOnCloseFn);
interstitialAd.offClose();