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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cafebazaar/ad-sdk

v0.0.5

Published

CafeBazaar Advertisement SDK for Web

Downloads

22

Readme

Bazaar Advertisement Sdk

This is CafeBazaar Advertisement Sdk for Minigames. The main job of this library is to show an ad when requested.

Installation

ESM/CJS

If you are using modern bundling libraries and you've access to esm/cjs modules, you can install the library via package-managers:

npm i @cafebazaar/ad-sdk
# or
yarn add @cafebazaar/ad-sdk
# or
pnpm add @cafebazaar/ad-sdk

And then import it:

// esm
import BazaarAd from '@cafebazaar/ad-sdk';
// cjs
const BazaarAd = require('@cafebazaar/ad-sdk');

Note that the BazaarAd is a default exported module and you can't import part of it like this:

import { x } from '@cafebazaar/ad-sdk'; // 🚫 Will throw an error

IIFE

If you are on jquery era or you dont want to deal with javascript package managers, simply add an <script> tag in your <head> and set the src:

# index.html
<html>
  <head>
    <!-- ... -->
    <script src="https://www.unpkg.com/@cafebazaar/ad-sdk"></script>
  </head>
  <!-- ... -->
</html>

After this the BazaarAd object is available on globalThis.

How to use?

Step 1: Initializae

At the very begining of app, call the initialize method to setup the sdk:

BazaarAd.init('MY_APP_ID'); // void

Step 2: Preload Ads

It's a common way to preload the ad before trying to show to speed up the process. However this is step is up to you and it's optional. In order to preload ads, just call the preload method in your app initializing step:

BazaarAd.preload(); // Promise<void>

Step 3: Show an Ad

After initializing the sdk, now it's time to show an ad. The activation time is up to you and your application logic. This method will open a full viewport size dialog and load the proper ad in the screen:

BazaarAd.show(); // Promise<void>

Advanced Using

Getting Current State

There is a method called getState that you can get current state of ad sdk with it.

const currentState = BazaarAd.getState(); /* object */

The object fields described bellow:

  • isInited: is sdk initialized?
  • canPreload: is it ok to preload?
  • canShow: is it ok to call show method? (is there an ad already on screen?)
  • preloadedAdsLength: the number of ads that preloaded and ready to show. For example if your'e unsure that you can show an ad, just check the canShow state before calling show method.
  • appId: current app id (that setted up with init method)

Getting SDK version and name

Also there are name and version fields in the root of window.BazaarAd object that you may want to use.

BazaarAd.version; /* `${number}.${number}.${number}` */
BazaarAd.name; /* string */