class Teak

All SDK functionality is exposed through an instance of the Teak class assigned to window.teak by the initialization snippit. Once the SDK is loaded, the class itself is accessible as window.teakClass.

Load the Teak JavasScript SDK on your page by inserting the following snipping after the <body> tag.

<script type="text/javascript">
(function(){window.teak=window.teak||[];window.teak.methods=["init","on","login","registerForNotifications","getNotificationState","incrementEvent","scheduleNotificationWithPersonalization","cancelNotification","cancelAllNotifications","setStringAttribute","setNumberAttribute","scheduleLongDistanceNotification","deleteEmail","setChannelState","setCategoryState", "registerRoute"];window.teak.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);window.teak.push(t);return window.teak}};for(var e=0;e<window.teak.methods.length;e++){var t=window.teak.methods[e];if(!window.teak[t]){window.teak[t]=window.teak.factory(t)}}})();
(function(){var n=document.createElement("script");n.type="text/javascript";n.async=true;n.src="//sdks.teakcdn.com/teak.min.js";var r=document.getElementsByTagName("script")[0];r.parentNode.insertBefore(n,r)})();
</script>

Static Attributes

NotificationState

Enum of possible states for Web Push.

Name Description

UnableToDetermine

The state of Web Push has either not been determined, or is unable to be determined due to a browser error.

Enabled

The player has granted Web Push permissions for the current site, and notifications may be sent.

Disabled

The player has denied Web Push permissions for the current site. Notifications may not be sent.

ServiceWorkerNotRegistered

No Service Worker is configured. Follow the steps in Add a Service Worker.

NotSupported

Web Push is not supported by the current browser.

AlternateVendor

The player has granted Web Push permissions for the current site, but for a different Web Push vendor or internal service. Teak cannot currently send Web Push notifications to the player, but could after calling registerForNotifications with the switchVendor parameter set to true.

RewardStatus

RewardStatus indicates the disposition of a reward claim, if it was granted or if it was denied why it was denied.

Name

Value

Description

GrantReward

"grant_reward"

The reward was granted to the player, and the RewardEvent will have a populated reward field.

Expired

"expired"

The reward has expired and is no longer claimable

AlreadyClaimed

"already_clicked"

The player has already claimed this reward and cannot claim it again

TooManyClaims

"too_many_clicks"

This reward has a limit on the number of players who can claim it, and has reached that limit

SelfClaim

"self_click"

This reward was shared by the current player, and cannot be claimed by them

ExceedMaxClaimsForDay

"exceed_max_clicks_for_day"

This reward has a limit of the number of times it can be claimed by the player in a day, and the player has reached that limit

NotForYou

"not_for_you"

This reward has a restriction on which players can claim it, and the current player is not on the list

InvalidReward

"invalid_post"

This reward was not recognized

Methods

init

Initializes the Teak SDK. This method must always be called first.

Parameters

Name

Type

Description

appId

string

Your Teak App Id

apiKey

string

Your Teak API Key

debug

boolean

Enable additional debug logging

login

Starts a session for a player, and reports additional data about the player. This method must be called in order to - Claim rewards - Track notification, link, and email clicks - Track DAU

Most Teak functionality is unavailable until this method is called.

If the additional data for the player such as their email address or Facebook ID changes during a session, call login again with the updated data.

Parameters

Name

Type

Description

playerId

string

A unique identifier for the current player

additionalData

{email: string, facebookId: string}

An object containing additional data about the player.

on

Registers a handler for a given event type.

The available event types are

  • reward: Fired when the SDK process a reward claim

  • deepLink: Fired when the SDK process a deep link

  • postLaunchSummary: Fired after the SDK initializes a session indicating the session attribution data

Types

RewardEvent

Name

Type

Description

status

The disposition of the reward claim

reward

Record<string, number> | undefined

If status is teak.RewardStatus.GrantReward, an object of internal ids for rewards to the amount given to the player

PostLaunchSummaryEvent

Name

Type

Description

launchLink

string

The URL of the current page

scheduleName

string | undefined

If the session started from a notification click, the name of the Schedule that was sent

scheduleId

string | undefined

If the session started from a notification click, the internal id of the Schedule that was sent

creativeName

string | undefined

If the session was started from a notification click, the name of the Message that was sent. If the session started from a link click, the name of the Link that was clicked

creativeId

string | undefined

If the session was started from a notification click, the internal id of the Message that was sent. If the session started from a link click, the internal id of the Link that was clicked

rewardId

string | undefined

If the session started from a source with an associated reward, the internal id of that reward

channelName

string | undefined

If the session started through a Teak source, a string indicating the channel. This value may be set by the marketing team

deepLink

string | undefined

If the session started from a source with an associated deep link, the raw URL of the deep link

sourceSendId

string | undefined

If the session started from a notification click, the internal id of the originating send event

optOutCategory

string\ undefined

If the session started from a notification click, the name of the opt out category configured for the message

Parameters

Name

Type

Description

eventType

"reward" | "deepLink" | "postLaunchSummary"

The event type to register a listener for

callback

(RewardEvent | PostLaunchSummaryEvent | object) ⇒ void

The listener callback to register

registerForNotifications

Attempts to register the current site for Web Push notifications. If required, will prompt the player for permissions using the browser’s native permission dialog. This method should be called when you want to prompt the player for Web Push permissions.

Parameters

Name

Type

Description

switchVendor

boolean

If true, and if the site is registered for Web Push with a different vendor or internal service, will unsubscribe from that vendor and resubscribe with Teak.

callback

(state: NotificationState) ⇒ void

After the player has granted or denied push permissions, called with the current state of Web Push for the site.

getNotificationState

Retrieves the current state of Web Push notifications.

Parameters

Name

Type

Description

callback

(state: NotificationState) ⇒ void

Called with the current state of Web Push for the site.

scheduleNotificationWithPersonalization

Schedules a Local Notification for the current player.

Parameters

Name

Type

Description

scheduleName

string

The name of Local Schedule to send to the current player

delayInSeconds

number

The number of seconds from now to send the notification in

personalizationData

Record<string, any>

Additional data to template into the notification as Local Notification Tags

callback

(status: "ok" | "error", errors?: Record<string, string[]>)

Called after the notification is scheduled. If status is ok the notification is scheduled to send. If status is error, the errors attribute will indicate issues with the call.

cancelNotification

Cancels a previously scheduled Local Notification for the current player.

Parameters

Name

Type

Description

scheduleName

string

The name of Local Schedule to cancel for the current player

callback

(status: "ok" | "error", errors?: Record<string, string[]>)

Called after the notification is canceled. If status is ok the notification has been canceled and will not send. If status is error, the errors attribute will indicate issues with the call.

cancelAllNotifications

Cancels all previously scheduled Local Notifications for the current player.

Parameters

Name

Type

Description

callback

(status: "ok" | "error", errors?: Record<string, string[]>)

Called after all notifications are canceled. If status is ok all notifications have been canceled and will not send. If status is error, the errors attribute will indicate issues with the call.

setStringAttribute

Sets a string Player Property for the current player.

Parameters

Name

Type

Description

attributeName

string

The name of the Player Property to set

value

string

The value to set

setNumberAttribute

Sets a number Player Property for the current player.

Parameters

Name

Type

Description

attributeName

string

The name of the Player Property to set

value

number

The value to set

incrementEvent

Reports a Custom Event for the current player.

Note that Teak has dedicated events for and automatically tracks sessions, session time, and interactions with notifications, emails, and links from Teak. This method should be used for unique in game events, such as completing a level or spinning on a slot machine.

Teak’s custom event structure is a three tiered hierachy, e.g. complete → quest → fetchApple. Calling incrementEvent("complete", "quest", "fetchApple", 1) will increment the player’s event count for complete, complete → quest, and complete → quest → fetchApple by 1.

Parameters

Name

Type

Description

actionId

string

The identifier for the top level of the hierarchy, e.g. 'complete'.

objectId

string

The identifier for the second level of the hierarchy, e.g. 'quest'.

instanceId

string

The identifier for the third level of the hierarchy, e.g. 'fetchApple'

count

number

How much to increase the event count by. Must be >= 1.

registerRoute

Registers a deep link route. This is similar to a single page application router, and is used by Teak to take players to specific in game destinations from an apprpriately configured notification, email, or link.

Parameters

Name

Type

Description

route

string

The route to register a callback for. May contain splat parameters beginning with :. E.g. /screen/:screenName

name

string

A name to give the route, which will be displayed in the Teak dashboard, e.g. In-Game Screen

description

string

Documentation of the route. Include a description of what it does and all parameters, e.g. Takes the player to the in-game screen specified by :screenName

callback

(parmeters: Record<string, string>) ⇒ void

A function called when a notification, email, or link navigates to this route. parameters will include all splat parameters and all query string parameters.