npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ad-handler

v0.4.0

Published

an ad handler for fb

Readme

ad-handler

ad-handler is a flexible and easy-to-use TypeScript library for handling Facebook Instant Games advertisements. It provides a simple interface to load and display various types of ads, including banner ads, interstitial ads, rewarded video ads, and rewarded interstitial ads.

Features

  • Support for multiple ad types: Banner, Interstitial, Rewarded Video, and Rewarded Interstitial
  • Flexible ad loading strategy using the Chain of Responsibility pattern
  • Lifecycle hooks for ad loading and display
  • Built-in error handling and retry mechanism
  • Customizable debug logging
  • Configurable ad priority chain

Installation

Using npm:

```bash npm install ad-handler ```

Or using yarn:

```bash yarn add ad-handler ```

Usage

Here's a comprehensive example of how to use the ad-handler:

```typescript import { InitializeAdHanlder, Config, ADType } from 'ad-handler'

const adHandler = InitializeAdHanlder({ adID: { bannerID: 'YOUR_BANNER_ID', rewardedVideoID: 'YOUR_REWARDED_VIDEO_ID', interstitialID: 'YOUR_INTERSTITIAL_ID', rewardInterstitialID: 'YOUR_REWARD_INTERSTITIAL_ID', }, debugLog: true, hooks: { onAdLoadStart: (params) => { console.log('ad_load_c', params) }, onAdLoadFailed: (params) => { console.log('ad_load_fail_c', params) }, onAdLoadSuccess: (params) => { console.log('ad_load_success_c', params) }, onAdShowSuccess: (params) => { console.log('ad_show_success_c', params) if (params.type === ADType.RewardInterstitial || params.type === ADType.RewardedVideo) { console.log('ad_impression_c_100', params) } }, onAdShowFailed: (params) => { console.log('ad_show_fail_c', params) }, onRewardUnFinished: (params) => { console.log('reward ad not completed', params) }, }, priorityChain: [ADType.Interstitial, ADType.RewardInterstitial, ADType.RewardedVideo], retryCount: 3, customErrorHandler: async (error, cb) => { console.log('Custom error handler:', error) await cb() }, })

const { showAds, preloadAds, showBanner, version } = adHandler console.log('ADHanlderDebug: version', version)

// Export functions for use in other parts of your application export { showAds, preloadAds, showBanner } ```

Usage example:

```typescript // Show an ad with custom parameters showAds({ placement: 'home' })

// Preload an ad of a specific type preloadAds({ placement: 'level_complete' }, ADType.RewardedVideo)

// Show a banner ad showBanner({ position: 'bottom' }) ```

API

InitializeAdHanlder(config: Config): ADHandlerReturnType

Initializes the ad handler and returns an object with the following methods:

| Method | Description | Parameters | Return Type | | -------------- | ------------------- | ------------------------------ | ------------------------------ | | `showAds` | Display an ad | `params: any, type?: ADType` | `Promise` | | `preloadAds` | Preload an ad | `params: any, type?: ADType` | `Promise` | | `showBanner` | Display a banner ad | `params: any` | `Promise` | | `version` | Library version | - | `string` |

Config

Configuration object with the following properties:

| Property | Type | Description | Required | | ---------------------- | ------------ | ------------------------------------------ | -------- | | `adID` | `ADID` | Object containing IDs for various ad types | Yes | | `hooks` | `ADHooks` | Lifecycle hook functions | No | | `retryCount` | `number` | Retry count for ad loading | No | | `priorityChain` | `ADType[]` | Priority chain for ad types | No | | `debugLog` | `boolean` | Enable or disable debug logging | No | | `customErrorHandler` | `Function` | Custom error handler function | No |

ADType

Enum for ad types:

| Type | Description | | ---------------------- | ----------------------------------- | | `Banner` | Banner advertisement | | `Interstitial` | Interstitial advertisement | | `RewardInterstitial` | Rewarded interstitial advertisement | | `RewardedVideo` | Rewarded video advertisement |

showAdsReturnType

Possible return values for the `showAds` function:

  • `'success'`: Ad was successfully shown
  • `'Ad not completed'`: User skipped the ad (for rewarded ads)
  • `'fail'`: Ad failed to show

Advanced Usage

You can customize the ad loading priority and implement your own retry logic using the provided hooks and custom error handler. The library uses a Chain of Responsibility pattern, allowing for flexible ad type fallbacks.

Error Handling

The library includes built-in error handling with configurable retry counts and waiting times. You can also provide a custom error handler for more specific error management.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the ISC License.