Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

AdLad

class AdLad<TPlugins extends AdLadPlugin> {
constructor(options?: AdLadOptions<TPlugins> | TPlugins[] | undefined);
private _assertNotDispossed;
private _canShowBannerAdState;
private _canShowFullScreenAdState;
private _canShowRewardedAdState;
private _createdBanners;
private _disposed;
private _gameplayStartState;
private _isShowingAd;
private _lastGameplayStartCallArgs;
private _lastGameplayStartState;
private _lastGameplayStopCallArgs;
private _loadingState;
private _manualNeedsMute;
private _manualNeedsPause;
private _needsMuteState;
private _needsPauseState;
private _plugin;
private _pluginInitializeFailed;
private _pluginInitializePromise;
private _showPluginFullScreenAd;
private _updateGameplayStartState;
get activePlugin(): TPlugins["name"] | null;
get canShowRewardedAd(): boolean;
gameplayStart: OmitMissing<CollectPluginArgsWithNever<TPlugins, "gameplayStart", 0>> extends infer TOptions ? TOptions extends Record<string, never> ? () => boolean : (options: TOptions) => boolean : never;
gameplayStop: OmitMissing<CollectPluginArgsWithNever<TPlugins, "gameplayStop", 0>> extends infer TOptions ? TOptions extends Record<string, never> ? () => boolean : (options: TOptions) => boolean : never;
get needsPause(): boolean;
get needsMute(): boolean;
get canShowFullScreenAd(): boolean;
get canShowBannerAd(): boolean;
 
customRequestsForPlugin<TPluginName extends TPlugins["name"]>(plugin: TPluginName): PromisifyProps<GetPluginFromUnionByName<TPlugins, TPluginName>["customRequests"]>;
destroyBannerAd(element: HTMLElement | string, options?: {
pluginOptions?: OmitMissing<CollectPluginArgsWithNever<TPlugins, "destroyBannerAd", 1>> | undefined;
}
): Promise<void>;
dispose(): void;
loadStart(): void;
loadStop(): void;
onCanShowBannerAdChange(cb: (canShowBannerAd: boolean) => void): void;
onCanShowFullScreenAdChange(cb: (canShowFullScreenAd: boolean) => void): void;
onCanShowRewardedAdChange(cb: (canShowRewardedAd: boolean) => void): void;
onNeedsMuteChange(cb: (needsMute: boolean) => void): void;
onNeedsPauseChange(cb: (needsPause: boolean) => void): void;
removeOnCanShowBannerAdChange(cb: (canShowBannerAd: boolean) => void): void;
removeOnCanShowFullScreenAdChange(cb: (canShowFullScreenAd: boolean) => void): void;
removeOnCanShowRewardedAdChange(cb: (canShowRewardedAd: boolean) => void): void;
removeOnNeedsMuteChange(cb: (needsMute: boolean) => void): void;
removeOnNeedsPauseChange(cb: (needsPause: boolean) => void): void;
showBannerAd(element: HTMLElement | string, options?: {
pluginOptions?: OmitMissing<CollectPluginArgsWithNever<TPlugins, "showBannerAd", 1>> | undefined;
}
): Promise<void>;
showFullScreenAd(options?: {
pluginOptions?: OmitMissing<CollectPluginArgsWithNever<TPlugins, "showFullScreenAd", 0>> | undefined;
}
): Promise<ShowFullScreenAdResult>;
showRewardedAd(options?: {
pluginOptions?: OmitMissing<CollectPluginArgsWithNever<TPlugins, "showRewardedAd", 0>> | undefined;
}
): Promise<ShowFullScreenAdResult>;
}

§Type Parameters

§
TPlugins extends AdLadPlugin
[src]

§Constructors

§
new AdLad(options?: AdLadOptions<TPlugins> | TPlugins[] | undefined)
[src]

You can instantiate the AdLad class with a list of plugins that should be supported. You can then make function calls to the AdLad instance, which will pass on requests such as showing full screen ads to the plugin that is currently active. Only a single plugin can be active, which will be picked during instantiation.

There are three methods for picking which plugin should be active:

  • First, every plugin can self report to AdLad whether it wishes to be active. Most plugins always want to be active, but some plugins can be configured to only be active depending on the domain the page is embedded on. If multiple plugins wish to be active, the first plugin from the provided list will be picked. This allows you to set a priority each plugin.
  • Secondly, you can pick a plugin using the plugin option. This will override the priority list, and the request for plugins to be active or not will be ignored.
  • Lastly, plugins can be activated using the ?adlad= query string. This will override all previous options. However, because this can potentially be abused by players in order to disable ads, there are some configurations available in order to control or completely disable this functionality.

Using the query string to select plugins is the recommended method. Doing it like <this will allow you to provide your domain including the query string to different game portals, which is a much more robust way than trying to figure out where your game is being embedded. The domains from game portals may change at any time, in which case you will have to update its plugin. The query string, on the other hand, can be configured by you and so will likely never change.

If you still want to make sure players can not disable ads using the query string, you can set invalidQueryStringPluginBehaviour to either "error" or "default"

§Properties

§
_assertNotDispossed
[src]
§
_canShowBannerAdState
[src]
§
_canShowFullScreenAdState
[src]
§
_canShowRewardedAdState
[src]
§
_createdBanners
[src]
§
_disposed
[src]
§
_gameplayStartState
[src]
§
_isShowingAd
[src]
§
_lastGameplayStartCallArgs
[src]
§
_lastGameplayStartState
[src]
§
_lastGameplayStopCallArgs
[src]
§
_loadingState
[src]
§
_manualNeedsMute
[src]
§
_manualNeedsPause
[src]
§
_needsMuteState
[src]
§
_needsPauseState
[src]
§
_plugin
[src]
§
_pluginInitializeFailed
[src]
§
_pluginInitializePromise
[src]
§
_showPluginFullScreenAd
[src]

Helper function for showing full screen and rewarded ads.

§
_updateGameplayStartState
[src]
§
activePlugin: TPlugins["name"] | null readonly
[src]

The name of the plugin that is currently active or null when no plugin is active.

§
canShowRewardedAd: boolean readonly
[src]

This is true when a plugin has initialized and supports the {@link showRewardedAd} method. When this is true, that is not a guarantee that {@link showRewardedAd} will always show an ad. It might still fail due to adblockers, time constraints, unknown reasons, etc.

§

Sends a custom request to the plugin that is currently active. Every plugin can handle these requests according their own specification. This allows plugins to extend their functionality with features that are not built-in into AdLad. For example, an sdk might have support for a happytime() call or getting an invite link.

Example usage

adLad.customRequests.myCoolCustomRequest("foo");

Properties of this object will always be callable, even if the active plugin doesn't implement the custom request. In the example above, the call will essentially be a no-op if the active plugin doesn't implement myCoolCustomRequest. You can still call it and you don't have to check if the function exists.

Plugins often share a similar signature for similar requests. When two plugins require the same arguments, you can use this just fine and your request will be forwarded to the plugin that is currently active. But it's possible that two plugins have name clashes between commands and both require a different set of parameters. In that case you can use {@link customRequestSpecific} to target your parameters to a specific plugin.

§
gameplayStart: OmitMissing<CollectPluginArgsWithNever<TPlugins, "gameplayStart", 0>> extends infer TOptions ? TOptions extends Record<string, never> ? () => boolean : (options: TOptions) => boolean : never
[src]
§
gameplayStop: OmitMissing<CollectPluginArgsWithNever<TPlugins, "gameplayStop", 0>> extends infer TOptions ? TOptions extends Record<string, never> ? () => boolean : (options: TOptions) => boolean : never
[src]
§
needsPause: boolean readonly
[src]

This is true when an ad is playing or about to play and your game should be paused. The difference between this and {@link needsMute} is that this becomes true a little sooner, the moment an ad is requested. Though the actual order in which the two change might differ per plugin. Use {@link onNeedsPauseChange} to listen for changes.

§
needsMute: boolean readonly
[src]

This is true when an ad is playing and your audio should be muted. The difference between this and {@link needsPause} is that this becomes true a little later when an ad is actually playing. Though the actual order in which the two change might differ per plugin. Use {@link onNeedsMuteChange} to listen for changes.

§
canShowFullScreenAd: boolean readonly
[src]

This is true when a plugin has initialized and supports the {@link showFullScreenAd} method. When this is true, that is not a guarantee that {@link showFullScreenAd} will always show an ad. It might still fail due to adblockers, time constraints, unknown reasons, etc.

§
canShowBannerAd: boolean readonly
[src]

This is true when a plugin has initialized and supports the {@link showBannerAd} method. When this is true, that is not a guarantee that {@link showBannerAd} will always show an ad. It might still fail due to adblockers, time constraints, unknown reasons, etc.

§Methods

§
customRequestsForPlugin<TPluginName extends TPlugins["name"]>(plugin: TPluginName): PromisifyProps<GetPluginFromUnionByName<TPlugins, TPluginName>["customRequests"]>
[src]

Similar to {@link customRequests} but targets a specific plugin. If the specified plugin is not the active plugin, this is a no-op.

Example usage

adLad.customRequestsForPlugin("plugin-name").myCoolCustomRequest("foo");
@param plugin
§
destroyBannerAd(element: HTMLElement | string, options?: {
pluginOptions?: OmitMissing<CollectPluginArgsWithNever<TPlugins, "destroyBannerAd", 1>> | undefined;
}
): Promise<void>
[src]
@param element
@param options
§
dispose(): void
[src]
§
loadStart(): void
[src]
§
loadStop(): void
[src]
§
onCanShowBannerAdChange(cb: (canShowBannerAd: boolean) => void): void
[src]

Registers a callback that is fired when {@link canShowBannerAd} changes.

@param cb
§
onCanShowFullScreenAdChange(cb: (canShowFullScreenAd: boolean) => void): void
[src]

Registers a callback that is fired when {@link canShowFullScreenAd} changes.

@param cb
§
onCanShowRewardedAdChange(cb: (canShowRewardedAd: boolean) => void): void
[src]

Registers a callback that is fired when {@link canShowRewardedAd} changes.

@param cb
§
onNeedsMuteChange(cb: (needsMute: boolean) => void): void
[src]

Registers a callback that is fired when {@link needsPause} changes. Use this to mute your game during ads.

@param cb
§
onNeedsPauseChange(cb: (needsPause: boolean) => void): void
[src]

Registers a callback that is fired when {@link needsPause} changes. Use this to pause your game during ads.

@param cb
§
removeOnCanShowBannerAdChange(cb: (canShowBannerAd: boolean) => void): void
[src]

Use this to unregister callbacks registered with {@link onCanShowBannerAdChange}.

@param cb
§
removeOnCanShowFullScreenAdChange(cb: (canShowFullScreenAd: boolean) => void): void
[src]

Use this to unregister callbacks registered with {@link onCanShowFullScreenAdChange}.

@param cb
§
removeOnCanShowRewardedAdChange(cb: (canShowRewardedAd: boolean) => void): void
[src]

Use this to unregister callbacks registered with {@link onCanShowRewardedAdChange}.

@param cb
§
removeOnNeedsMuteChange(cb: (needsMute: boolean) => void): void
[src]

Use this to unregister callbacks registered with {@link onNeedsMuteChange}.

@param cb
§
removeOnNeedsPauseChange(cb: (needsPause: boolean) => void): void
[src]

Use this to unregister callbacks registered with {@link onNeedsPauseChange}.

@param cb
§
showBannerAd(element: HTMLElement | string, options?: {
pluginOptions?: OmitMissing<CollectPluginArgsWithNever<TPlugins, "showBannerAd", 1>> | undefined;
}
): Promise<void>
[src]
@param element
@param options
§
showFullScreenAd(options?: {
pluginOptions?: OmitMissing<CollectPluginArgsWithNever<TPlugins, "showFullScreenAd", 0>> | undefined;
}
): Promise<ShowFullScreenAdResult>
[src]

Waits for the plugin to initialize and shows a full screen ad once it's ready.

@param options
@return
§
showRewardedAd(options?: {
pluginOptions?: OmitMissing<CollectPluginArgsWithNever<TPlugins, "showRewardedAd", 0>> | undefined;
}
): Promise<ShowFullScreenAdResult>
[src]

Waits for the plugin to initialize and shows a rewarded ad once it's ready.

@param options
@return