Description
In-game cross-promotion lets you reward players who have played more than one title in your studio’s portfolio. When a player checks in to a title, CloudScript reads their Publisher Data—a data store shared across all titles under the same PlayFab publisher account—to discover which other titles they have visited. If the current title has a reward defined for any of those titles, the items are granted immediately. Each cross-title reward is granted only once per player per title pair, preventing duplicate grants on future logins.How it works
Authenticate
The client calls an authentication method (for example,
LoginWithCustomID) to obtain a valid session ticket.Call the CheckIn CloudScript
Immediately after login the client calls
ExecuteCloudScript with FunctionName: "CheckIn".CheckIn reads Publisher Data
CheckIn calls server.GetUserPublisherReadOnlyData with the key CrossPromotionalTracking. This returns a JSON object whose keys are title IDs the player has previously visited and whose values contain a Redeemed array recording which cross-promotion rewards have already been granted.If the key does not yet exist, an empty tracker is created in memory.Record the current title visit
If the current title ID (
CURRENT_TITLE_CODE) is not already in the tracker, a new entry is created with an empty Redeemed array.Load the reward table from Title Data
CheckIn calls server.GetTitleData with the key CrossPromotionalRewards to retrieve the JSON map that links other title IDs to the items this title should grant.Grant unredeemed cross-promotion rewards
The script iterates over every title in the tracker. For each title that:
- Is not the current title, and
- Has not already been marked as redeemed in
trackedTitles[CURRENT_TITLE_CODE].Redeemed, and - Has a corresponding entry in the reward table
server.GrantItemsToUser from the CrossPromotional catalog. The title ID is then added to the Redeemed array so it is never granted again.Write back updated tracking data
The updated tracker is written back to Publisher Data via
server.UpdateUserPublisherReadOnlyData, ensuring the same rewards are not re-granted on the player’s next login.To fully test this recipe you need at least two titles configured under the same PlayFab publisher account. Each title must have a matching CloudScript and a
TitleData > CrossPromotionalRewards entry that references the other titles.PlayFab building blocks
- Accounts — player authentication and session management
- Player Publisher ReadOnly Data —
CrossPromotionalTrackingshared across all titles under the publisher account - Title Data —
CrossPromotionalRewardsmapping other title IDs to item grants for this title - Catalog (
CrossPromotional) — items to be granted as cross-promotion rewards - Virtual Currency — Gems (GM) used as reward currency
- CloudScript —
CheckInhandler containing all cross-title detection and grant logic
Setup
Create the Gems virtual currency
In Game Manager, go to Economy > Currencies and select New Currency. Enter:
Select Save Currency.
| Property | Value | Detail |
|---|---|---|
| Code | GM | Abbreviation for the Gems currency |
| Name | Gems | Display name |
| Initial Deposit | 5 | Starting balance for every new player |
Upload the catalog
Go to Economy > Catalogs and select Upload JSON. Select
Catalog.json from the PlayFab-JSON folder of this recipe. Ensure the catalog version is named CrossPromotional.Upload title data
In Game Manager, go to Content > Title Data. Under Title Data, select Upload JSON and provide
TitleData.json. This file defines the CrossPromotionalRewards key that maps other title IDs to the item IDs to grant.Upload the CloudScript
Go to Automation > Revisions, select Upload New Revision, choose
CloudScript.js, and select Save as revision.The CloudScript
TheCheckIn handler uses Publisher Data—shared across all of your titles—to detect cross-title play and grant rewards exactly once.
Helper functions
Helper functions
Running the example
- Unity 3D
- JavaScript
Install the PlayFab Unity SDK
Download the PlayFab Unity 3D SDK and import it into a new or existing Unity project.
Import the recipe package
Import
SimpleCrossPromotionRecipe.unitypackage from the Example-Unity3d folder (or download it from the PlayFab-Samples GitHub repo).Open the scene
In the Project window, open Assets > PlayFab Recipes > SimpleCrossPromotion > Scenes and add the scene to your Hierarchy.
Set your title ID
Select the Main Camera. In the Inspector, set Play Fab Title Id to your PlayFab title ID.
