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.

image (16)

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

image (17)
image (18)
  • Add TPPersonalizedOfferController game objects to the Scene.

image (19)
  • 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

image (20)
An image of a automatically generated AI In-Game Shop Message1
image (21)
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).

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

image (22)
An image of TentuPlayAIOffer created as a child of TPPersonalizedOfferController

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.

image (23)
TentuPlayAIOffer’s child
image (24)
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

image (25)
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

It also needs to add logic for getting Player’s store information in String type.

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 4 steps 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. Retrive the players' store string.

The store string should be identical to that of the 'store' column in the csv file uploaded through TentuPlay console. The GetRecommendedProduct by using the store string parses the products that matches the player’s store from the recommended products. The default value of store is "ios" in the demo game.

string store = "ios";

2. 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

3. 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); // a custom method to retrieve a product's Sprite, price(string)
Sprite sprite = productInfo.sprite;
string price =productInfo.price;

4. 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;

Getting the performance data of AI offers correctly

After you send the AI In-game Shop messages, you will get the performance data in return by the action that a user takes on them such as Open, Dismiss,or Interact. It gives the valuable information about the delivered messages (for example, what type of messages work more efficiently for players) and the recipients (for example, the persons who respond to the messages positively and how they interact with them), and offers insights about how to improve the AI offers in terms of texts and graphic interfaces. Thus, it is important to ensure that the achievement data can be retrieved correctly from AI offers you sent.

By default, you don’t have to do any further steps to make it to work unless you either modify or delete the associated code blocks of TPStashEvent() in TentuPlayAIOffer.cs. If you are not sure, make sure that you invoke all of the following methods correctly within PlaceOffer() in TentuPlayAIOffer.cs.

The methods to be called when a message is opened
TPStashEvent myStashEvent = new TPStashEvent();
myStashEvent.StashOfferEvent(
	player_uuid: player_id, offer_id: thisOffer.offer_id,
	message_status: messageStatus.Open, message_detail: purchasable_slug);

myPerOffer.OfferOpened(thisOffer.offer_id, (response) =>
        {
        });
The methods to be called when a message is closed (which is the same as those of TentuPlayAIOffer.OnCloseOfferEvent())
int r = new TPStashEvent().StashOfferEvent(
		player_uuid: thisPlayerUUID, offer_id: thisOffer.offer_id, message_status: messageStatus.Dismiss, //Dismiss!
		message_detail: purchasable_slug);
new TPUploadData().UploadData(toCheckInterval: false);
The methods to be called when a button is clicked to continue on a message (which is the same as those of TentuPlayAIOffer.OnGoToOfferEvent())
int r = new TPStashEvent().StashOfferEvent(
		player_uuid: thisPlayerUUID, offer_id: thisOffer.offer_id, message_status: messageStatus.Interact, //Interact!
	  message_detail: purchasable_slug);
new TPUploadData().UploadData(toCheckInterval: false);
  • Make sure that you assign the name of recommended product for the player to purchasable_slug. It goes for all of the methods.

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.