Skip to content

API Reference

Namespaces

Enumerations

Interfaces

Type aliases

CreateLinkOptions

Ƭ CreateLinkOptions: Object

Options to pass to createLink.

Type declaration

Name Type Description
channel? string The entry channel to use for tracking, defaults to "SHARE".
data? unknown Payload to include with shared link.
description? string Open Graph description to display in embedded shares.
image? string Open Graph image to display in embedded shares.
title? string Open Graph title to display in embedded shares.
trackProps? Record<string, unknown> Additional tracking properties that will be sent along with the EntryFinal/EntryConversion event. The event properties will also be prefixed and stored as firstEntry and lastEntry user properties for the converted user. Eg: The link created by playpass.createLink({ trackProps: { feature: "test" }}) will send a feature event property with EntryFinal, and set the lastEntryFeature and firstEntryFeature user properties.
url? string Create a link to this explicit URL. It must have the same origin as the current document. If not specified, the current URL will be used.

Defined in

share/index.ts:36


InitOptions

Ƭ InitOptions: Object

Options to pass to init.

Type declaration

Name Type Description
gameId string -
serviceWorker? string Path to the service worker JS.
stripeAccount? string -
trackProps? Record<string, unknown> Additional tracking properties that will be sent along with the Entry event.

Defined in

init.ts:17


ShareOptions

Ƭ ShareOptions: Object

Options to pass to share.

Type declaration

Name Type Description
files? File[] Files to be included in share. For file compatibility, see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share#shareable_file_types
inReplyTo? string Optional, share type dependent, ID of a social media post at which to target this share. Twitter is only supported.
text? string Text to be shared.
trackProps? Record<string, unknown> Additional tracking properties that will be sent along with the Share events.
type? ShareType The type of share, defaults to "any".

Defined in

share/index.ts:18

Variables

storage

Const storage: Storage = cloudStorage

Game data storage.

Defined in

storage/index.ts:14

Functions

createContextLink(opts?): string

Generate a context based share link. Use this when a shareable link is desired for use outside of the share method.

Parameters

Name Type Description
opts? CreateLinkOptions CreateLinkOptions

Returns

string

Promise A string representing the shortened url containing the payload data

Defined in

share/index.ts:304


createLink(opts?): string

Generate a short link for sharing the game. Use this when a shareable link is desired for use outside of the share method.

Parameters

Name Type Description
opts? CreateLinkOptions CreateLinkOptions

Returns

string

A string representing the shortened url containing the payload data

Defined in

share/index.ts:253


getLinkData

getLinkData(): unknown

Gets the custom link data.

Returns

unknown

Defined in

links.ts:130


init

init(opts?): Promise<void>

Initialize the Playpass SDK.

Parameters

Name Type
opts? InitOptions

Returns

Promise<void>

Defined in

init.ts:29


share

share(opts?): Promise<boolean>

Open the device share dialog.

WARNING! This function must be called in a user gesture handler such as pointerup.

Sending a share with a game link:

playpass.share({
  text: "Here's a coin gift for you: " + playpass.createLink({data: { coins: 123 } }),
});

Receive data from the game link:

const data = playpass.getLinkData();
if (data) {
    console.log("Opened a link with coins!", data.coins);
}

Parameters

Name Type
opts? ShareOptions

Returns

Promise<boolean>

Whether the share was successfully sent.

Defined in

share/index.ts:91


uploadTemporaryImage

uploadTemporaryImage(canvas, type?): Promise<string>

Uploads an image to a temporary URL. The image URL will only be valid for up to 90 days.

This is designed to be used in combination with createLink() for dynamic share images.

const imageUrl = await playpass.uploadTemporaryImage(canvas);

const link = playpass.createLink({
    image: imageUrl,
});

Parameters

Name Type
canvas HTMLCanvasElement
type? "image/png" | "image/jpeg"

Returns

Promise<string>

Defined in

share/index.ts:377