Code Monkey home page Code Monkey logo

sevio-react-sdk's Introduction

Sevio React SDK

This is a unofficial third-party React client SDK for integrating Sevio into your React applications. The SDK provides components and hooks to easily manage and display advertisements using Sevio's services.

Table of Contents

Installation

Install the SDK via npm:

npm install git+https://github.com/ChristianTucker/sevio-react-sdk

Getting Started

Provider Setup

To use the Sevio SDK, you need to wrap your application with the <SevioProvider> component. This provider must be placed at a top level in your application and requires two properties: accountId and inventoryId, both of which are provided by Sevio.

import React from 'react';
import ReactDOM from 'react-dom';
import { SevioProvider } from 'sevio-react-sdk/context';

const App = () => (
  <SevioProvider accountId="your-account-id" inventoryId="your-inventory-id">
    {/* Your application components */}
  </SevioProvider>
);

ReactDOM.render(<App />, document.getElementById('root'));

Using the useSevio Hook

The useSevio hook can be used to access Sevio context properties within your components. It provides access to various properties and methods to manage advertisements. However, this hook will likely go unused as advertisement state is managed automagically by the <SevioAdvertisement> component. refreshZone is only used in cases where you need direct control over advertisement refreshing, make sure to verify your use case with Sevio first, most people do not need this and it may get your account disabled if you abuse it.

import React from 'react';
import { useSevio } from 'sevio-react-sdk/hooks';

const MyComponent = () => {
  const { initialized, advertisements, setAdvertisements, refreshZone, debugEnabled } = useSevio();
  // ...
  return ( ... );
};

Sevio Context Properties

The SevioContextProps interface extends common Sevio properties and includes the following:

  • initialized: boolean: Indicates if the SDK is initialized.
  • advertisements: SevioPlacement[][]: A 2D array of advertisements.
  • setAdvertisements: React.Dispatch<React.SetStateAction<SevioPlacement[][]>>: Function to update advertisements.
  • refreshZone: (adType: AdType, zone: string) => void: Function to refresh advertisements in a specific zone.
  • debugEnabled?: boolean: Optional debug mode.

Advertisement Component

The SevioAdvertisement component is used to display advertisements. This component automatically handles the state updates to show and hide advertisements based on its placement in the component tree.

import React from 'react';
import { SevioAdvertisement } from 'sevio-react-sdk/components';

const AdComponent = () => (
  <SevioAdvertisement accountId="your-account-id" inventoryId="your-inventory-id" zone="header" adType="banner">
    {/* Optional children components */}
  </SevioAdvertisement>
);

API Reference

SevioProvider

Props:

  • accountId: string: Your Sevio account ID.
  • inventoryId: string: Your Sevio inventory ID.
  • debugEnabled?: boolean: Optional. Enable debug mode.

useSevio

Returns SevioContextProps:

  • initialized: boolean
  • advertisements: SevioPlacement[][]
  • setAdvertisements: React.Dispatch<React.SetStateAction<SevioPlacement[][]>>
  • refreshZone: (adType: AdType, zone: string) => void
  • debugEnabled?: boolean

SevioAdvertisement

Props:

  • accountId: string: Your Sevio account ID.
  • inventoryId: string: Your Sevio inventory ID.
  • zone: string: The zone where the advertisement will be displayed.
  • adType: AdType: The type of advertisement.
  • children?: React.ReactNode: Optional children components.

Example

Here is a complete example of how to use the Sevio SDK in a React application:

import React from 'react';
import ReactDOM from 'react-dom';
import { SevioProvider, SevioAdvertisement } from 'sevio-react-sdk';

const AdSection = () => {
  return (
    <div>
        <SevioAdvertisement
          zone={"<INSERT_ZONE_ID>"}
          adType={AdType.Banner}
        />
    </div>
  );
};

const App = () => (
  <SevioProvider accountId="your-account-id" inventoryId="your-inventory-id">
    <AdSection />
  </SevioProvider>
);

ReactDOM.render(<App />, document.getElementById('root'));

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes or additions.

Contact

For any questions or support with this SDK, please create an issue.

For any questions or support with sevio, please contact [email protected].

sevio-react-sdk's People

Contributors

christiantucker avatar ctucker-bc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.