React Demo Project
See how easy it is to integrate high-performance ads into your React app using our lightweight SDK.
1. Installation
To get started, you will need to set up a publisher account to get a
publisherToken
and code
2. Initialize AdsProvider
Next, you need to set up theAdsProvider
. This component handles all data-fetching logic and requires access to the chat messages. Place it somewhere in your component tree where messages are already available and high enough in the hierarchy to contain all ad placements (i.e., locations where ads will be rendered).
Prop | Description |
---|---|
publisherToken | Your unique publisher token |
messages | A list of messages between the assistant and the user |
userId | A unique string that should remain the same during the user’s lifetime (used for retargeting and rewarded ads) |
conversationId | Unique ID of the conversation |
enabledPlacementCodes | A list of placement codes that should be enabled for the conversation |
character | The character object used in this conversation |
onAdView | A function that will be called when an ad is viewed (optional) |
onAdClick | A function that will be called when an ad is clicked (optional) |
variantId | A string provided by the publisher to identify the user cohort in order to compare A/B test groups (optional) |
messages
array includes objects with the following properties:
Prop | Description |
---|---|
id | Unique ID of the message |
role | Role of the message (user or assistant ) |
content | Content of the message |
createdAt | Timestamp when the message was created |
character
object includes the following properties:
Prop | Description |
---|---|
name | Name of the character |
avatarUrl | URL of the character’s avatar |
isNsfw | Whether the character is NSFW |
id | Unique ID of the character |
greeting | Greeting of the character |
persona | Description of the character’s personality |
tags | Tags of the character (list of strings) |
3. Show your first ad
An ad slot is the UI element or space where an ad will be displayed. During onboarding, you will receive acode
that you need to use for each ad slot or ad format you want to display.
We will be using an InlineAd
format in this example. Copy the markup <InlineAd />
and place it in your application where it should be rendered. Don’t forget to assign messageId
as a unique identifier. For example, if you have a MessageList
component, you can show an ad after each message like this (every message will have a unique ad displayed because of messageId
).
4. Going further
<InlineAd />
, being the most versatile format, already offers advanced functionality such as rendering images and videos. If you want to style your ads, check out our Inline ad guide.