Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@cafebazaar/ad-sdk

Package Overview
Dependencies
Maintainers
3
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cafebazaar/ad-sdk

CafeBazaar Advertisement SDK for Web

latest
npmnpm
Version
0.0.5
Version published
Weekly downloads
2
-75%
Maintainers
3
Weekly downloads
 
Created
Source

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 */

FAQs

Package last updated on 05 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts