Documentation

Support

SDK

Import the React Native SDK guide to learn how to request and display ad placements using TJPlacement, including pre-caching content and handling callbacks for a smooth user experience.
Read time 2 minutesLast updated 3 hours ago

Requesting a Placement

Firstly, import
TJPlacement
:
import Tapjoy, { TJPlacement } from "tapjoy-react-native-sdk";
Create an instance of TJPlacement and initialize it with your placement name. Be sure the placement name string in your code exactly matches the placement name in the dashboard exactly. You can also implement a delegate to receive callbacks (explained below).
let placement = new TJPlacement("Placement Name");
Now you can request the content.
placement.requestContent();
Before you request content, ensure that the Tapjoy connect call has succeeded. Do not make a request before you have received the onConnectSuccess callback.

Pre-caching the content

For the best user experience, request content in advance of when the user might be shown that content. For example, if the placement is a button on your main menu, you might want to request content for it when your application starts, just after the Tapjoy Connect call succeeds. If you wait until the last moment to request content, it is likely the user will have to wait for the content to load, and watch a loading spinner. For ads, this makes the user less likely to interact with the ad, and therefore less likely to make money for you.

Callbacks

To get feedback on the status of the content request, implement the following callbacks:
placement.on(TJPlacement.REQUEST_DID_SUCCEED, (placement: TJPlacement) => { });
placement.on(TJPlacement.REQUEST_DID_FAIL, (placement: TJPlacement) => { });
placement.on(TJPlacement.CONTENT_IS_READY, (placement: TJPlacement) => { });
placement.on(TJPlacement.CONTENT_DID_APPEAR, (placement: TJPlacement) => { });
placement.on(TJPlacement.CONTENT_DID_DISAPPEAR, (placement: TJPlacement) => { });

Displaying a Placement

To display content, use
placement.showContent();
Check to make sure that content is ready before
showContent()
:
if (placement.isContentReady()) {
   placement.showContent();
}
The recommended best practice is to mute your app’s audio before showing content from a placement that might include video, otherwise the audio for the video and your app’s audio might conflict. Often, it is a good idea to wait until the
CONTENT_IS_READY
callback fires before showing content to the user. This way, you can be sure that the content is actually on the device, and can be shown to the user without delay. Another equivalent way is to check to see if
p.isContentReady()
is true, as in the example above.
To ensure proper functionality, prior to creating a placement object, the Tapjoy connect call needs to have been made and succeeded.

Re-requesting the content

When you successfully display content from a placement to a user, you must request content again (for example, call
placement.requestContent();
again) to "reload" the placement with another content unit. You cannot call
placement.showContent();
again. If you try to show content before requesting content, the show content will fail.
For placements that are expecting video content, the proper time to re-request content is right after the content is shown. This will pre-load the next video while the user is watching the current video. If you wait until the content is dismissed to re-request content, there will be a delay if the user immediately tries to watch another video.

Setting the Entry Point

You can optionally tell Tapjoy the 'entry point' of each placement. There are a variety of preset values to choose from:
TJEntryPointUnknown
TJEntryPointOther
TJEntryPointMainMenu
TJEntryPointHud
TJEntryPointExit
TJEntryPointFail
TJEntryPointComplete
TJEntryPointInbox
TJEntryPointInit
TJEntryPointStore
Set the entry point after creating your placement object, but before requesting content:
let placement = new TJPlacement("myPlacement");
placement.setEntryPoint(TJEntryPoint.TJEntryPointMainMenu);
placement.requestContent();