Use AI In-Game Shop SDK

Before We Start

The AI In-Game Shop is supported from TENTUPLAY SDK v2021.4, so please check your installed SDK version. Before using the AI In-Game Shop, you must download and install the SDK. To learn more about this process, please refer to the following link.

TPPersonalizedOfferController

  • Identical to Personalized Offers. When the methods ShowOfferById or ShowLatestOffer are called, TPPersonalizedOfferController will dynamically retrieve offers generated for each player(player_uuid) and display said offer on Scene.

  • ShowOfferById and ShowLatestOfferare methods of TPPersonalizedOffer class, TPPersonalizedOffer is the class for displaying TENTUPLAY’s personalized offers.

Implementing In Unity

TPPersonalizedOfferController.prefab can be found in the location below, and contains TPPersonalizedOfferController.cs script as a component.

  • Assets/TentuPlay/TPPersonalizedOfferTemplates/TPPersonalizedOfferController.prefab

  • Add TPPersonalizedOfferController game objects to the Scene.

  • By utilizing the parameter value of tpPersonalizedOfferController GameObject call ShowOfferById or ShowLatestOffer. After, TentuPlay will automatically show offers. Please refer to the example code below.

Example Code

  • For more detailed examples please refer to Assets/ShingGoongDemo/Scripts/TentuplayRelated/TentuPlayCRMPlayerController.cs and Assets/ShingGoongDemo/Scripts/TentuplayRelated/MailBoxOpen_offer.cs.

public void ShowPersonalizedOffer()
{
TPPersonalizedOffer myTPOffer = new TPPersonalizedOffer();
StartCoroutine(
myTPOffer.ShowOfferById(tpPersonalizedOfferController, player_uuid, "en", offer_id, (response => { })));
}

Example Images

[An image of a automatically generated AI In-Game Shop Message1]
[An image of a automatically generated AI In-Game Shop Message2]

If ShowOfferById or ShowLatestOfferis called, TentuPlayAIOffer is generated as a child of TPPersonalizedOfferController within the Scene (TPPersonalizedOfferController.ShowOffer). The image entered into the console will become a Texture/Raw Image of OfferImage (differs by version).

[An image of TentuPlayAIOffer created as a child of TPPersonalizedOfferController]

Personalized Offers and AI In-Game Shop offers are differentiated via OfferInfo.offerType.

Step 1: Create a Message Template

First, create a message template in Unity. Customize TentuPlayAIOffer‘s child(BackgroundImage, Title’s Rect Transform, etc) to fit your game’s style.

[ TentuPlayAIOffer's child ]
[ Default message templates included within the TENTUPLAY SDK ]

Each of the childs of TentuPlayAIOffer can be customized to fit a game’s style. However, we advise that the following categories do not be changed.

Category

Editable aspects

Uneditable aspects

Reason

BackgroundImage

Rect Transform component’s content

Raw Image component

The selected image in the console is added as a Raw Image Component..

Title

Rect Transform, Text component’s content

Text Component's Text

The selected personalized message is overwritten onto the Text Component’s Text.

Message

Rect Transform, Text component's content

Text Component's Text

The selected personalized message is overwritten onto the Text Component’s Text.

ProductImage

Rect Transform component’s content

Image Component's Source Image

The personalized Image Component’s Source Image is overwritten dynamically.

ProductButton

Rect Transform component’s content,Image

On Click event

When a button is clicked (On Click) the event GoToOfferEvent is used.

Price

Rect Transform, Text component’s content

Text Component's Text

The personalized Text Component’s Text is overwritten dynamically..

CloseButton

Rect Transform component’s content

On Click event

When a button is clicked (On Click) the event CloseOfferEvent is used.

Toggle

Rect Transform component’s content, Image

On Value Changed event

When the toggle is checked (On Value Changed) the event CheckDoNotShowToday is used.

ToggleMessage

Rect Transform, Text component’s content

Text Component's Text

The selected image in the console is overwritten onto the Text Component’s Text.

The messages templates which are edited here are applied to all messages sent from the AI In-Game Shop.

Step 2: Edit Code Within Unity

Edit the script so that the AI In-Game Shop messages can be shown in-game. The following script is a component of TentuPlayAIOffer.prefab and can be found at the following location:

Assets/TentuPlay/TPPersonalizedOfferTemplates/TentuPlayAIoffer.cs

[ TentuPlayAIOffer.cs file location ]

Edit the following method as follows. If this is not done correctly, the messages from the AI In-Game Shop will not work as intended.

AI Important Notes for Utilizing the AI In-Game Shop

There needs to be internal logic within the game to bring the following categories utilizing product_index or purchasable_slug.

  • Sprite : The image of the product recommended by the AI In-Game Shop

  • price : The price of the product recommended by the AI In-Game Shop

  • purchase_link : A link to a purchase page of the product or the product recommended by the AI In-Game Shop

PlaceOffer

  • For specific code, please refer to TentuPlayAIOffer.cs.

This method operates before the AI In-Game Shop message is shown on screen. Before an AI In-Game Shop message generated by TentuPlay AI is shown, it must retrieve the recommended product and related information. PlaceOffer operates through the following 3 stages to retrievel product related information, and during this process if an error occurs, it will return -1 and must be made so that a message does not appear.

1. First, the purchase_link of the product that TentuPlay AI recommends must be called. If the csv file uploaded on the TentuPlay console > Ai-In Game Shop > Shop Operation > Setting/Management > Information Upload tab has action links in the purchase_link column, the TentuPlay SDK can retrieve the recommended product’s purchase_link via the GetRecommendedProduct method and recommendedProduct class through the following way.

purchase_link = recommendedProduct.purchase_link;

If, in the csv file, the purchase_link column was not filled with an action link, the recommended item's purchase_link must be retrieved via the product's product_index or purchasable_slug. You can retrieve the purchase_link of a product via its product_index or purchasable_slug as in the example below

purchase_link = getProductUrl(purchasable_slug); // a custom method to retrieve a product's purchase_link

2. The Sprite and price of the product recommended by TentuPlay's AI must be retrieved . You can retrieve a product's Sprite and price via the product's product_index or purchasable_slug as in the example below.

ProductInfo productInfo = GetProductInfoDemo(purchasable_slug); // Sprite, price(string)를 가져오기 위한 커스텀 메소드
Sprite sprite = productInfo.sprite;
string price =productInfo.price;

3. The messages sent via the AI In-Game Shop must be checked for validity before sending. For example, if a product recommended via an AI In-Game Shop message has a number of purchase limit, it must be checked if a player can purchase the product. If a player has already reached the purchase limit of the recommended product and cannot purchase any more of said product, it must be set to return -1 and not show a message to the player. An example you can reference is noted below. Most game developers will have internal logic to check a message's validity before sending, and we recommend applying this in-game internal logic to messages being sent by the AI In-Game Shop.

bool val = validateproduct(player_id, product_index); // a custom method to retrieve a product's validity
if (!val)
return -1;

If you wish to run your code and debug live in Unity, there are additional tasks which need to be done in the TentuPlay console. For specifics, please refer to the page below.

Need Help?

Do you have questions? Join TENTUPLAY Discord if you have any questions.