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 |
---|---|
|
The state of Web Push has either not been determined, or is unable to be determined due to a browser error. |
|
The player has granted Web Push permissions for the current site, and notifications may be sent. |
|
The player has denied Web Push permissions for the current site. Notifications may not be sent. |
|
No Service Worker is configured. Follow the steps in Add a Service Worker. |
|
Web Push is not supported by the current browser. |
|
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 |
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 |
|
"grant_reward" |
The reward was granted to the player, and the RewardEvent will have a populated |
|
"expired" |
The reward has expired and is no longer claimable |
|
"already_clicked" |
The player has already claimed this reward and cannot claim it again |
|
"too_many_clicks" |
This reward has a limit on the number of players who can claim it, and has reached that limit |
|
"self_click" |
This reward was shared by the current player, and cannot be claimed by them |
|
"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 |
|
"not_for_you" |
This reward has a restriction on which players can claim it, and the current player is not on the list |
|
"invalid_post" |
This reward was not recognized |
Methods
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.
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
PostLaunchSummaryEvent
Name |
Type |
Description |
|
string |
The URL of the current page |
|
string | undefined |
If the session started from a notification click, the name of the Schedule that was sent |
|
string | undefined |
If the session started from a notification click, the internal id of the Schedule that was sent |
|
string | undefined |
|
|
string | undefined |
|
|
string | undefined |
If the session started from a source with an associated reward, the internal id of that reward |
|
string | undefined |
If the session started through a Teak source, a string indicating the channel. This value may be set by the marketing team |
|
string | undefined |
If the session started from a source with an associated deep link, the raw URL of the deep link |
|
string | undefined |
If the session started from a notification click, the internal id of the originating send event |
|
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 |
|
"reward" | "deepLink" | "postLaunchSummary" |
The event type to register a listener for |
|
(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 |
|
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. |
|
(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 |
|
(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 |
|
string |
The name of Local Schedule to send to the current player |
|
number |
The number of seconds from now to send the notification in |
|
Record<string, any> |
Additional data to template into the notification as Local Notification Tags |
|
(status: "ok" | "error", errors?: Record<string, string[]>) |
Called after the notification is scheduled. If |
cancelNotification
Cancels a previously scheduled Local Notification for the current player.
Parameters
Name |
Type |
Description |
|
string |
The name of Local Schedule to cancel for the current player |
|
(status: "ok" | "error", errors?: Record<string, string[]>) |
Called after the notification is canceled. If |
cancelAllNotifications
Cancels all previously scheduled Local Notifications for the current player.
setStringAttribute
Sets a string Player Property for the current player.
setNumberAttribute
Sets a number Player Property for the current player.
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 |
|
string |
The identifier for the top level of the hierarchy, e.g. 'complete'. |
|
string |
The identifier for the second level of the hierarchy, e.g. 'quest'. |
|
string |
The identifier for the third level of the hierarchy, e.g. 'fetchApple' |
|
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 |
|
string |
The route to register a callback for. May contain splat parameters beginning with |
|
string |
A name to give the route, which will be displayed in the Teak dashboard, e.g. |
|
string |
Documentation of the route. Include a description of what it does and all parameters, e.g. |
|
(parmeters: Record<string, string>) ⇒ void |
A function called when a notification, email, or link navigates to this route. |