SDK
Use the Unity SDK guide to learn how to add Tapjoy to your project with sample code for requesting, displaying, and handling ad placements like virtual currencies or Offerwalls.
Read time 3 minutesLast updated 3 hours ago
Requesting a Placement
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. You can also implement a delegate to receive callbacks (explained below).Now you can request the content.TJPlacement p = TJPlacement.CreatePlacement("APP_LAUNCH");
Before you request content, ensure that the Tapjoy connect call has succeeded. Do not make a request before you have received the onConnectSuccess callback.if (Tapjoy.IsConnected()) { p.requestContent(); } else { Debug.LogWarning("Tapjoy SDK must be connected before you can request content."); }
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:TJPlacement.OnRequestSuccess += HandlePlacementRequestSuccess; ... public void HandlePlacementRequestSuccess(TJPlacement placement) { ... } TJPlacement.OnRequestFailure += HandlePlacementRequestFailure; ... public void HandlePlacementRequestFailure(TJPlacement placement, string error) { } TJPlacement.OnContentReady += HandlePlacementContentReady; ... public void HandlePlacementContentReady(TJPlacement placement) { // This gets called when content is ready to show. } TJPlacement.OnContentShow += HandlePlacementContentShow; ... public void HandlePlacementContentShow(TJPlacement placement) { ... } TJPlacement.OnContentDismiss += HandlePlacementContentDismiss; ... public void HandlePlacementContentDismiss(TJPlacement placement) { ... }
Displaying a Placement
To display content, usep.ShowContent();
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 HandlePlacementContentReady 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 ifif (p.IsContentReady()) { p.ShowContent(); } else { // Code to handle situation where content is not ready goes here }
p.IsContentReady()
Re-requesting the content
When you successfully display content from a placement to a user, you must request content again (for example, callp.RequestContent();
p.ShowContent();
Handling Tapjoy Content Action Requests
Some Tapjoy content types, like Reward and IAP Promotion, require your code to take action based on parameters passed by that content unit. For example, the Reward content unit specifies an item name (a string) and a quantity (an integer) to be given to the user. It is up to the application to actually adjust the user’s inventory to reflect the reward. The following delegate methods are called and passed the appropriate information from the content unit:TJPlacement.OnPurchaseRequest += HandleOnPurchaseRequest; ... public void HandleOnPurchaseRequest(TJPlacement placement, TJActionRequest request, string productId) { ... } TJPlacement.OnRewardRequest += HandleOnRewardRequest; ... public void HandleOnRewardRequest(TJPlacement placement, TJActionRequest request, string itemId, int quantity) { ... }
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:Set the entry point after creating your placement object, but before requesting content:TJEntryPoint.UNKNOWN TJEntryPoint.OTHER TJEntryPoint.MAIN_MENU TJEntryPoint.HUD TJEntryPoint.EXIT TJEntryPoint.FAIL TJEntryPoint.COMPLETE TJEntryPoint.INBOX TJEntryPoint.INIT TJEntryPoint.STORE
TJPlacement placement = TJPlacement.CreatePlacement("placementName"); placement.SetEntryPoint(TJEntryPoint.COMPLETE);