LogoLogo
Become a partnerSell a traffic
  • Introduction
    • Spot - Ads for mini-apps
    • How does Spot work?
    • Payments
      • How to make a deposit?
      • How to withdraw my earnings?
    • Advertisers - Campaigns
      • How to launch a campaign?
      • Moderation and rules
      • Post-campaign analysis
    • Publishers - Platforms
      • How to add a platform?
  • Code integration
    • Getting started
    • How to get an API key?
    • Code examples
  • Reference
    • API Reference
  • Other
    • Troubleshooting
    • Glossary
Powered by GitBook
LogoLogo

@ Spot Ads 2024

On this page
  • Installation
  • Basic Usage
  1. Code integration

Getting started

Installation

To start using the Spot React library, install it via npm:

npm install spot-ads-react

or with yarn:

yarn add spot-ads-react

Basic Usage

Step 1: Set up the Provider

To enable ads across your application, wrap your root component with the SpotAdsProvider component and provide your apiKey.

Example

./src/App.jsx

import { SpotAdsProvider } from "spot-ads-react";
import MyComponent from “./MyComponent”

const App = () => {
  return (
    <SpotAdsProvider apiKey="YOUR_API_KEY">
      <MyComponent />
    </SpotAdsProvider>
  );
}

export default App;

Step 2: Displaying an Ad

In any component where you want to display an ad, you can use the useSpotAd hook.

  1. Import the useSpotAd hook:

  2. Set up the ad display logic.

Example

./src/MyComponent.jsx

import { useSpotAd } from "spot-ads-react";

const MyComponent = () => {
  const spotAd = useSpotAd();

  // Define callback functions
  const onSuccess = () => {
    console.log("Ad is showed!");
    // Add reward logic here
  };

  const onError = (error) => {
    console.error("Ad failed to show:", error);
  };

  // Function to show the ad
  function showSpotAd() {
    spotAd.showAd(onSuccess, onError);
  }

  return (
    <div>
      <button onClick={showSpotAd}>Show Spot Ad</button>
    </div>
  );
}

export default MyComponent;
PreviousHow to add a platform?NextHow to get an API key?

Last updated 5 months ago