question

benmadsen avatar image
benmadsen asked

Is there a way to send custom data to Client.PurchaseItem for Event Processing?

I'm trying to get some contextual data sent from the client passed up to the playstream handler for purchasing an item with VC. This is to support currency spend attribution in our application.

Since PurchaseItem doesn't seem to have any parameters for sending data that would be attached to an item instance (because it would be untrusted data), how would it be best to get information into a place where we could generate a player event that contained how much VC was spent, and in what context (level, fight, story, etc.)?

I've read up on these:

https://community.playfab.com/questions/4918/customdata-in-catalog-and-iteminstances-questions.html

https://community.playfab.com/content/idea/895/210537287-Atomically-Creating-Items.html

and checked out:

https://api.playfab.com/documentation/Server/method/GrantItemsToUsers

But I can't seem to find the magic combination to do what I am looking for without resorting to the following task:

1) Setup Items in the store with no price

2) Map items to prices in a bit of Title Data

3) Have clients initiate a Cloud Script request with item_id and contextual info

4) Cloud script would look up pricing data from Title Data

5) Cloud script would deduct prices

6) Cloud script would grant item

7) Cloud script would collect the information and send the event

8) Cloud script would return success / failure of "purchase" of the item

Ideally, we would rather send a chunk of contextual info from the client to the PurchaseItem event and have access to it from the 'player_vc_item_purchased' playstream event so that we can utilize existing APIs but send appropriate data in a customized analytics event after validating the data.

Player Inventory
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

The answer on this thread would apply (since we're talking about a built-in event):

https://community.playfab.com/questions/4172/custom-data-in-player-logged-in-event.html

For your custom event, you could potentially use the ItemInstanceId as part of your data, to help with associating the data from the two events.

5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

benmadsen avatar image benmadsen commented ·

That's fine, but I don't yet see a way of taking the pricing data from the vc_item_purchased event and combining it with a custom event fired from the client with the data I'd like to combine. I really don't want to trust the client either to send the pricing information separately to a custom event.

0 Likes 0 ·
benmadsen avatar image benmadsen benmadsen commented ·

I could see using the built in playstream event to add the pricing data to the item instance custom data, then calling our custom event with the contextual data... would this be prone to out of order processing of events, though?

0 Likes 0 ·
brendan avatar image brendan benmadsen commented ·

What you could do would be to set the context data in Player Read Only or Player Internal Data via a Cloud Script call, then make the PurchaseItem call and use a PlayStream Action on the purchase event to call a Cloud Script that posts the custom event. Would the work for you?

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.