@cafebazaar/ad-sdk
v0.0.5
Published
CafeBazaar Advertisement SDK for Web
Downloads
14
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 topreload
?canShow:
is it ok to callshow
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 thecanShow
state before callingshow
method.appId
: current app id (that setted up withinit
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 */