How to start the Game with Arguments

Similar to deep links on mobile, you can start games on web with Pley Game Arguments.

Pley Game Arguments (PGA) allows you to start the game with some paramater, which the game can fetch using a Pley SDK C# method (GetGameArguments();). This allows you to create links which leads to specific states in the game, use it to link accounts across platforms, or send players a "reward link" giving them an item on startup.

The GetGameArguments method will provide any data from the URL quary parameter which starts with pga_ .:exclamation:

  1. Start the game with a URL query parameter website.com/game?pga_metadata=XXXYYYZZZ.
  2. Once the game starts, call GetGameArguments(); through the Pley Unity SDK.
  3. Recieve a PleyResult GetGameArguments(out GameArgument[] gameArguments) in return with the data.

Having the argument data clientside allows you handle the case in the C# game code.

API Reference: GetGameArguments(); documentation


Code Example

You have your game on webgame.com, on a game subpage. Then, you send this link to players: webgame.com/game?pga_reward=abc123.

In-game, you call GetGameArguments();

public class PleyArgsHandler : MonoBehaviour
{
    void Start()
    {
        if (SDK.GetGameArguments(out var parameters) == PleyResult.OK)
        {
            foreach (var arg in parameters)
            {

              Debug.Log($"Pley Game Argument: {arg}");
              //Here you can parse and handle the arguments. Inside the array you'll have the value "abc123".
							//For example granting a reward:
							GrantReward(arg);
            }
        }
    }

    void GrantReward(string code)
    {
        Debug.Log($"Granting reward: {code}");
        // Add your reward logic here. The code will be "abc123".
    }
}